@@ -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 |
@@ -516,10 +516,10 @@ discard block |
||
| 516 | 516 | } |
| 517 | 517 | $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
| 518 | 518 | if( in_array( |
| 519 | - $this->type(), |
|
| 520 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 521 | - true |
|
| 522 | - ) ) { |
|
| 519 | + $this->type(), |
|
| 520 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 521 | + true |
|
| 522 | + ) ) { |
|
| 523 | 523 | $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
| 524 | 524 | null, |
| 525 | 525 | min( $max_max_for_question, $this->max() ) |
@@ -632,17 +632,17 @@ discard block |
||
| 632 | 632 | |
| 633 | 633 | |
| 634 | 634 | |
| 635 | - /** |
|
| 636 | - * Returns whether or not this question type should have question option entries |
|
| 637 | - * @return bool |
|
| 638 | - */ |
|
| 635 | + /** |
|
| 636 | + * Returns whether or not this question type should have question option entries |
|
| 637 | + * @return bool |
|
| 638 | + */ |
|
| 639 | 639 | public function should_have_question_options() |
| 640 | - { |
|
| 641 | - return in_array( |
|
| 642 | - $this->type(), |
|
| 643 | - $this->_model->question_types_with_options(), |
|
| 644 | - true |
|
| 645 | - ); |
|
| 646 | - } |
|
| 640 | + { |
|
| 641 | + return in_array( |
|
| 642 | + $this->type(), |
|
| 643 | + $this->_model->question_types_with_options(), |
|
| 644 | + true |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | 647 | |
| 648 | 648 | } |
@@ -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,33 +496,33 @@ 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( in_array( |
|
| 517 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 518 | + if (in_array( |
|
| 519 | 519 | $this->type(), |
| 520 | 520 | EEM_Question::instance()->questionTypesWithMaxLength(), |
| 521 | 521 | true |
| 522 | - ) ) { |
|
| 523 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
| 522 | + )) { |
|
| 523 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 524 | 524 | null, |
| 525 | - min( $max_max_for_question, $this->max() ) |
|
| 525 | + min($max_max_for_question, $this->max()) |
|
| 526 | 526 | ); |
| 527 | 527 | } |
| 528 | 528 | $input_constructor_args = apply_filters( |
@@ -534,22 +534,22 @@ discard block |
||
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | 536 | $result = null; |
| 537 | - switch ( $this->type() ) { |
|
| 537 | + switch ($this->type()) { |
|
| 538 | 538 | // Text |
| 539 | 539 | case EEM_Question::QST_type_text : |
| 540 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 540 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 541 | 541 | break; |
| 542 | 542 | // Textarea |
| 543 | 543 | case EEM_Question::QST_type_textarea : |
| 544 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
| 544 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 545 | 545 | break; |
| 546 | 546 | // Radio Buttons |
| 547 | 547 | case EEM_Question::QST_type_radio : |
| 548 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
| 548 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 549 | 549 | break; |
| 550 | 550 | // Dropdown |
| 551 | 551 | case EEM_Question::QST_type_dropdown : |
| 552 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
| 552 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 553 | 553 | break; |
| 554 | 554 | // State Dropdown |
| 555 | 555 | case EEM_Question::QST_type_state : |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $registration, |
| 561 | 561 | $answer |
| 562 | 562 | ); |
| 563 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
| 563 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 564 | 564 | break; |
| 565 | 565 | // Country Dropdown |
| 566 | 566 | case EEM_Question::QST_type_country : |
@@ -571,47 +571,47 @@ discard block |
||
| 571 | 571 | $registration, |
| 572 | 572 | $answer |
| 573 | 573 | ); |
| 574 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
| 574 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 575 | 575 | break; |
| 576 | 576 | // Checkboxes |
| 577 | 577 | case EEM_Question::QST_type_checkbox : |
| 578 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
| 578 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 579 | 579 | break; |
| 580 | 580 | // Date |
| 581 | 581 | case EEM_Question::QST_type_date : |
| 582 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
| 582 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 583 | 583 | break; |
| 584 | 584 | case EEM_Question::QST_type_html_textarea : |
| 585 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 586 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
| 587 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
| 585 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 586 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 587 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 588 | 588 | break; |
| 589 | 589 | case EEM_Question::QST_type_email : |
| 590 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
| 590 | + $result = new EE_Email_Input($input_constructor_args); |
|
| 591 | 591 | break; |
| 592 | 592 | case EEM_Question::QST_type_us_phone : |
| 593 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
| 593 | + $result = new EE_Phone_Input($input_constructor_args); |
|
| 594 | 594 | break; |
| 595 | 595 | case EEM_Question::QST_type_int : |
| 596 | - $result = new EE_Integer_Input( $input_constructor_args ); |
|
| 596 | + $result = new EE_Integer_Input($input_constructor_args); |
|
| 597 | 597 | break; |
| 598 | 598 | case EEM_Question::QST_type_decimal : |
| 599 | - $result = new EE_Float_Input( $input_constructor_args ); |
|
| 599 | + $result = new EE_Float_Input($input_constructor_args); |
|
| 600 | 600 | break; |
| 601 | 601 | case EEM_Question::QST_type_url : |
| 602 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
| 603 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 602 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
| 603 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 604 | 604 | break; |
| 605 | 605 | case EEM_Question::QST_type_year : |
| 606 | 606 | $result = new EE_Year_Input( |
| 607 | 607 | $input_constructor_args, |
| 608 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
| 609 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
| 610 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
| 608 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
| 609 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
| 610 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
| 611 | 611 | ); |
| 612 | 612 | break; |
| 613 | 613 | case EEM_Question::QST_type_multi_select : |
| 614 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
| 614 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 615 | 615 | break; |
| 616 | 616 | // fallback |
| 617 | 617 | default : |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | $this, |
| 623 | 623 | $input_constructor_args |
| 624 | 624 | ); |
| 625 | - if( ! $default_input ){ |
|
| 626 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
| 625 | + if ( ! $default_input) { |
|
| 626 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
| 627 | 627 | } |
| 628 | 628 | $result = $default_input; |
| 629 | 629 | } |
| 630 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
| 630 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | |
@@ -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 | require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
| 5 | 5 | require_once(EE_CLASSES . 'EE_Question.class.php'); |
@@ -16,431 +16,431 @@ discard block |
||
| 16 | 16 | class EEM_Question extends EEM_Soft_Delete_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - // constant used to indicate that the question type is COUNTRY |
|
| 20 | - const QST_type_country = 'COUNTRY'; |
|
| 21 | - |
|
| 22 | - // constant used to indicate that the question type is DATE |
|
| 23 | - const QST_type_date = 'DATE'; |
|
| 24 | - |
|
| 25 | - // constant used to indicate that the question type is DROPDOWN |
|
| 26 | - const QST_type_dropdown = 'DROPDOWN'; |
|
| 27 | - |
|
| 28 | - // constant used to indicate that the question type is CHECKBOX |
|
| 29 | - const QST_type_checkbox = 'CHECKBOX'; |
|
| 30 | - |
|
| 31 | - // constant used to indicate that the question type is RADIO_BTN |
|
| 32 | - const QST_type_radio = 'RADIO_BTN'; |
|
| 33 | - |
|
| 34 | - // constant used to indicate that the question type is STATE |
|
| 35 | - const QST_type_state = 'STATE'; |
|
| 36 | - |
|
| 37 | - // constant used to indicate that the question type is TEXT |
|
| 38 | - const QST_type_text = 'TEXT'; |
|
| 39 | - |
|
| 40 | - // constant used to indicate that the question type is TEXTAREA |
|
| 41 | - const QST_type_textarea = 'TEXTAREA'; |
|
| 42 | - |
|
| 43 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 44 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 45 | - |
|
| 46 | - // constant used to indicate that the question type is an email input |
|
| 47 | - const QST_type_email = 'EMAIL'; |
|
| 48 | - |
|
| 49 | - // constant used to indicate that the question type is a US-formatted phone number |
|
| 50 | - const QST_type_us_phone = 'US_PHONE'; |
|
| 51 | - |
|
| 52 | - // constant used to indicate that the question type is an integer (whole number) |
|
| 53 | - const QST_type_int = 'INTEGER'; |
|
| 54 | - |
|
| 55 | - // constant used to indicate that the question type is a decimal (float) |
|
| 56 | - const QST_type_decimal = 'DECIMAL'; |
|
| 57 | - |
|
| 58 | - // constant used to indicate that the question type is a valid URL |
|
| 59 | - const QST_type_url = 'URL'; |
|
| 60 | - |
|
| 61 | - // constant used to indicate that the question type is a YEAR |
|
| 62 | - const QST_type_year = 'YEAR'; |
|
| 63 | - |
|
| 64 | - // constant used to indicate that the question type is a multi-select |
|
| 65 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
| 69 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 70 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 71 | - * |
|
| 72 | - * @access protected |
|
| 73 | - * @var array $_question_type_categories { |
|
| 74 | - * @type string $text |
|
| 75 | - * @type string $single -answer-enum |
|
| 76 | - * @type string $multi -answer-enum |
|
| 77 | - * } |
|
| 78 | - */ |
|
| 79 | - protected $_question_type_categories = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 83 | - * |
|
| 84 | - * @access protected |
|
| 85 | - * @var array $_allowed_question_types |
|
| 86 | - */ |
|
| 87 | - protected $_allowed_question_types = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * brief descriptions for all the question types |
|
| 91 | - * |
|
| 92 | - * @access protected |
|
| 93 | - * @var EEM_Question $_instance |
|
| 94 | - */ |
|
| 95 | - protected $_question_descriptions; |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Question types that should have an admin-defined max input length |
|
| 100 | - * @var array |
|
| 101 | - */ |
|
| 102 | - protected $question_types_with_max_lengh; |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - // private instance of the Attendee object |
|
| 106 | - protected static $_instance = NULL; |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * EEM_Question constructor. |
|
| 111 | - * |
|
| 112 | - * @param null $timezone |
|
| 113 | - */ |
|
| 114 | - protected function __construct($timezone = NULL) |
|
| 115 | - { |
|
| 116 | - $this->singular_item = __('Question', 'event_espresso'); |
|
| 117 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
| 118 | - $this->_allowed_question_types = apply_filters( |
|
| 119 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 120 | - array( |
|
| 121 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
| 122 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
| 123 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
| 124 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
| 125 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
| 126 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
| 127 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
| 128 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
| 129 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
| 130 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
| 131 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
| 132 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
| 133 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
| 134 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
| 135 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
| 136 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - $this->_question_descriptions = apply_filters( |
|
| 140 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 141 | - array( |
|
| 142 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
| 143 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
| 144 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 145 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
| 146 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
| 147 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 148 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
| 149 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
| 150 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 151 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 152 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 153 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
| 154 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 155 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
| 156 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 157 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
| 158 | - ) |
|
| 159 | - ); |
|
| 160 | - $this->_question_type_categories = (array)apply_filters( |
|
| 161 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 162 | - array( |
|
| 163 | - 'text' => array( |
|
| 164 | - EEM_Question::QST_type_text, |
|
| 165 | - EEM_Question::QST_type_textarea, |
|
| 166 | - EEM_Question::QST_type_date, |
|
| 167 | - EEM_Question::QST_type_html_textarea, |
|
| 168 | - EEM_Question::QST_type_email, |
|
| 169 | - EEM_Question::QST_type_us_phone, |
|
| 170 | - EEM_Question::QST_type_decimal, |
|
| 171 | - EEM_Question::QST_type_int, |
|
| 172 | - EEM_Question::QST_type_url, |
|
| 173 | - EEM_Question::QST_type_year |
|
| 174 | - ), |
|
| 175 | - 'single-answer-enum' => array( |
|
| 176 | - EEM_Question::QST_type_radio, |
|
| 177 | - EEM_Question::QST_type_dropdown |
|
| 178 | - ), |
|
| 179 | - 'multi-answer-enum' => array( |
|
| 180 | - EEM_Question::QST_type_checkbox, |
|
| 181 | - EEM_Question::QST_type_multi_select |
|
| 182 | - ) |
|
| 183 | - ) |
|
| 184 | - ); |
|
| 185 | - $this->question_types_with_max_lengh = apply_filters( |
|
| 186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 187 | - array( |
|
| 188 | - EEM_Question::QST_type_text, |
|
| 189 | - EEM_Question::QST_type_textarea, |
|
| 190 | - EEM_Question::QST_type_html_textarea |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - $this->_tables = array( |
|
| 195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 196 | - ); |
|
| 197 | - $this->_fields = array( |
|
| 198 | - 'Question' => array( |
|
| 199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
| 200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
| 201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 204 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
| 205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 206 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
| 207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
| 209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
| 210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - $this->_model_relations = array( |
|
| 214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
| 217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 218 | - //for QST_order column |
|
| 219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 220 | - ); |
|
| 221 | - //this model is generally available for reading |
|
| 222 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 223 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 224 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 225 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 226 | - parent::__construct($timezone); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 231 | - * but they can be extended |
|
| 232 | - * @return string[] |
|
| 233 | - */ |
|
| 234 | - public function allowed_question_types() |
|
| 235 | - { |
|
| 236 | - return $this->_allowed_question_types; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Gets all the question types in the same category |
|
| 241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
| 243 | - */ |
|
| 244 | - public function question_types_in_same_category($question_type) |
|
| 245 | - { |
|
| 246 | - $question_types = array($question_type); |
|
| 247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 248 | - if (in_array($question_type, $question_types_in_category)) { |
|
| 249 | - $question_types = $question_types_in_category; |
|
| 250 | - break; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Determines if the given question type is in the given question type category |
|
| 259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 261 | - * @return boolean |
|
| 262 | - */ |
|
| 263 | - public function question_type_is_in_category($question_type, $category) |
|
| 264 | - { |
|
| 265 | - if (!isset($this->_question_type_categories[$category])) { |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 268 | - return in_array($question_type, $this->_question_type_categories[$category]); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Returns all the question types in the given category |
|
| 274 | - * @param string $category |
|
| 275 | - * @return array|mixed |
|
| 276 | - */ |
|
| 277 | - public function question_types_in_category($category) |
|
| 278 | - { |
|
| 279 | - if (isset($this->_question_type_categories[$category])) { |
|
| 280 | - return $this->_question_type_categories[$category]; |
|
| 281 | - } |
|
| 282 | - return array(); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns all the question types that should have question options |
|
| 288 | - * @return array |
|
| 289 | - */ |
|
| 290 | - public function question_types_with_options() |
|
| 291 | - { |
|
| 292 | - return array_merge( |
|
| 293 | - $this->question_types_in_category('single-answer-enum'), |
|
| 294 | - $this->question_types_in_category('multi-answer-enum') |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Returns the question type categories 2d array |
|
| 300 | - * @return array see EEM_Question::_question_type_categories |
|
| 301 | - */ |
|
| 302 | - public function question_type_categories() |
|
| 303 | - { |
|
| 304 | - return $this->_question_type_categories; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 309 | - * identified by $system_question_group_id |
|
| 310 | - * @param string $system_question_group_id QSG_system |
|
| 311 | - * @return array of system question names (QST_system) |
|
| 312 | - */ |
|
| 313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 314 | - { |
|
| 315 | - $question_system_ids = array(); |
|
| 316 | - switch ($system_question_group_id) { |
|
| 317 | - case EEM_Question_Group::system_personal: |
|
| 318 | - $question_system_ids = array( |
|
| 319 | - EEM_Attendee::system_question_fname, |
|
| 320 | - EEM_Attendee::system_question_lname, |
|
| 321 | - EEM_Attendee::system_question_email, |
|
| 322 | - EEM_Attendee::system_question_phone |
|
| 323 | - ); |
|
| 324 | - break; |
|
| 325 | - case EEM_Question_Group::system_address: |
|
| 326 | - $question_system_ids = array( |
|
| 327 | - EEM_Attendee::system_question_address, |
|
| 328 | - EEM_Attendee::system_question_address2, |
|
| 329 | - EEM_Attendee::system_question_city, |
|
| 330 | - EEM_Attendee::system_question_state, |
|
| 331 | - EEM_Attendee::system_question_country, |
|
| 332 | - EEM_Attendee::system_question_zip, |
|
| 333 | - EEM_Attendee::system_question_phone |
|
| 334 | - ); |
|
| 335 | - break; |
|
| 336 | - } |
|
| 337 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Returns an array of all the QST_system values that are required in the system question group |
|
| 342 | - * identified by $system_question_group_id |
|
| 343 | - * @param string $system_question_group_id QSG_system |
|
| 344 | - * @return array of system question names (QST_system) |
|
| 345 | - */ |
|
| 346 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 347 | - { |
|
| 348 | - $question_system_ids = null; |
|
| 349 | - switch ($system_question_group_id) { |
|
| 350 | - case EEM_Question_Group::system_personal: |
|
| 351 | - $question_system_ids = array( |
|
| 352 | - EEM_Attendee::system_question_fname, |
|
| 353 | - EEM_Attendee::system_question_email, |
|
| 354 | - ); |
|
| 355 | - break; |
|
| 356 | - default: |
|
| 357 | - $question_system_ids = array(); |
|
| 358 | - } |
|
| 359 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 365 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 366 | - * @param $QST_system |
|
| 367 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 368 | - */ |
|
| 369 | - public function get_Question_ID_from_system_string($QST_system) |
|
| 370 | - { |
|
| 371 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * searches the db for the question with the latest question order and returns that value. |
|
| 377 | - * @access public |
|
| 378 | - * @return int |
|
| 379 | - */ |
|
| 380 | - public function get_latest_question_order() |
|
| 381 | - { |
|
| 382 | - $columns_to_select = array( |
|
| 383 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
| 384 | - ); |
|
| 385 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 386 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Returns an array where keys are system question QST_system values, |
|
| 391 | - * and values are the highest question max the admin can set on the question |
|
| 392 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 393 | - * of 5, but no larger than 12) |
|
| 394 | - * @return array |
|
| 395 | - */ |
|
| 396 | - public function system_question_maxes() |
|
| 397 | - { |
|
| 398 | - return array( |
|
| 399 | - 'fname' => 45, |
|
| 400 | - 'lname' => 45, |
|
| 401 | - 'address' => 255, |
|
| 402 | - 'address2' => 255, |
|
| 403 | - 'city' => 45, |
|
| 404 | - 'zip' => 12, |
|
| 405 | - 'email' => 255, |
|
| 406 | - 'phone' => 45, |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
| 412 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 413 | - * @param string $system_question_value |
|
| 414 | - * @return int|float |
|
| 415 | - */ |
|
| 416 | - public function absolute_max_for_system_question($system_question_value) |
|
| 417 | - { |
|
| 418 | - $maxes = $this->system_question_maxes(); |
|
| 419 | - if (isset($maxes[$system_question_value])) { |
|
| 420 | - return $maxes[$system_question_value]; |
|
| 421 | - } else { |
|
| 422 | - return EE_INF; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @return array |
|
| 429 | - */ |
|
| 430 | - public function question_descriptions() |
|
| 431 | - { |
|
| 432 | - return $this->_question_descriptions; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Returns all the question types that should have an admin-defined max input length |
|
| 438 | - * @return array |
|
| 439 | - */ |
|
| 440 | - public function questionTypesWithMaxLength() |
|
| 441 | - { |
|
| 442 | - return (array)$this->question_types_with_max_lengh; |
|
| 443 | - } |
|
| 19 | + // constant used to indicate that the question type is COUNTRY |
|
| 20 | + const QST_type_country = 'COUNTRY'; |
|
| 21 | + |
|
| 22 | + // constant used to indicate that the question type is DATE |
|
| 23 | + const QST_type_date = 'DATE'; |
|
| 24 | + |
|
| 25 | + // constant used to indicate that the question type is DROPDOWN |
|
| 26 | + const QST_type_dropdown = 'DROPDOWN'; |
|
| 27 | + |
|
| 28 | + // constant used to indicate that the question type is CHECKBOX |
|
| 29 | + const QST_type_checkbox = 'CHECKBOX'; |
|
| 30 | + |
|
| 31 | + // constant used to indicate that the question type is RADIO_BTN |
|
| 32 | + const QST_type_radio = 'RADIO_BTN'; |
|
| 33 | + |
|
| 34 | + // constant used to indicate that the question type is STATE |
|
| 35 | + const QST_type_state = 'STATE'; |
|
| 36 | + |
|
| 37 | + // constant used to indicate that the question type is TEXT |
|
| 38 | + const QST_type_text = 'TEXT'; |
|
| 39 | + |
|
| 40 | + // constant used to indicate that the question type is TEXTAREA |
|
| 41 | + const QST_type_textarea = 'TEXTAREA'; |
|
| 42 | + |
|
| 43 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 44 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 45 | + |
|
| 46 | + // constant used to indicate that the question type is an email input |
|
| 47 | + const QST_type_email = 'EMAIL'; |
|
| 48 | + |
|
| 49 | + // constant used to indicate that the question type is a US-formatted phone number |
|
| 50 | + const QST_type_us_phone = 'US_PHONE'; |
|
| 51 | + |
|
| 52 | + // constant used to indicate that the question type is an integer (whole number) |
|
| 53 | + const QST_type_int = 'INTEGER'; |
|
| 54 | + |
|
| 55 | + // constant used to indicate that the question type is a decimal (float) |
|
| 56 | + const QST_type_decimal = 'DECIMAL'; |
|
| 57 | + |
|
| 58 | + // constant used to indicate that the question type is a valid URL |
|
| 59 | + const QST_type_url = 'URL'; |
|
| 60 | + |
|
| 61 | + // constant used to indicate that the question type is a YEAR |
|
| 62 | + const QST_type_year = 'YEAR'; |
|
| 63 | + |
|
| 64 | + // constant used to indicate that the question type is a multi-select |
|
| 65 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
| 69 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 70 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 71 | + * |
|
| 72 | + * @access protected |
|
| 73 | + * @var array $_question_type_categories { |
|
| 74 | + * @type string $text |
|
| 75 | + * @type string $single -answer-enum |
|
| 76 | + * @type string $multi -answer-enum |
|
| 77 | + * } |
|
| 78 | + */ |
|
| 79 | + protected $_question_type_categories = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 83 | + * |
|
| 84 | + * @access protected |
|
| 85 | + * @var array $_allowed_question_types |
|
| 86 | + */ |
|
| 87 | + protected $_allowed_question_types = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * brief descriptions for all the question types |
|
| 91 | + * |
|
| 92 | + * @access protected |
|
| 93 | + * @var EEM_Question $_instance |
|
| 94 | + */ |
|
| 95 | + protected $_question_descriptions; |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Question types that should have an admin-defined max input length |
|
| 100 | + * @var array |
|
| 101 | + */ |
|
| 102 | + protected $question_types_with_max_lengh; |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + // private instance of the Attendee object |
|
| 106 | + protected static $_instance = NULL; |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * EEM_Question constructor. |
|
| 111 | + * |
|
| 112 | + * @param null $timezone |
|
| 113 | + */ |
|
| 114 | + protected function __construct($timezone = NULL) |
|
| 115 | + { |
|
| 116 | + $this->singular_item = __('Question', 'event_espresso'); |
|
| 117 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
| 118 | + $this->_allowed_question_types = apply_filters( |
|
| 119 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 120 | + array( |
|
| 121 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
| 122 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
| 123 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
| 124 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
| 125 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
| 126 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
| 127 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
| 128 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
| 129 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
| 130 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
| 131 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
| 132 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
| 133 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
| 134 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
| 135 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
| 136 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + $this->_question_descriptions = apply_filters( |
|
| 140 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 141 | + array( |
|
| 142 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
| 143 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
| 144 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 145 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
| 146 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
| 147 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 148 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
| 149 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
| 150 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 151 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 152 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 153 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
| 154 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 155 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
| 156 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 157 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
| 158 | + ) |
|
| 159 | + ); |
|
| 160 | + $this->_question_type_categories = (array)apply_filters( |
|
| 161 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 162 | + array( |
|
| 163 | + 'text' => array( |
|
| 164 | + EEM_Question::QST_type_text, |
|
| 165 | + EEM_Question::QST_type_textarea, |
|
| 166 | + EEM_Question::QST_type_date, |
|
| 167 | + EEM_Question::QST_type_html_textarea, |
|
| 168 | + EEM_Question::QST_type_email, |
|
| 169 | + EEM_Question::QST_type_us_phone, |
|
| 170 | + EEM_Question::QST_type_decimal, |
|
| 171 | + EEM_Question::QST_type_int, |
|
| 172 | + EEM_Question::QST_type_url, |
|
| 173 | + EEM_Question::QST_type_year |
|
| 174 | + ), |
|
| 175 | + 'single-answer-enum' => array( |
|
| 176 | + EEM_Question::QST_type_radio, |
|
| 177 | + EEM_Question::QST_type_dropdown |
|
| 178 | + ), |
|
| 179 | + 'multi-answer-enum' => array( |
|
| 180 | + EEM_Question::QST_type_checkbox, |
|
| 181 | + EEM_Question::QST_type_multi_select |
|
| 182 | + ) |
|
| 183 | + ) |
|
| 184 | + ); |
|
| 185 | + $this->question_types_with_max_lengh = apply_filters( |
|
| 186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 187 | + array( |
|
| 188 | + EEM_Question::QST_type_text, |
|
| 189 | + EEM_Question::QST_type_textarea, |
|
| 190 | + EEM_Question::QST_type_html_textarea |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + $this->_tables = array( |
|
| 195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 196 | + ); |
|
| 197 | + $this->_fields = array( |
|
| 198 | + 'Question' => array( |
|
| 199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
| 200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
| 201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 204 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
| 205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 206 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
| 207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
| 209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
| 210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + $this->_model_relations = array( |
|
| 214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
| 217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 218 | + //for QST_order column |
|
| 219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 220 | + ); |
|
| 221 | + //this model is generally available for reading |
|
| 222 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 223 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 224 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 225 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 226 | + parent::__construct($timezone); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 231 | + * but they can be extended |
|
| 232 | + * @return string[] |
|
| 233 | + */ |
|
| 234 | + public function allowed_question_types() |
|
| 235 | + { |
|
| 236 | + return $this->_allowed_question_types; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Gets all the question types in the same category |
|
| 241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
| 243 | + */ |
|
| 244 | + public function question_types_in_same_category($question_type) |
|
| 245 | + { |
|
| 246 | + $question_types = array($question_type); |
|
| 247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 248 | + if (in_array($question_type, $question_types_in_category)) { |
|
| 249 | + $question_types = $question_types_in_category; |
|
| 250 | + break; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Determines if the given question type is in the given question type category |
|
| 259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 261 | + * @return boolean |
|
| 262 | + */ |
|
| 263 | + public function question_type_is_in_category($question_type, $category) |
|
| 264 | + { |
|
| 265 | + if (!isset($this->_question_type_categories[$category])) { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Returns all the question types in the given category |
|
| 274 | + * @param string $category |
|
| 275 | + * @return array|mixed |
|
| 276 | + */ |
|
| 277 | + public function question_types_in_category($category) |
|
| 278 | + { |
|
| 279 | + if (isset($this->_question_type_categories[$category])) { |
|
| 280 | + return $this->_question_type_categories[$category]; |
|
| 281 | + } |
|
| 282 | + return array(); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns all the question types that should have question options |
|
| 288 | + * @return array |
|
| 289 | + */ |
|
| 290 | + public function question_types_with_options() |
|
| 291 | + { |
|
| 292 | + return array_merge( |
|
| 293 | + $this->question_types_in_category('single-answer-enum'), |
|
| 294 | + $this->question_types_in_category('multi-answer-enum') |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Returns the question type categories 2d array |
|
| 300 | + * @return array see EEM_Question::_question_type_categories |
|
| 301 | + */ |
|
| 302 | + public function question_type_categories() |
|
| 303 | + { |
|
| 304 | + return $this->_question_type_categories; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 309 | + * identified by $system_question_group_id |
|
| 310 | + * @param string $system_question_group_id QSG_system |
|
| 311 | + * @return array of system question names (QST_system) |
|
| 312 | + */ |
|
| 313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 314 | + { |
|
| 315 | + $question_system_ids = array(); |
|
| 316 | + switch ($system_question_group_id) { |
|
| 317 | + case EEM_Question_Group::system_personal: |
|
| 318 | + $question_system_ids = array( |
|
| 319 | + EEM_Attendee::system_question_fname, |
|
| 320 | + EEM_Attendee::system_question_lname, |
|
| 321 | + EEM_Attendee::system_question_email, |
|
| 322 | + EEM_Attendee::system_question_phone |
|
| 323 | + ); |
|
| 324 | + break; |
|
| 325 | + case EEM_Question_Group::system_address: |
|
| 326 | + $question_system_ids = array( |
|
| 327 | + EEM_Attendee::system_question_address, |
|
| 328 | + EEM_Attendee::system_question_address2, |
|
| 329 | + EEM_Attendee::system_question_city, |
|
| 330 | + EEM_Attendee::system_question_state, |
|
| 331 | + EEM_Attendee::system_question_country, |
|
| 332 | + EEM_Attendee::system_question_zip, |
|
| 333 | + EEM_Attendee::system_question_phone |
|
| 334 | + ); |
|
| 335 | + break; |
|
| 336 | + } |
|
| 337 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Returns an array of all the QST_system values that are required in the system question group |
|
| 342 | + * identified by $system_question_group_id |
|
| 343 | + * @param string $system_question_group_id QSG_system |
|
| 344 | + * @return array of system question names (QST_system) |
|
| 345 | + */ |
|
| 346 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 347 | + { |
|
| 348 | + $question_system_ids = null; |
|
| 349 | + switch ($system_question_group_id) { |
|
| 350 | + case EEM_Question_Group::system_personal: |
|
| 351 | + $question_system_ids = array( |
|
| 352 | + EEM_Attendee::system_question_fname, |
|
| 353 | + EEM_Attendee::system_question_email, |
|
| 354 | + ); |
|
| 355 | + break; |
|
| 356 | + default: |
|
| 357 | + $question_system_ids = array(); |
|
| 358 | + } |
|
| 359 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 365 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 366 | + * @param $QST_system |
|
| 367 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 368 | + */ |
|
| 369 | + public function get_Question_ID_from_system_string($QST_system) |
|
| 370 | + { |
|
| 371 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * searches the db for the question with the latest question order and returns that value. |
|
| 377 | + * @access public |
|
| 378 | + * @return int |
|
| 379 | + */ |
|
| 380 | + public function get_latest_question_order() |
|
| 381 | + { |
|
| 382 | + $columns_to_select = array( |
|
| 383 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
| 384 | + ); |
|
| 385 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 386 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Returns an array where keys are system question QST_system values, |
|
| 391 | + * and values are the highest question max the admin can set on the question |
|
| 392 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 393 | + * of 5, but no larger than 12) |
|
| 394 | + * @return array |
|
| 395 | + */ |
|
| 396 | + public function system_question_maxes() |
|
| 397 | + { |
|
| 398 | + return array( |
|
| 399 | + 'fname' => 45, |
|
| 400 | + 'lname' => 45, |
|
| 401 | + 'address' => 255, |
|
| 402 | + 'address2' => 255, |
|
| 403 | + 'city' => 45, |
|
| 404 | + 'zip' => 12, |
|
| 405 | + 'email' => 255, |
|
| 406 | + 'phone' => 45, |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
| 412 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 413 | + * @param string $system_question_value |
|
| 414 | + * @return int|float |
|
| 415 | + */ |
|
| 416 | + public function absolute_max_for_system_question($system_question_value) |
|
| 417 | + { |
|
| 418 | + $maxes = $this->system_question_maxes(); |
|
| 419 | + if (isset($maxes[$system_question_value])) { |
|
| 420 | + return $maxes[$system_question_value]; |
|
| 421 | + } else { |
|
| 422 | + return EE_INF; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @return array |
|
| 429 | + */ |
|
| 430 | + public function question_descriptions() |
|
| 431 | + { |
|
| 432 | + return $this->_question_descriptions; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Returns all the question types that should have an admin-defined max input length |
|
| 438 | + * @return array |
|
| 439 | + */ |
|
| 440 | + public function questionTypesWithMaxLength() |
|
| 441 | + { |
|
| 442 | + return (array)$this->question_types_with_max_lengh; |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | 445 | |
| 446 | 446 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | -require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
|
| 5 | -require_once(EE_CLASSES . 'EE_Question.class.php'); |
|
| 4 | +require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
| 5 | +require_once(EE_CLASSES.'EE_Question.class.php'); |
|
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
| 158 | 158 | ) |
| 159 | 159 | ); |
| 160 | - $this->_question_type_categories = (array)apply_filters( |
|
| 160 | + $this->_question_type_categories = (array) apply_filters( |
|
| 161 | 161 | 'FHEE__EEM_Question__construct__question_type_categories', |
| 162 | 162 | array( |
| 163 | 163 | 'text' => array( |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function question_type_is_in_category($question_type, $category) |
| 264 | 264 | { |
| 265 | - if (!isset($this->_question_type_categories[$category])) { |
|
| 265 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
| 266 | 266 | return false; |
| 267 | 267 | } |
| 268 | 268 | return in_array($question_type, $this->_question_type_categories[$category]); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | */ |
| 440 | 440 | public function questionTypesWithMaxLength() |
| 441 | 441 | { |
| 442 | - return (array)$this->question_types_with_max_lengh; |
|
| 442 | + return (array) $this->question_types_with_max_lengh; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -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 | /** |
@@ -28,621 +28,621 @@ discard block |
||
| 28 | 28 | class Registration_Form_Admin_Page extends EE_Admin_Page |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * _question |
|
| 33 | - * holds the specific question object for the question details screen |
|
| 34 | - * |
|
| 35 | - * @var EE_Question $_question |
|
| 36 | - */ |
|
| 37 | - protected $_question; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * _question_group |
|
| 41 | - * holds the specific question group object for the question group details screen |
|
| 42 | - * |
|
| 43 | - * @var EE_Question_Group $_question_group |
|
| 44 | - */ |
|
| 45 | - protected $_question_group; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - *_question_model EEM_Question model instance (for queries) |
|
| 49 | - * |
|
| 50 | - * @var EEM_Question $_question_model ; |
|
| 51 | - */ |
|
| 52 | - protected $_question_model; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * _question_group_model EEM_Question_group instance (for queries) |
|
| 56 | - * |
|
| 57 | - * @var EEM_Question_Group $_question_group_model |
|
| 58 | - */ |
|
| 59 | - protected $_question_group_model; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @Constructor |
|
| 64 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 65 | - * @access public |
|
| 66 | - */ |
|
| 67 | - public function __construct($routing = true) |
|
| 68 | - { |
|
| 69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 71 | - $this->_question_model = EEM_Question::instance(); |
|
| 72 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
| 73 | - parent::__construct($routing); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - protected function _init_page_props() |
|
| 78 | - { |
|
| 79 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
| 80 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
| 81 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
| 82 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - protected function _ajax_hooks() |
|
| 87 | - { |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - protected function _define_page_props() |
|
| 92 | - { |
|
| 93 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
| 94 | - $this->_labels = array( |
|
| 95 | - 'buttons' => array( |
|
| 96 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
| 97 | - ), |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - *_set_page_routes |
|
| 104 | - */ |
|
| 105 | - protected function _set_page_routes() |
|
| 106 | - { |
|
| 107 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 108 | - $this->_page_routes = array( |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_questions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_questions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'edit_question' => array( |
|
| 115 | - 'func' => '_edit_question', |
|
| 116 | - 'capability' => 'ee_edit_question', |
|
| 117 | - 'obj_id' => $qst_id, |
|
| 118 | - 'args' => array('edit'), |
|
| 119 | - ), |
|
| 120 | - |
|
| 121 | - 'question_groups' => array( |
|
| 122 | - 'func' => '_questions_groups_preview', |
|
| 123 | - 'capability' => 'ee_read_question_groups', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'update_question' => array( |
|
| 127 | - 'func' => '_insert_or_update_question', |
|
| 128 | - 'args' => array('new_question' => false), |
|
| 129 | - 'capability' => 'ee_edit_question', |
|
| 130 | - 'obj_id' => $qst_id, |
|
| 131 | - 'noheader' => true, |
|
| 132 | - ), |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - protected function _set_page_config() |
|
| 138 | - { |
|
| 139 | - $this->_page_config = array( |
|
| 140 | - 'default' => array( |
|
| 141 | - 'nav' => array( |
|
| 142 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
| 143 | - 'order' => 10, |
|
| 144 | - ), |
|
| 145 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
| 146 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 147 | - 'help_tabs' => array( |
|
| 148 | - 'registration_form_questions_overview_help_tab' => array( |
|
| 149 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
| 150 | - 'filename' => 'registration_form_questions_overview', |
|
| 151 | - ), |
|
| 152 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
| 153 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
| 154 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
| 155 | - ), |
|
| 156 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
| 157 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
| 158 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
| 159 | - ), |
|
| 160 | - ), |
|
| 161 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
| 162 | - 'require_nonce' => false, |
|
| 163 | - 'qtips' => array( |
|
| 164 | - 'EE_Registration_Form_Tips', |
|
| 165 | - )/**/ |
|
| 166 | - ), |
|
| 167 | - |
|
| 168 | - 'question_groups' => array( |
|
| 169 | - 'nav' => array( |
|
| 170 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 171 | - 'order' => 20, |
|
| 172 | - ), |
|
| 173 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 174 | - 'help_tabs' => array( |
|
| 175 | - 'registration_form_question_groups_help_tab' => array( |
|
| 176 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 177 | - 'filename' => 'registration_form_question_groups', |
|
| 178 | - ), |
|
| 179 | - ), |
|
| 180 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 181 | - 'require_nonce' => false, |
|
| 182 | - ), |
|
| 183 | - |
|
| 184 | - 'edit_question' => array( |
|
| 185 | - 'nav' => array( |
|
| 186 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
| 187 | - 'order' => 15, |
|
| 188 | - 'persistent' => false, |
|
| 189 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
| 190 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 191 | - ), |
|
| 192 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 193 | - 'help_tabs' => array( |
|
| 194 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 195 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
| 196 | - 'filename' => 'registration_form_edit_question', |
|
| 197 | - ), |
|
| 198 | - ), |
|
| 199 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
| 200 | - 'require_nonce' => false, |
|
| 201 | - ), |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - protected function _add_screen_options() |
|
| 207 | - { |
|
| 208 | - //todo |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - protected function _add_screen_options_default() |
|
| 212 | - { |
|
| 213 | - $page_title = $this->_admin_page_title; |
|
| 214 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
| 215 | - $this->_per_page_screen_option(); |
|
| 216 | - $this->_admin_page_title = $page_title; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - protected function _add_screen_options_question_groups() |
|
| 220 | - { |
|
| 221 | - $page_title = $this->_admin_page_title; |
|
| 222 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
| 223 | - $this->_per_page_screen_option(); |
|
| 224 | - $this->_admin_page_title = $page_title; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - //none of the below group are currently used for Event Categories |
|
| 228 | - protected function _add_feature_pointers() |
|
| 229 | - { |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public function load_scripts_styles() |
|
| 233 | - { |
|
| 234 | - wp_register_style('espresso_registration', |
|
| 235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | - wp_enqueue_style('espresso_registration'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public function admin_init() |
|
| 240 | - { |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function admin_notices() |
|
| 244 | - { |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - public function admin_footer_scripts() |
|
| 248 | - { |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - public function load_scripts_styles_default() |
|
| 253 | - { |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - public function load_scripts_styles_add_question() |
|
| 258 | - { |
|
| 259 | - $this->load_scripts_styles_question_details(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function load_scripts_styles_edit_question() |
|
| 263 | - { |
|
| 264 | - $this->load_scripts_styles_question_details(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Loads the JS required for adding or editing a question |
|
| 269 | - */ |
|
| 270 | - protected function load_scripts_styles_question_details() |
|
| 271 | - { |
|
| 272 | - $this->load_scripts_styles_forms(); |
|
| 273 | - wp_register_script('espresso_registration_form_single', |
|
| 274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 275 | - EVENT_ESPRESSO_VERSION, true); |
|
| 276 | - wp_enqueue_script('espresso_registration_form_single'); |
|
| 277 | - wp_localize_script( |
|
| 278 | - 'espresso_registration_form_single', |
|
| 279 | - 'ee_question_data', |
|
| 280 | - array( |
|
| 281 | - 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 282 | - 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
| 283 | - ) |
|
| 284 | - ); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - public function recaptcha_info_help_tab() |
|
| 289 | - { |
|
| 290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 291 | - EEH_Template::display_template($template, array()); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - public function load_scripts_styles_forms() |
|
| 296 | - { |
|
| 297 | - //styles |
|
| 298 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 299 | - //scripts |
|
| 300 | - wp_enqueue_script('ee_admin_js'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - protected function _set_list_table_views_default() |
|
| 305 | - { |
|
| 306 | - $this->_views = array( |
|
| 307 | - 'all' => array( |
|
| 308 | - 'slug' => 'all', |
|
| 309 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 310 | - 'count' => 0, |
|
| 31 | + /** |
|
| 32 | + * _question |
|
| 33 | + * holds the specific question object for the question details screen |
|
| 34 | + * |
|
| 35 | + * @var EE_Question $_question |
|
| 36 | + */ |
|
| 37 | + protected $_question; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * _question_group |
|
| 41 | + * holds the specific question group object for the question group details screen |
|
| 42 | + * |
|
| 43 | + * @var EE_Question_Group $_question_group |
|
| 44 | + */ |
|
| 45 | + protected $_question_group; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + *_question_model EEM_Question model instance (for queries) |
|
| 49 | + * |
|
| 50 | + * @var EEM_Question $_question_model ; |
|
| 51 | + */ |
|
| 52 | + protected $_question_model; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * _question_group_model EEM_Question_group instance (for queries) |
|
| 56 | + * |
|
| 57 | + * @var EEM_Question_Group $_question_group_model |
|
| 58 | + */ |
|
| 59 | + protected $_question_group_model; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @Constructor |
|
| 64 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 65 | + * @access public |
|
| 66 | + */ |
|
| 67 | + public function __construct($routing = true) |
|
| 68 | + { |
|
| 69 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 71 | + $this->_question_model = EEM_Question::instance(); |
|
| 72 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
| 73 | + parent::__construct($routing); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + protected function _init_page_props() |
|
| 78 | + { |
|
| 79 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
| 80 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
| 81 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
| 82 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + protected function _ajax_hooks() |
|
| 87 | + { |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + protected function _define_page_props() |
|
| 92 | + { |
|
| 93 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
| 94 | + $this->_labels = array( |
|
| 95 | + 'buttons' => array( |
|
| 96 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
| 97 | + ), |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + *_set_page_routes |
|
| 104 | + */ |
|
| 105 | + protected function _set_page_routes() |
|
| 106 | + { |
|
| 107 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 108 | + $this->_page_routes = array( |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_questions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_questions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'edit_question' => array( |
|
| 115 | + 'func' => '_edit_question', |
|
| 116 | + 'capability' => 'ee_edit_question', |
|
| 117 | + 'obj_id' => $qst_id, |
|
| 118 | + 'args' => array('edit'), |
|
| 119 | + ), |
|
| 120 | + |
|
| 121 | + 'question_groups' => array( |
|
| 122 | + 'func' => '_questions_groups_preview', |
|
| 123 | + 'capability' => 'ee_read_question_groups', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'update_question' => array( |
|
| 127 | + 'func' => '_insert_or_update_question', |
|
| 128 | + 'args' => array('new_question' => false), |
|
| 129 | + 'capability' => 'ee_edit_question', |
|
| 130 | + 'obj_id' => $qst_id, |
|
| 131 | + 'noheader' => true, |
|
| 132 | + ), |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + protected function _set_page_config() |
|
| 138 | + { |
|
| 139 | + $this->_page_config = array( |
|
| 140 | + 'default' => array( |
|
| 141 | + 'nav' => array( |
|
| 142 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
| 143 | + 'order' => 10, |
|
| 144 | + ), |
|
| 145 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
| 146 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 147 | + 'help_tabs' => array( |
|
| 148 | + 'registration_form_questions_overview_help_tab' => array( |
|
| 149 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
| 150 | + 'filename' => 'registration_form_questions_overview', |
|
| 151 | + ), |
|
| 152 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
| 153 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
| 154 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
| 155 | + ), |
|
| 156 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
| 157 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
| 158 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
| 159 | + ), |
|
| 160 | + ), |
|
| 161 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
| 162 | + 'require_nonce' => false, |
|
| 163 | + 'qtips' => array( |
|
| 164 | + 'EE_Registration_Form_Tips', |
|
| 165 | + )/**/ |
|
| 166 | + ), |
|
| 167 | + |
|
| 168 | + 'question_groups' => array( |
|
| 169 | + 'nav' => array( |
|
| 170 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 171 | + 'order' => 20, |
|
| 172 | + ), |
|
| 173 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 174 | + 'help_tabs' => array( |
|
| 175 | + 'registration_form_question_groups_help_tab' => array( |
|
| 176 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 177 | + 'filename' => 'registration_form_question_groups', |
|
| 178 | + ), |
|
| 179 | + ), |
|
| 180 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 181 | + 'require_nonce' => false, |
|
| 182 | + ), |
|
| 183 | + |
|
| 184 | + 'edit_question' => array( |
|
| 185 | + 'nav' => array( |
|
| 186 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
| 187 | + 'order' => 15, |
|
| 188 | + 'persistent' => false, |
|
| 189 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
| 190 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 191 | + ), |
|
| 192 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 193 | + 'help_tabs' => array( |
|
| 194 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 195 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
| 196 | + 'filename' => 'registration_form_edit_question', |
|
| 197 | + ), |
|
| 198 | + ), |
|
| 199 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
| 200 | + 'require_nonce' => false, |
|
| 201 | + ), |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + protected function _add_screen_options() |
|
| 207 | + { |
|
| 208 | + //todo |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + protected function _add_screen_options_default() |
|
| 212 | + { |
|
| 213 | + $page_title = $this->_admin_page_title; |
|
| 214 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
| 215 | + $this->_per_page_screen_option(); |
|
| 216 | + $this->_admin_page_title = $page_title; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + protected function _add_screen_options_question_groups() |
|
| 220 | + { |
|
| 221 | + $page_title = $this->_admin_page_title; |
|
| 222 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
| 223 | + $this->_per_page_screen_option(); |
|
| 224 | + $this->_admin_page_title = $page_title; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + //none of the below group are currently used for Event Categories |
|
| 228 | + protected function _add_feature_pointers() |
|
| 229 | + { |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public function load_scripts_styles() |
|
| 233 | + { |
|
| 234 | + wp_register_style('espresso_registration', |
|
| 235 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | + wp_enqueue_style('espresso_registration'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public function admin_init() |
|
| 240 | + { |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function admin_notices() |
|
| 244 | + { |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + public function admin_footer_scripts() |
|
| 248 | + { |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + public function load_scripts_styles_default() |
|
| 253 | + { |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + public function load_scripts_styles_add_question() |
|
| 258 | + { |
|
| 259 | + $this->load_scripts_styles_question_details(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function load_scripts_styles_edit_question() |
|
| 263 | + { |
|
| 264 | + $this->load_scripts_styles_question_details(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Loads the JS required for adding or editing a question |
|
| 269 | + */ |
|
| 270 | + protected function load_scripts_styles_question_details() |
|
| 271 | + { |
|
| 272 | + $this->load_scripts_styles_forms(); |
|
| 273 | + wp_register_script('espresso_registration_form_single', |
|
| 274 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 275 | + EVENT_ESPRESSO_VERSION, true); |
|
| 276 | + wp_enqueue_script('espresso_registration_form_single'); |
|
| 277 | + wp_localize_script( |
|
| 278 | + 'espresso_registration_form_single', |
|
| 279 | + 'ee_question_data', |
|
| 280 | + array( |
|
| 281 | + 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 282 | + 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
| 283 | + ) |
|
| 284 | + ); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + public function recaptcha_info_help_tab() |
|
| 289 | + { |
|
| 290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 291 | + EEH_Template::display_template($template, array()); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + public function load_scripts_styles_forms() |
|
| 296 | + { |
|
| 297 | + //styles |
|
| 298 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 299 | + //scripts |
|
| 300 | + wp_enqueue_script('ee_admin_js'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + protected function _set_list_table_views_default() |
|
| 305 | + { |
|
| 306 | + $this->_views = array( |
|
| 307 | + 'all' => array( |
|
| 308 | + 'slug' => 'all', |
|
| 309 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 310 | + 'count' => 0, |
|
| 311 | 311 | // 'bulk_action' => array( |
| 312 | 312 | // 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
| 313 | 313 | // ) |
| 314 | - ), |
|
| 315 | - ); |
|
| 316 | - |
|
| 317 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 318 | - 'espresso_registration_form_trash_questions') |
|
| 319 | - ) { |
|
| 320 | - $this->_views['trash'] = array( |
|
| 321 | - 'slug' => 'trash', |
|
| 322 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 323 | - 'count' => 0, |
|
| 314 | + ), |
|
| 315 | + ); |
|
| 316 | + |
|
| 317 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 318 | + 'espresso_registration_form_trash_questions') |
|
| 319 | + ) { |
|
| 320 | + $this->_views['trash'] = array( |
|
| 321 | + 'slug' => 'trash', |
|
| 322 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 323 | + 'count' => 0, |
|
| 324 | 324 | // 'bulk_action' => array( |
| 325 | 325 | // 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
| 326 | 326 | // 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * This just previews the question groups tab that comes in caffeinated. |
|
| 333 | - * |
|
| 334 | - * @return string html |
|
| 335 | - */ |
|
| 336 | - protected function _questions_groups_preview() |
|
| 337 | - { |
|
| 338 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
| 339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 340 | - 'event_espresso') . '" />'; |
|
| 341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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 Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 342 | - 'event_espresso') . '</strong>'; |
|
| 343 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Extracts the question field's values from the POST request to update or insert them |
|
| 349 | - * |
|
| 350 | - * @param \EEM_Base $model |
|
| 351 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
| 352 | - */ |
|
| 353 | - protected function _set_column_values_for(EEM_Base $model) |
|
| 354 | - { |
|
| 355 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 356 | - $set_column_values = array(); |
|
| 357 | - |
|
| 358 | - //some initial checks for proper values. |
|
| 359 | - //if QST_admin_only, then no matter what QST_required is we disable. |
|
| 360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 361 | - $this->_req_data['QST_required'] = 0; |
|
| 362 | - } |
|
| 363 | - //if the question shouldn't have a max length, don't let them set one |
|
| 364 | - if (! isset( |
|
| 365 | - $this->_req_data['QST_type'], |
|
| 366 | - $this->_req_data['QST_max'] |
|
| 367 | - ) |
|
| 368 | - || ! in_array( |
|
| 369 | - $this->_req_data['QST_type'], |
|
| 370 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 371 | - true) |
|
| 372 | - ) { |
|
| 373 | - //they're not allowed to set the max |
|
| 374 | - $this->_req_data['QST_max'] = null; |
|
| 375 | - } |
|
| 376 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
| 377 | - // basically if QSG_identifier is empty or not set |
|
| 378 | - if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
| 379 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
| 380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * This just previews the question groups tab that comes in caffeinated. |
|
| 333 | + * |
|
| 334 | + * @return string html |
|
| 335 | + */ |
|
| 336 | + protected function _questions_groups_preview() |
|
| 337 | + { |
|
| 338 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
| 339 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 340 | + 'event_espresso') . '" />'; |
|
| 341 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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 Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 342 | + 'event_espresso') . '</strong>'; |
|
| 343 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Extracts the question field's values from the POST request to update or insert them |
|
| 349 | + * |
|
| 350 | + * @param \EEM_Base $model |
|
| 351 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
| 352 | + */ |
|
| 353 | + protected function _set_column_values_for(EEM_Base $model) |
|
| 354 | + { |
|
| 355 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 356 | + $set_column_values = array(); |
|
| 357 | + |
|
| 358 | + //some initial checks for proper values. |
|
| 359 | + //if QST_admin_only, then no matter what QST_required is we disable. |
|
| 360 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 361 | + $this->_req_data['QST_required'] = 0; |
|
| 362 | + } |
|
| 363 | + //if the question shouldn't have a max length, don't let them set one |
|
| 364 | + if (! isset( |
|
| 365 | + $this->_req_data['QST_type'], |
|
| 366 | + $this->_req_data['QST_max'] |
|
| 367 | + ) |
|
| 368 | + || ! in_array( |
|
| 369 | + $this->_req_data['QST_type'], |
|
| 370 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
| 371 | + true) |
|
| 372 | + ) { |
|
| 373 | + //they're not allowed to set the max |
|
| 374 | + $this->_req_data['QST_max'] = null; |
|
| 375 | + } |
|
| 376 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
| 377 | + // basically if QSG_identifier is empty or not set |
|
| 378 | + if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
| 379 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
| 380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 381 | 381 | // dd($set_column_values); |
| 382 | - } //if the admin label is blank, use a slug version of the question text |
|
| 383 | - else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
| 384 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
| 385 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
| 386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 387 | - $set_column_values[$fieldName] = 0; |
|
| 388 | - } else if ($fieldName === 'QST_max') { |
|
| 389 | - $qst_system = EEM_Question::instance()->get_var( |
|
| 390 | - array( |
|
| 391 | - array( |
|
| 392 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
| 393 | - ), |
|
| 394 | - ), |
|
| 395 | - 'QST_system'); |
|
| 396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 397 | - if (empty($this->_req_data['QST_max']) || |
|
| 398 | - $this->_req_data['QST_max'] > $max_max |
|
| 399 | - ) { |
|
| 400 | - $set_column_values[$fieldName] = $max_max; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
| 406 | - if ( |
|
| 407 | - ! isset($set_column_values[$fieldName]) && |
|
| 408 | - isset($this->_req_data[$fieldName]) |
|
| 409 | - ) { |
|
| 410 | - $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - } |
|
| 414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - *_questions_overview_list_table |
|
| 420 | - */ |
|
| 421 | - protected function _questions_overview_list_table() |
|
| 422 | - { |
|
| 423 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
| 424 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * _edit_question |
|
| 430 | - */ |
|
| 431 | - protected function _edit_question() |
|
| 432 | - { |
|
| 433 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 434 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
| 435 | - |
|
| 436 | - switch ($this->_req_action) { |
|
| 437 | - case 'add_question' : |
|
| 438 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
| 439 | - break; |
|
| 440 | - case 'edit_question' : |
|
| 441 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
| 442 | - break; |
|
| 443 | - default : |
|
| 444 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // add PRC_ID to title if editing |
|
| 448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 449 | - if ($ID) { |
|
| 450 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
| 451 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 452 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
| 453 | - } else { |
|
| 454 | - $question = EE_Question::new_instance(); |
|
| 455 | - $question->set_order_to_latest(); |
|
| 456 | - $this->_set_add_edit_form_tags('insert_question'); |
|
| 457 | - } |
|
| 458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
| 459 | - $question_types = array_intersect_key( |
|
| 460 | - EEM_Question::instance()->allowed_question_types(), |
|
| 461 | - array_flip( |
|
| 462 | - array( |
|
| 463 | - EEM_Question::QST_type_text, |
|
| 464 | - EEM_Question::QST_type_us_phone |
|
| 465 | - ) |
|
| 466 | - ) |
|
| 467 | - ); |
|
| 468 | - } else { |
|
| 469 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
| 470 | - } |
|
| 471 | - $this->_template_args['QST_ID'] = $ID; |
|
| 472 | - $this->_template_args['question'] = $question; |
|
| 473 | - $this->_template_args['question_types'] = $question_types; |
|
| 474 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
| 475 | - $question->system_ID() |
|
| 476 | - ); |
|
| 477 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
| 478 | - $this->_set_publish_post_box_vars('id', $ID); |
|
| 479 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 481 | - $this->_template_args, true |
|
| 482 | - ); |
|
| 483 | - |
|
| 484 | - // the details template wrapper |
|
| 485 | - $this->display_admin_page_with_sidebar(); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - protected function _get_question_type_descriptions() |
|
| 493 | - { |
|
| 494 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 495 | - $descriptions = ''; |
|
| 496 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
| 497 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
| 498 | - if ($type == 'HTML_TEXTAREA') { |
|
| 499 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
| 500 | - $question_type_description .= sprintf( |
|
| 501 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
| 502 | - '<br/>', |
|
| 503 | - $html->get_list_of_allowed_tags() |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - $descriptions .= EEH_HTML::p( |
|
| 507 | - $question_type_description, |
|
| 508 | - 'question_type_description-' . $type, |
|
| 509 | - 'question_type_description description', |
|
| 510 | - 'display:none;' |
|
| 511 | - ); |
|
| 512 | - } |
|
| 513 | - return $descriptions; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * @param bool|true $new_question |
|
| 519 | - * @throws \EE_Error |
|
| 520 | - */ |
|
| 521 | - protected function _insert_or_update_question($new_question = true) |
|
| 522 | - { |
|
| 523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 524 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
| 525 | - if ($new_question) { |
|
| 526 | - $question = EE_Question::new_instance($set_column_values); |
|
| 527 | - $action_desc = 'added'; |
|
| 528 | - } else { |
|
| 529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
| 530 | - foreach($set_column_values as $field => $new_value) { |
|
| 531 | - $question->set($field, $new_value); |
|
| 532 | - } |
|
| 533 | - $action_desc = 'updated'; |
|
| 534 | - } |
|
| 535 | - $success = $question->save(); |
|
| 536 | - $ID = $question->ID(); |
|
| 537 | - if ($ID && $question->should_have_question_options()) { |
|
| 538 | - //save the related options |
|
| 539 | - //trash removed options, save old ones |
|
| 540 | - //get list of all options |
|
| 541 | - $options = $question->options(); |
|
| 542 | - if (! empty($options)) { |
|
| 543 | - foreach ($options as $option_ID => $option) { |
|
| 544 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
| 545 | - if ($option_req_index !== false) { |
|
| 546 | - $option->save($this->_req_data['question_options'][$option_req_index]); |
|
| 547 | - } else { |
|
| 548 | - //not found, remove it |
|
| 549 | - $option->delete(); |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - //save new related options |
|
| 554 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
| 555 | - //skip $index that is from our sample |
|
| 556 | - if ( $index === 'xxcountxx' ) { |
|
| 557 | - continue; |
|
| 558 | - } |
|
| 559 | - //note we allow saving blank options. |
|
| 560 | - if (empty($option_req_data['QSO_ID']) |
|
| 561 | - ) {//no ID! save it! |
|
| 562 | - $new_option = EE_Question_Option::new_instance(array( |
|
| 563 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
| 564 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
| 565 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
| 566 | - 'QST_ID' => $question->ID(), |
|
| 567 | - )); |
|
| 568 | - $new_option->save(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
| 573 | - if ($success !== false) { |
|
| 574 | - $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 575 | - $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
| 576 | - $this->_question_model->item_name()); |
|
| 577 | - EE_Error::add_success($msg); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
| 586 | - * by ID |
|
| 587 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
| 588 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
| 589 | - * |
|
| 590 | - * @param int $ID of the question option to find |
|
| 591 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
| 592 | - */ |
|
| 593 | - protected function _get_option_req_data_index($ID) |
|
| 594 | - { |
|
| 595 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
| 596 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
| 597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 598 | - return $num; |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /***********/ |
|
| 608 | - /* QUERIES */ |
|
| 609 | - /** |
|
| 610 | - * For internal use in getting all the query parameters |
|
| 611 | - * (because it's pretty well the same between question, question groups, |
|
| 612 | - * and for both when searching for trashed and untrashed ones) |
|
| 613 | - * |
|
| 614 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
| 615 | - * @param int $per_page |
|
| 616 | - * @param int $current_page |
|
| 617 | - * @return array lik EEM_Base::get_all's $query_params parameter |
|
| 618 | - */ |
|
| 619 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
| 620 | - { |
|
| 621 | - $query_params = array(); |
|
| 622 | - $offset = ($current_page - 1) * $per_page; |
|
| 623 | - $query_params['limit'] = array($offset, $per_page); |
|
| 624 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 625 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
| 626 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
| 627 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
| 628 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
| 629 | - if (! empty($search_string)) { |
|
| 630 | - if ($model instanceof EEM_Question_Group) { |
|
| 631 | - $query_params[0] = array( |
|
| 632 | - 'OR' => array( |
|
| 633 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
| 634 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
| 635 | - ), |
|
| 636 | - ); |
|
| 637 | - } else { |
|
| 638 | - $query_params[0] = array( |
|
| 639 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
| 640 | - ); |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
| 645 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
| 382 | + } //if the admin label is blank, use a slug version of the question text |
|
| 383 | + else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
| 384 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
| 385 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
| 386 | + } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 387 | + $set_column_values[$fieldName] = 0; |
|
| 388 | + } else if ($fieldName === 'QST_max') { |
|
| 389 | + $qst_system = EEM_Question::instance()->get_var( |
|
| 390 | + array( |
|
| 391 | + array( |
|
| 392 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
| 393 | + ), |
|
| 394 | + ), |
|
| 395 | + 'QST_system'); |
|
| 396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 397 | + if (empty($this->_req_data['QST_max']) || |
|
| 398 | + $this->_req_data['QST_max'] > $max_max |
|
| 399 | + ) { |
|
| 400 | + $set_column_values[$fieldName] = $max_max; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
| 406 | + if ( |
|
| 407 | + ! isset($set_column_values[$fieldName]) && |
|
| 408 | + isset($this->_req_data[$fieldName]) |
|
| 409 | + ) { |
|
| 410 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + } |
|
| 414 | + return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + *_questions_overview_list_table |
|
| 420 | + */ |
|
| 421 | + protected function _questions_overview_list_table() |
|
| 422 | + { |
|
| 423 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
| 424 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * _edit_question |
|
| 430 | + */ |
|
| 431 | + protected function _edit_question() |
|
| 432 | + { |
|
| 433 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 434 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
| 435 | + |
|
| 436 | + switch ($this->_req_action) { |
|
| 437 | + case 'add_question' : |
|
| 438 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
| 439 | + break; |
|
| 440 | + case 'edit_question' : |
|
| 441 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
| 442 | + break; |
|
| 443 | + default : |
|
| 444 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // add PRC_ID to title if editing |
|
| 448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 449 | + if ($ID) { |
|
| 450 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
| 451 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 452 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
| 453 | + } else { |
|
| 454 | + $question = EE_Question::new_instance(); |
|
| 455 | + $question->set_order_to_latest(); |
|
| 456 | + $this->_set_add_edit_form_tags('insert_question'); |
|
| 457 | + } |
|
| 458 | + if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
| 459 | + $question_types = array_intersect_key( |
|
| 460 | + EEM_Question::instance()->allowed_question_types(), |
|
| 461 | + array_flip( |
|
| 462 | + array( |
|
| 463 | + EEM_Question::QST_type_text, |
|
| 464 | + EEM_Question::QST_type_us_phone |
|
| 465 | + ) |
|
| 466 | + ) |
|
| 467 | + ); |
|
| 468 | + } else { |
|
| 469 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
| 470 | + } |
|
| 471 | + $this->_template_args['QST_ID'] = $ID; |
|
| 472 | + $this->_template_args['question'] = $question; |
|
| 473 | + $this->_template_args['question_types'] = $question_types; |
|
| 474 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
| 475 | + $question->system_ID() |
|
| 476 | + ); |
|
| 477 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
| 478 | + $this->_set_publish_post_box_vars('id', $ID); |
|
| 479 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 480 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 481 | + $this->_template_args, true |
|
| 482 | + ); |
|
| 483 | + |
|
| 484 | + // the details template wrapper |
|
| 485 | + $this->display_admin_page_with_sidebar(); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + protected function _get_question_type_descriptions() |
|
| 493 | + { |
|
| 494 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 495 | + $descriptions = ''; |
|
| 496 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
| 497 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
| 498 | + if ($type == 'HTML_TEXTAREA') { |
|
| 499 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
| 500 | + $question_type_description .= sprintf( |
|
| 501 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
| 502 | + '<br/>', |
|
| 503 | + $html->get_list_of_allowed_tags() |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + $descriptions .= EEH_HTML::p( |
|
| 507 | + $question_type_description, |
|
| 508 | + 'question_type_description-' . $type, |
|
| 509 | + 'question_type_description description', |
|
| 510 | + 'display:none;' |
|
| 511 | + ); |
|
| 512 | + } |
|
| 513 | + return $descriptions; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * @param bool|true $new_question |
|
| 519 | + * @throws \EE_Error |
|
| 520 | + */ |
|
| 521 | + protected function _insert_or_update_question($new_question = true) |
|
| 522 | + { |
|
| 523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 524 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
| 525 | + if ($new_question) { |
|
| 526 | + $question = EE_Question::new_instance($set_column_values); |
|
| 527 | + $action_desc = 'added'; |
|
| 528 | + } else { |
|
| 529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
| 530 | + foreach($set_column_values as $field => $new_value) { |
|
| 531 | + $question->set($field, $new_value); |
|
| 532 | + } |
|
| 533 | + $action_desc = 'updated'; |
|
| 534 | + } |
|
| 535 | + $success = $question->save(); |
|
| 536 | + $ID = $question->ID(); |
|
| 537 | + if ($ID && $question->should_have_question_options()) { |
|
| 538 | + //save the related options |
|
| 539 | + //trash removed options, save old ones |
|
| 540 | + //get list of all options |
|
| 541 | + $options = $question->options(); |
|
| 542 | + if (! empty($options)) { |
|
| 543 | + foreach ($options as $option_ID => $option) { |
|
| 544 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
| 545 | + if ($option_req_index !== false) { |
|
| 546 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
| 547 | + } else { |
|
| 548 | + //not found, remove it |
|
| 549 | + $option->delete(); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + //save new related options |
|
| 554 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
| 555 | + //skip $index that is from our sample |
|
| 556 | + if ( $index === 'xxcountxx' ) { |
|
| 557 | + continue; |
|
| 558 | + } |
|
| 559 | + //note we allow saving blank options. |
|
| 560 | + if (empty($option_req_data['QSO_ID']) |
|
| 561 | + ) {//no ID! save it! |
|
| 562 | + $new_option = EE_Question_Option::new_instance(array( |
|
| 563 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
| 564 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
| 565 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
| 566 | + 'QST_ID' => $question->ID(), |
|
| 567 | + )); |
|
| 568 | + $new_option->save(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
| 573 | + if ($success !== false) { |
|
| 574 | + $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 575 | + $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
| 576 | + $this->_question_model->item_name()); |
|
| 577 | + EE_Error::add_success($msg); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
| 586 | + * by ID |
|
| 587 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
| 588 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
| 589 | + * |
|
| 590 | + * @param int $ID of the question option to find |
|
| 591 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
| 592 | + */ |
|
| 593 | + protected function _get_option_req_data_index($ID) |
|
| 594 | + { |
|
| 595 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
| 596 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
| 597 | + if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 598 | + return $num; |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /***********/ |
|
| 608 | + /* QUERIES */ |
|
| 609 | + /** |
|
| 610 | + * For internal use in getting all the query parameters |
|
| 611 | + * (because it's pretty well the same between question, question groups, |
|
| 612 | + * and for both when searching for trashed and untrashed ones) |
|
| 613 | + * |
|
| 614 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
| 615 | + * @param int $per_page |
|
| 616 | + * @param int $current_page |
|
| 617 | + * @return array lik EEM_Base::get_all's $query_params parameter |
|
| 618 | + */ |
|
| 619 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
| 620 | + { |
|
| 621 | + $query_params = array(); |
|
| 622 | + $offset = ($current_page - 1) * $per_page; |
|
| 623 | + $query_params['limit'] = array($offset, $per_page); |
|
| 624 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 625 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
| 626 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
| 627 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
| 628 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
| 629 | + if (! empty($search_string)) { |
|
| 630 | + if ($model instanceof EEM_Question_Group) { |
|
| 631 | + $query_params[0] = array( |
|
| 632 | + 'OR' => array( |
|
| 633 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
| 634 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
| 635 | + ), |
|
| 636 | + ); |
|
| 637 | + } else { |
|
| 638 | + $query_params[0] = array( |
|
| 639 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
| 640 | + ); |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
| 645 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
| 646 | 646 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
| 647 | 647 | $query_params[0] = array( |
| 648 | 648 | 'AND' => array( |
@@ -672,62 +672,62 @@ discard block |
||
| 672 | 672 | } |
| 673 | 673 | }/**/ |
| 674 | 674 | |
| 675 | - return $query_params; |
|
| 676 | - |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * @param int $per_page |
|
| 682 | - * @param int $current_page |
|
| 683 | - * @param bool|false $count |
|
| 684 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 685 | - */ |
|
| 686 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
| 687 | - { |
|
| 688 | - $QST = EEM_Question::instance(); |
|
| 689 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
| 690 | - if ($count) { |
|
| 691 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 692 | - $results = $QST->count($where); |
|
| 693 | - } else { |
|
| 694 | - $results = $QST->get_all($query_params); |
|
| 695 | - } |
|
| 696 | - return $results; |
|
| 697 | - |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * @param $per_page |
|
| 703 | - * @param int $current_page |
|
| 704 | - * @param bool|false $count |
|
| 705 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 706 | - */ |
|
| 707 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 708 | - { |
|
| 709 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 710 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 711 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 712 | - return $questions; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * @param $per_page |
|
| 718 | - * @param int $current_page |
|
| 719 | - * @param bool|false $count |
|
| 720 | - * @return \EE_Soft_Delete_Base_Class[] |
|
| 721 | - */ |
|
| 722 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 723 | - { |
|
| 724 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
| 725 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 726 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 727 | - return $questionGroupModel->get_all( |
|
| 728 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
| 729 | - ); |
|
| 730 | - } |
|
| 675 | + return $query_params; |
|
| 676 | + |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * @param int $per_page |
|
| 682 | + * @param int $current_page |
|
| 683 | + * @param bool|false $count |
|
| 684 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 685 | + */ |
|
| 686 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
| 687 | + { |
|
| 688 | + $QST = EEM_Question::instance(); |
|
| 689 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
| 690 | + if ($count) { |
|
| 691 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 692 | + $results = $QST->count($where); |
|
| 693 | + } else { |
|
| 694 | + $results = $QST->get_all($query_params); |
|
| 695 | + } |
|
| 696 | + return $results; |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * @param $per_page |
|
| 703 | + * @param int $current_page |
|
| 704 | + * @param bool|false $count |
|
| 705 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 706 | + */ |
|
| 707 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 708 | + { |
|
| 709 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 710 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 711 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 712 | + return $questions; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * @param $per_page |
|
| 718 | + * @param int $current_page |
|
| 719 | + * @param bool|false $count |
|
| 720 | + * @return \EE_Soft_Delete_Base_Class[] |
|
| 721 | + */ |
|
| 722 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 723 | + { |
|
| 724 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
| 725 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 726 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 727 | + return $questionGroupModel->get_all( |
|
| 728 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
| 729 | + ); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | } //ends Registration_Form_Admin_Page class |
@@ -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 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function __construct($routing = true) |
| 68 | 68 | { |
| 69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
| 70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
| 69 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
| 70 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
| 71 | 71 | $this->_question_model = EEM_Question::instance(); |
| 72 | 72 | $this->_question_group_model = EEM_Question_Group::instance(); |
| 73 | 73 | parent::__construct($routing); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | public function load_scripts_styles() |
| 233 | 233 | { |
| 234 | 234 | wp_register_style('espresso_registration', |
| 235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 235 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 236 | 236 | wp_enqueue_style('espresso_registration'); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | { |
| 272 | 272 | $this->load_scripts_styles_forms(); |
| 273 | 273 | wp_register_script('espresso_registration_form_single', |
| 274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 274 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
| 275 | 275 | EVENT_ESPRESSO_VERSION, true); |
| 276 | 276 | wp_enqueue_script('espresso_registration_form_single'); |
| 277 | 277 | wp_localize_script( |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | public function recaptcha_info_help_tab() |
| 289 | 289 | { |
| 290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
| 291 | 291 | EEH_Template::display_template($template, array()); |
| 292 | 292 | } |
| 293 | 293 | |
@@ -336,10 +336,10 @@ discard block |
||
| 336 | 336 | protected function _questions_groups_preview() |
| 337 | 337 | { |
| 338 | 338 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
| 339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 340 | - 'event_espresso') . '" />'; |
|
| 341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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 Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 342 | - 'event_espresso') . '</strong>'; |
|
| 339 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
| 340 | + 'event_espresso').'" />'; |
|
| 341 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups 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 Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
| 342 | + 'event_espresso').'</strong>'; |
|
| 343 | 343 | $this->display_admin_caf_preview_page('question_groups_tab'); |
| 344 | 344 | } |
| 345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | //some initial checks for proper values. |
| 359 | 359 | //if QST_admin_only, then no matter what QST_required is we disable. |
| 360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
| 360 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
| 361 | 361 | $this->_req_data['QST_required'] = 0; |
| 362 | 362 | } |
| 363 | 363 | //if the question shouldn't have a max length, don't let them set one |
| 364 | - if (! isset( |
|
| 364 | + if ( ! isset( |
|
| 365 | 365 | $this->_req_data['QST_type'], |
| 366 | 366 | $this->_req_data['QST_max'] |
| 367 | 367 | ) |
@@ -377,13 +377,13 @@ discard block |
||
| 377 | 377 | // basically if QSG_identifier is empty or not set |
| 378 | 378 | if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
| 379 | 379 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
| 380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
| 380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
| 381 | 381 | // dd($set_column_values); |
| 382 | 382 | } //if the admin label is blank, use a slug version of the question text |
| 383 | 383 | else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
| 384 | 384 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
| 385 | 385 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
| 386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
| 386 | + } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
| 387 | 387 | $set_column_values[$fieldName] = 0; |
| 388 | 388 | } else if ($fieldName === 'QST_max') { |
| 389 | 389 | $qst_system = EEM_Question::instance()->get_var( |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | ), |
| 394 | 394 | ), |
| 395 | 395 | 'QST_system'); |
| 396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
| 397 | 397 | if (empty($this->_req_data['QST_max']) || |
| 398 | 398 | $this->_req_data['QST_max'] > $max_max |
| 399 | 399 | ) { |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | } |
| 414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 414 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // add PRC_ID to title if editing |
| 448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 449 | 449 | if ($ID) { |
| 450 | 450 | $question = $this->_question_model->get_one_by_ID($ID); |
| 451 | 451 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | $question->set_order_to_latest(); |
| 456 | 456 | $this->_set_add_edit_form_tags('insert_question'); |
| 457 | 457 | } |
| 458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
| 458 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
| 459 | 459 | $question_types = array_intersect_key( |
| 460 | 460 | EEM_Question::instance()->allowed_question_types(), |
| 461 | 461 | array_flip( |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
| 478 | 478 | $this->_set_publish_post_box_vars('id', $ID); |
| 479 | 479 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
| 480 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
| 481 | 481 | $this->_template_args, true |
| 482 | 482 | ); |
| 483 | 483 | |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | $descriptions .= EEH_HTML::p( |
| 507 | 507 | $question_type_description, |
| 508 | - 'question_type_description-' . $type, |
|
| 508 | + 'question_type_description-'.$type, |
|
| 509 | 509 | 'question_type_description description', |
| 510 | 510 | 'display:none;' |
| 511 | 511 | ); |
@@ -526,8 +526,8 @@ discard block |
||
| 526 | 526 | $question = EE_Question::new_instance($set_column_values); |
| 527 | 527 | $action_desc = 'added'; |
| 528 | 528 | } else { |
| 529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
| 530 | - foreach($set_column_values as $field => $new_value) { |
|
| 529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
| 530 | + foreach ($set_column_values as $field => $new_value) { |
|
| 531 | 531 | $question->set($field, $new_value); |
| 532 | 532 | } |
| 533 | 533 | $action_desc = 'updated'; |
@@ -538,8 +538,8 @@ discard block |
||
| 538 | 538 | //save the related options |
| 539 | 539 | //trash removed options, save old ones |
| 540 | 540 | //get list of all options |
| 541 | - $options = $question->options(); |
|
| 542 | - if (! empty($options)) { |
|
| 541 | + $options = $question->options(); |
|
| 542 | + if ( ! empty($options)) { |
|
| 543 | 543 | foreach ($options as $option_ID => $option) { |
| 544 | 544 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
| 545 | 545 | if ($option_req_index !== false) { |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | //save new related options |
| 554 | 554 | foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
| 555 | 555 | //skip $index that is from our sample |
| 556 | - if ( $index === 'xxcountxx' ) { |
|
| 556 | + if ($index === 'xxcountxx') { |
|
| 557 | 557 | continue; |
| 558 | 558 | } |
| 559 | 559 | //note we allow saving blank options. |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | { |
| 595 | 595 | $req_data_for_question_options = $this->_req_data['question_options']; |
| 596 | 596 | foreach ($req_data_for_question_options as $num => $option_data) { |
| 597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
| 597 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
| 598 | 598 | return $num; |
| 599 | 599 | } |
| 600 | 600 | } |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
| 627 | 627 | $query_params['order_by'] = array($field_to_order_by => $order); |
| 628 | 628 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
| 629 | - if (! empty($search_string)) { |
|
| 629 | + if ( ! empty($search_string)) { |
|
| 630 | 630 | if ($model instanceof EEM_Question_Group) { |
| 631 | 631 | $query_params[0] = array( |
| 632 | 632 | 'OR' => array( |
@@ -21,724 +21,724 @@ |
||
| 21 | 21 | abstract class EE_PMT_Base |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - const onsite = 'on-site'; |
|
| 25 | - const offsite = 'off-site'; |
|
| 26 | - const offline = 'off-line'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var EE_Payment_Method |
|
| 30 | - */ |
|
| 31 | - protected $_pm_instance = NULL; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean |
|
| 35 | - */ |
|
| 36 | - protected $_requires_https = FALSE; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var boolean |
|
| 40 | - */ |
|
| 41 | - protected $_has_billing_form; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Gateway |
|
| 45 | - */ |
|
| 46 | - protected $_gateway = NULL; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var EE_Payment_Method_Form |
|
| 50 | - */ |
|
| 51 | - protected $_settings_form = NULL; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var EE_Form_Section_Proper |
|
| 55 | - */ |
|
| 56 | - protected $_billing_form = NULL; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var boolean |
|
| 60 | - */ |
|
| 61 | - protected $_cache_billing_form = TRUE; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * String of the absolute path to the folder containing this file, with a trailing slash. |
|
| 65 | - * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - protected $_file_folder = NULL; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
| 72 | - * like images, js, or css) |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_file_url = NULL; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Pretty name for the payment method |
|
| 79 | - * @var string |
|
| 80 | - */ |
|
| 81 | - protected $_pretty_name = NULL; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * |
|
| 85 | - * @var string |
|
| 86 | - */ |
|
| 87 | - protected $_default_button_url = NULL; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - protected $_default_description = NULL; |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * |
|
| 98 | - * @param EE_Payment_Method $pm_instance |
|
| 99 | - * @throws EE_Error |
|
| 100 | - * @return EE_PMT_Base |
|
| 101 | - */ |
|
| 102 | - function __construct($pm_instance = NULL) |
|
| 103 | - { |
|
| 104 | - if ($pm_instance instanceof EE_Payment_Method) { |
|
| 105 | - $this->set_instance($pm_instance); |
|
| 106 | - } |
|
| 107 | - if ($this->_gateway) { |
|
| 108 | - $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
| 109 | - $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
| 110 | - $this->_gateway->set_template_helper(new EEH_Template()); |
|
| 111 | - $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
| 112 | - $this->_gateway->set_money_helper(new EEH_Money()); |
|
| 113 | - $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
| 114 | - $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
| 115 | - do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
| 116 | - } |
|
| 117 | - if (!isset($this->_has_billing_form)) { |
|
| 118 | - // by default, On Site gateways have a billing form |
|
| 119 | - if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
| 120 | - $this->set_has_billing_form(true); |
|
| 121 | - } else { |
|
| 122 | - $this->set_has_billing_form(false); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$this->_pretty_name) { |
|
| 127 | - throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
|
| 128 | - } |
|
| 129 | - //if the child didn't specify a default button, use the credit card one |
|
| 130 | - if ($this->_default_button_url === NULL) { |
|
| 131 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param boolean $has_billing_form |
|
| 138 | - */ |
|
| 139 | - public function set_has_billing_form($has_billing_form) |
|
| 140 | - { |
|
| 141 | - $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * sets the file_folder property |
|
| 147 | - */ |
|
| 148 | - protected function _set_file_folder() |
|
| 149 | - { |
|
| 150 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 151 | - $fn = $reflector->getFileName(); |
|
| 152 | - $this->_file_folder = dirname($fn) . DS; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * sets the file URL with a trailing slash for this PMT |
|
| 158 | - */ |
|
| 159 | - protected function _set_file_url() |
|
| 160 | - { |
|
| 161 | - $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
| 162 | - $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
| 163 | - $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
| 164 | - $this->_file_url = $file_path; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Gets the default description on all payment methods of this type |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - public function default_description() |
|
| 172 | - { |
|
| 173 | - return $this->_default_description; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Returns the folder containing the PMT child class, with a trailing slash |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function file_folder() |
|
| 182 | - { |
|
| 183 | - if (!$this->_file_folder) { |
|
| 184 | - $this->_set_file_folder(); |
|
| 185 | - } |
|
| 186 | - return $this->_file_folder; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public function file_url() |
|
| 194 | - { |
|
| 195 | - if (!$this->_file_url) { |
|
| 196 | - $this->_set_file_url(); |
|
| 197 | - } |
|
| 198 | - return $this->_file_url; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Sets the payment method instance this payment method type is for. |
|
| 204 | - * Its important teh payment method instance is set before |
|
| 205 | - * @param EE_Payment_Method $payment_method_instance |
|
| 206 | - */ |
|
| 207 | - function set_instance($payment_method_instance) |
|
| 208 | - { |
|
| 209 | - $this->_pm_instance = $payment_method_instance; |
|
| 210 | - //if they have already requested the settings form, make sure its |
|
| 211 | - //data matches this model object |
|
| 212 | - if ($this->_settings_form) { |
|
| 213 | - $this->settings_form()->populate_model_obj($payment_method_instance); |
|
| 214 | - } |
|
| 215 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 216 | - $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Gets teh form for displaying to admins where they setup the payment method |
|
| 223 | - * @return EE_Payment_Method_Form |
|
| 224 | - */ |
|
| 225 | - function settings_form() |
|
| 226 | - { |
|
| 227 | - if (!$this->_settings_form) { |
|
| 228 | - $this->_settings_form = $this->generate_new_settings_form(); |
|
| 229 | - $this->_settings_form->set_payment_method_type($this); |
|
| 230 | - //if we have already assigned a model object to this pmt, make |
|
| 231 | - //sure its reflected in teh form we just generated |
|
| 232 | - if ($this->_pm_instance) { |
|
| 233 | - $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - return $this->_settings_form; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Gets the form for all the settings related to this payment method type |
|
| 242 | - * @return EE_Payment_Method_Form |
|
| 243 | - */ |
|
| 244 | - abstract function generate_new_settings_form(); |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Sets the form for settings. This may be useful if we have already received |
|
| 249 | - * a form submission and have form data it in, and want to use it anytime we're showing |
|
| 250 | - * this payment method type's settings form later in the request |
|
| 251 | - * @param EE_Payment_Method_Form $form |
|
| 252 | - */ |
|
| 253 | - public function set_settings_form($form) |
|
| 254 | - { |
|
| 255 | - $this->_settings_form = $form; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return boolean |
|
| 261 | - */ |
|
| 262 | - public function has_billing_form() |
|
| 263 | - { |
|
| 264 | - return $this->_has_billing_form; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Gets the form for displaying to attendees where they can enter their billing info |
|
| 270 | - * which will be sent to teh gateway (can be null) |
|
| 271 | - * |
|
| 272 | - * @param \EE_Transaction $transaction |
|
| 273 | - * @param array $extra_args |
|
| 274 | - * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
| 275 | - */ |
|
| 276 | - public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
|
| 277 | - { |
|
| 278 | - // has billing form already been regenerated ? or overwrite cache? |
|
| 279 | - if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
| 280 | - $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
| 281 | - } |
|
| 282 | - //if we know who the attendee is, and this is a billing form |
|
| 283 | - //that uses attendee info, populate it |
|
| 284 | - if ( |
|
| 285 | - apply_filters( |
|
| 286 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 287 | - ( |
|
| 288 | - $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 289 | - && $transaction instanceof EE_Transaction |
|
| 290 | - && $transaction->primary_registration() instanceof EE_Registration |
|
| 291 | - && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
| 292 | - ), |
|
| 293 | - $this->_billing_form, |
|
| 294 | - $transaction |
|
| 295 | - ) |
|
| 296 | - ) { |
|
| 297 | - $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
| 298 | - } |
|
| 299 | - return $this->_billing_form; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Creates the billing form for this payment method type |
|
| 305 | - * @param \EE_Transaction $transaction |
|
| 306 | - * @return \EE_Billing_Info_Form |
|
| 307 | - */ |
|
| 308 | - abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * apply_billing_form_debug_settings |
|
| 313 | - * applies debug data to the form |
|
| 314 | - * |
|
| 315 | - * @param \EE_Billing_Info_Form $billing_form |
|
| 316 | - * @return \EE_Billing_Info_Form |
|
| 317 | - */ |
|
| 318 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
| 319 | - { |
|
| 320 | - return $billing_form; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Sets the billing form for this payment method type. You may want to use this |
|
| 326 | - * if you have form |
|
| 327 | - * @param EE_Payment_Method $form |
|
| 328 | - */ |
|
| 329 | - public function set_billing_form($form) |
|
| 330 | - { |
|
| 331 | - $this->_billing_form = $form; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Returns whether or not this payment method requires HTTPS to be used |
|
| 337 | - * @return boolean |
|
| 338 | - */ |
|
| 339 | - function requires_https() |
|
| 340 | - { |
|
| 341 | - return $this->_requires_https; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * |
|
| 347 | - * @param EE_Transaction $transaction |
|
| 348 | - * @param float $amount |
|
| 349 | - * @param EE_Billing_Info_Form $billing_info |
|
| 350 | - * @param string $return_url |
|
| 351 | - * @param string $fail_url |
|
| 352 | - * @param string $method |
|
| 353 | - * @param bool $by_admin |
|
| 354 | - * @return EE_Payment |
|
| 355 | - * @throws EE_Error |
|
| 356 | - */ |
|
| 357 | - function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) |
|
| 358 | - { |
|
| 359 | - // @todo: add surcharge for the payment method, if any |
|
| 360 | - if ($this->_gateway) { |
|
| 361 | - //there is a gateway, so we're going to make a payment object |
|
| 362 | - //but wait! do they already have a payment in progress that we thought was failed? |
|
| 363 | - $duplicate_properties = array( |
|
| 364 | - 'STS_ID' => EEM_Payment::status_id_failed, |
|
| 365 | - 'TXN_ID' => $transaction->ID(), |
|
| 366 | - 'PMD_ID' => $this->_pm_instance->ID(), |
|
| 367 | - 'PAY_source' => $method, |
|
| 368 | - 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
| 369 | - 'PAY_gateway_response' => null, |
|
| 370 | - ); |
|
| 371 | - $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
| 372 | - //if we didn't already have a payment in progress for the same thing, |
|
| 373 | - //then we actually want to make a new payment |
|
| 374 | - if (!$payment instanceof EE_Payment) { |
|
| 375 | - $payment = EE_Payment::new_instance( |
|
| 376 | - array_merge( |
|
| 377 | - $duplicate_properties, |
|
| 378 | - array( |
|
| 379 | - 'PAY_timestamp' => time(), |
|
| 380 | - 'PAY_txn_id_chq_nmbr' => null, |
|
| 381 | - 'PAY_po_number' => null, |
|
| 382 | - 'PAY_extra_accntng' => null, |
|
| 383 | - 'PAY_details' => null, |
|
| 384 | - ) |
|
| 385 | - ) |
|
| 386 | - ); |
|
| 387 | - } |
|
| 388 | - //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
| 389 | - $payment->save(); |
|
| 390 | - $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
| 391 | - |
|
| 392 | - // Offsite Gateway |
|
| 393 | - if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 394 | - |
|
| 395 | - $payment = $this->_gateway->set_redirection_info( |
|
| 396 | - $payment, |
|
| 397 | - $billing_values, |
|
| 398 | - $return_url, |
|
| 399 | - EE_Config::instance()->core->txn_page_url( |
|
| 400 | - array( |
|
| 401 | - 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
| 402 | - 'ee_payment_method' => $this->_pm_instance->slug() |
|
| 403 | - ) |
|
| 404 | - ), |
|
| 405 | - $fail_url |
|
| 406 | - ); |
|
| 407 | - $payment->save(); |
|
| 408 | - // Onsite Gateway |
|
| 409 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 410 | - |
|
| 411 | - $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
| 412 | - $payment->save(); |
|
| 413 | - |
|
| 414 | - } else { |
|
| 415 | - throw new EE_Error( |
|
| 416 | - sprintf( |
|
| 417 | - __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
| 418 | - get_class($this), |
|
| 419 | - gettype($this->_gateway) |
|
| 420 | - ) |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - } else { |
|
| 425 | - // no gateway provided |
|
| 426 | - // there is no payment. Must be an offline gateway |
|
| 427 | - // create a payment object anyways, but dont save it |
|
| 428 | - $payment = EE_Payment::new_instance( |
|
| 429 | - array( |
|
| 430 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 431 | - 'TXN_ID' => $transaction->ID(), |
|
| 432 | - 'PMD_ID' => $transaction->payment_method_ID(), |
|
| 433 | - 'PAY_amount' => 0.00, |
|
| 434 | - 'PAY_timestamp' => time(), |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // if there is billing info, clean it and save it now |
|
| 441 | - if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
| 442 | - $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - return $payment; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Gets the values we want to pass onto the gateway. Normally these |
|
| 450 | - * are just the 'pretty' values, but there may be times the data may need |
|
| 451 | - * a little massaging. Proper subsections will become arrays of inputs |
|
| 452 | - * @param EE_Billing_Info_Form $billing_form |
|
| 453 | - * @return array |
|
| 454 | - */ |
|
| 455 | - protected function _get_billing_values_from_form($billing_form) |
|
| 456 | - { |
|
| 457 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 458 | - return $billing_form->input_pretty_values(true); |
|
| 459 | - } else { |
|
| 460 | - return NULL; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Handles an instant payment notification when the transaction is known (by default). |
|
| 467 | - * @param array $req_data |
|
| 468 | - * @param EE_Transaction $transaction |
|
| 469 | - * @return EE_Payment |
|
| 470 | - * @throws EE_Error |
|
| 471 | - */ |
|
| 472 | - public function handle_ipn($req_data, $transaction) |
|
| 473 | - { |
|
| 474 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 475 | - if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 476 | - throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
| 477 | - |
|
| 478 | - } |
|
| 479 | - $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
| 480 | - return $payment; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
| 486 | - * cleans it first. |
|
| 487 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 488 | - * @param EE_Transaction $transaction |
|
| 489 | - * @return boolean success |
|
| 490 | - */ |
|
| 491 | - protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
| 492 | - { |
|
| 493 | - if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
| 494 | - EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - $primary_reg = $transaction->primary_registration(); |
|
| 498 | - if (!$primary_reg) { |
|
| 499 | - EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 500 | - return false; |
|
| 501 | - } |
|
| 502 | - $attendee = $primary_reg->attendee(); |
|
| 503 | - if (!$attendee) { |
|
| 504 | - EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 505 | - return false; |
|
| 506 | - } |
|
| 507 | - return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
| 508 | - |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Gets the payment this IPN is for. Children may often want to |
|
| 514 | - * override this to inspect the request |
|
| 515 | - * @param EE_Transaction $transaction |
|
| 516 | - * @param array $req_data |
|
| 517 | - * @return EE_Payment |
|
| 518 | - */ |
|
| 519 | - protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
| 520 | - { |
|
| 521 | - return $transaction->last_payment(); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * In case generic code cannot provide the payment processor with a specific payment method |
|
| 527 | - * and transaction, it will try calling this method on each activate payment method. |
|
| 528 | - * If the payment method is able to identify the request as being for it, it should fetch |
|
| 529 | - * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
| 530 | - * handle the IPN |
|
| 531 | - * @param array $req_data |
|
| 532 | - * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
| 533 | - * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
| 534 | - * @throws EE_Error |
|
| 535 | - */ |
|
| 536 | - public function handle_unclaimed_ipn($req_data = array()) |
|
| 537 | - { |
|
| 538 | - throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Logic to be accomplished when the payment attempt is complete. |
|
| 544 | - * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
| 545 | - * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
| 546 | - * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
| 547 | - * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
| 548 | - * we're dealing with. Returns that last payment (if there is one) |
|
| 549 | - * |
|
| 550 | - * @param EE_Transaction $transaction |
|
| 551 | - * @return EE_Payment |
|
| 552 | - */ |
|
| 553 | - public function finalize_payment_for($transaction) |
|
| 554 | - { |
|
| 555 | - return $transaction->last_payment(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Whether or not this payment method's gateway supports sending refund requests |
|
| 561 | - * @return boolean |
|
| 562 | - */ |
|
| 563 | - public function supports_sending_refunds() |
|
| 564 | - { |
|
| 565 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 566 | - return $this->_gateway->supports_sending_refunds(); |
|
| 567 | - } else { |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * |
|
| 575 | - * @param EE_Payment $payment |
|
| 576 | - * @param array $refund_info |
|
| 577 | - * @throws EE_Error |
|
| 578 | - * @return EE_Payment |
|
| 579 | - */ |
|
| 580 | - public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
| 581 | - { |
|
| 582 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 583 | - return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
| 584 | - } else { |
|
| 585 | - throw new EE_Error( |
|
| 586 | - sprintf( |
|
| 587 | - __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
| 588 | - get_class($this) |
|
| 589 | - ) |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
| 597 | - * payment method's gateway. |
|
| 598 | - * @return string |
|
| 599 | - * @throws EE_Error |
|
| 600 | - */ |
|
| 601 | - public function payment_occurs() |
|
| 602 | - { |
|
| 603 | - if (!$this->_gateway) { |
|
| 604 | - return EE_PMT_Base::offline; |
|
| 605 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 606 | - return EE_PMT_Base::onsite; |
|
| 607 | - } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 608 | - return EE_PMT_Base::offsite; |
|
| 609 | - } else { |
|
| 610 | - throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * For adding any html output ab ove the payment overview. |
|
| 617 | - * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
| 618 | - * Other gateways may want to override this, such as offline gateways. |
|
| 619 | - * @param EE_Payment $payment |
|
| 620 | - * @return string |
|
| 621 | - */ |
|
| 622 | - public function payment_overview_content(EE_Payment $payment) |
|
| 623 | - { |
|
| 624 | - return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * @return array where keys are the help tab name, |
|
| 630 | - * values are: array { |
|
| 631 | - * @type string $title i18n name for the help tab |
|
| 632 | - * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
| 633 | - * @type array $template_args any arguments you want passed to the template file while rendering. |
|
| 634 | - * Keys will be variable names and values with be their values. |
|
| 635 | - */ |
|
| 636 | - public function help_tabs_config() |
|
| 637 | - { |
|
| 638 | - return array(); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
| 644 | - * the payment method's table's PMT_type column) |
|
| 645 | - * @return string |
|
| 646 | - */ |
|
| 647 | - public function system_name() |
|
| 648 | - { |
|
| 649 | - $classname = get_class($this); |
|
| 650 | - return str_replace("EE_PMT_", '', $classname); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * A pretty i18n version of the PMT name |
|
| 656 | - * @return string |
|
| 657 | - */ |
|
| 658 | - public function pretty_name() |
|
| 659 | - { |
|
| 660 | - return $this->_pretty_name; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Gets the default absolute URL to the payment method type's button |
|
| 666 | - * @return string |
|
| 667 | - */ |
|
| 668 | - public function default_button_url() |
|
| 669 | - { |
|
| 670 | - return $this->_default_button_url; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Gets the gateway used by this payment method (if any) |
|
| 676 | - * @return EE_Gateway |
|
| 677 | - */ |
|
| 678 | - public function get_gateway() |
|
| 679 | - { |
|
| 680 | - return $this->_gateway; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * @return string html for the link to a help tab |
|
| 686 | - */ |
|
| 687 | - public function get_help_tab_link() |
|
| 688 | - { |
|
| 689 | - return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Returns the name of the help tab for this PMT |
|
| 695 | - * @return string |
|
| 696 | - */ |
|
| 697 | - public function get_help_tab_name() |
|
| 698 | - { |
|
| 699 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * The name of the wp capability that should be associated with the usage of |
|
| 704 | - * this PMT by an admin |
|
| 705 | - * @return string |
|
| 706 | - */ |
|
| 707 | - public function cap_name() |
|
| 708 | - { |
|
| 709 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Called by client code to tell the gateway that if it wants to change |
|
| 714 | - * the transaction or line items or registrations related to teh payment it already |
|
| 715 | - * processed (we think, but possibly not) that now's the time to do it. |
|
| 716 | - * It is expected that gateways will store any info they need for this on the PAY_details, |
|
| 717 | - * or maybe an extra meta value |
|
| 718 | - * @param EE_Payment $payment |
|
| 719 | - * @return void |
|
| 720 | - */ |
|
| 721 | - public function update_txn_based_on_payment($payment) |
|
| 722 | - { |
|
| 723 | - if ($this->_gateway instanceof EE_Gateway) { |
|
| 724 | - $this->_gateway->update_txn_based_on_payment($payment); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Returns a string of HTML describing this payment method type for an admin, |
|
| 730 | - * primarily intended for them to read before activating it. |
|
| 731 | - * The easiest way to set this is to create a folder 'templates' alongside |
|
| 732 | - * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
| 733 | - * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
| 734 | - * then you'd create a file named "templates" in the same folder as it, and name the file |
|
| 735 | - * "foo_bar_intro.template.php", and its content will be returned by this method |
|
| 736 | - * @return string |
|
| 737 | - */ |
|
| 738 | - public function introductory_html() |
|
| 739 | - { |
|
| 740 | - return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
| 741 | - } |
|
| 24 | + const onsite = 'on-site'; |
|
| 25 | + const offsite = 'off-site'; |
|
| 26 | + const offline = 'off-line'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var EE_Payment_Method |
|
| 30 | + */ |
|
| 31 | + protected $_pm_instance = NULL; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean |
|
| 35 | + */ |
|
| 36 | + protected $_requires_https = FALSE; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var boolean |
|
| 40 | + */ |
|
| 41 | + protected $_has_billing_form; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Gateway |
|
| 45 | + */ |
|
| 46 | + protected $_gateway = NULL; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var EE_Payment_Method_Form |
|
| 50 | + */ |
|
| 51 | + protected $_settings_form = NULL; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var EE_Form_Section_Proper |
|
| 55 | + */ |
|
| 56 | + protected $_billing_form = NULL; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var boolean |
|
| 60 | + */ |
|
| 61 | + protected $_cache_billing_form = TRUE; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * String of the absolute path to the folder containing this file, with a trailing slash. |
|
| 65 | + * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + protected $_file_folder = NULL; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
| 72 | + * like images, js, or css) |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_file_url = NULL; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Pretty name for the payment method |
|
| 79 | + * @var string |
|
| 80 | + */ |
|
| 81 | + protected $_pretty_name = NULL; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * |
|
| 85 | + * @var string |
|
| 86 | + */ |
|
| 87 | + protected $_default_button_url = NULL; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + protected $_default_description = NULL; |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * |
|
| 98 | + * @param EE_Payment_Method $pm_instance |
|
| 99 | + * @throws EE_Error |
|
| 100 | + * @return EE_PMT_Base |
|
| 101 | + */ |
|
| 102 | + function __construct($pm_instance = NULL) |
|
| 103 | + { |
|
| 104 | + if ($pm_instance instanceof EE_Payment_Method) { |
|
| 105 | + $this->set_instance($pm_instance); |
|
| 106 | + } |
|
| 107 | + if ($this->_gateway) { |
|
| 108 | + $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
| 109 | + $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
| 110 | + $this->_gateway->set_template_helper(new EEH_Template()); |
|
| 111 | + $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
| 112 | + $this->_gateway->set_money_helper(new EEH_Money()); |
|
| 113 | + $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
| 114 | + $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
| 115 | + do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
| 116 | + } |
|
| 117 | + if (!isset($this->_has_billing_form)) { |
|
| 118 | + // by default, On Site gateways have a billing form |
|
| 119 | + if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
| 120 | + $this->set_has_billing_form(true); |
|
| 121 | + } else { |
|
| 122 | + $this->set_has_billing_form(false); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$this->_pretty_name) { |
|
| 127 | + throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
|
| 128 | + } |
|
| 129 | + //if the child didn't specify a default button, use the credit card one |
|
| 130 | + if ($this->_default_button_url === NULL) { |
|
| 131 | + $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param boolean $has_billing_form |
|
| 138 | + */ |
|
| 139 | + public function set_has_billing_form($has_billing_form) |
|
| 140 | + { |
|
| 141 | + $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * sets the file_folder property |
|
| 147 | + */ |
|
| 148 | + protected function _set_file_folder() |
|
| 149 | + { |
|
| 150 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 151 | + $fn = $reflector->getFileName(); |
|
| 152 | + $this->_file_folder = dirname($fn) . DS; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * sets the file URL with a trailing slash for this PMT |
|
| 158 | + */ |
|
| 159 | + protected function _set_file_url() |
|
| 160 | + { |
|
| 161 | + $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
| 162 | + $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
| 163 | + $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
| 164 | + $this->_file_url = $file_path; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Gets the default description on all payment methods of this type |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + public function default_description() |
|
| 172 | + { |
|
| 173 | + return $this->_default_description; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Returns the folder containing the PMT child class, with a trailing slash |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function file_folder() |
|
| 182 | + { |
|
| 183 | + if (!$this->_file_folder) { |
|
| 184 | + $this->_set_file_folder(); |
|
| 185 | + } |
|
| 186 | + return $this->_file_folder; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public function file_url() |
|
| 194 | + { |
|
| 195 | + if (!$this->_file_url) { |
|
| 196 | + $this->_set_file_url(); |
|
| 197 | + } |
|
| 198 | + return $this->_file_url; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Sets the payment method instance this payment method type is for. |
|
| 204 | + * Its important teh payment method instance is set before |
|
| 205 | + * @param EE_Payment_Method $payment_method_instance |
|
| 206 | + */ |
|
| 207 | + function set_instance($payment_method_instance) |
|
| 208 | + { |
|
| 209 | + $this->_pm_instance = $payment_method_instance; |
|
| 210 | + //if they have already requested the settings form, make sure its |
|
| 211 | + //data matches this model object |
|
| 212 | + if ($this->_settings_form) { |
|
| 213 | + $this->settings_form()->populate_model_obj($payment_method_instance); |
|
| 214 | + } |
|
| 215 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 216 | + $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Gets teh form for displaying to admins where they setup the payment method |
|
| 223 | + * @return EE_Payment_Method_Form |
|
| 224 | + */ |
|
| 225 | + function settings_form() |
|
| 226 | + { |
|
| 227 | + if (!$this->_settings_form) { |
|
| 228 | + $this->_settings_form = $this->generate_new_settings_form(); |
|
| 229 | + $this->_settings_form->set_payment_method_type($this); |
|
| 230 | + //if we have already assigned a model object to this pmt, make |
|
| 231 | + //sure its reflected in teh form we just generated |
|
| 232 | + if ($this->_pm_instance) { |
|
| 233 | + $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + return $this->_settings_form; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Gets the form for all the settings related to this payment method type |
|
| 242 | + * @return EE_Payment_Method_Form |
|
| 243 | + */ |
|
| 244 | + abstract function generate_new_settings_form(); |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Sets the form for settings. This may be useful if we have already received |
|
| 249 | + * a form submission and have form data it in, and want to use it anytime we're showing |
|
| 250 | + * this payment method type's settings form later in the request |
|
| 251 | + * @param EE_Payment_Method_Form $form |
|
| 252 | + */ |
|
| 253 | + public function set_settings_form($form) |
|
| 254 | + { |
|
| 255 | + $this->_settings_form = $form; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return boolean |
|
| 261 | + */ |
|
| 262 | + public function has_billing_form() |
|
| 263 | + { |
|
| 264 | + return $this->_has_billing_form; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Gets the form for displaying to attendees where they can enter their billing info |
|
| 270 | + * which will be sent to teh gateway (can be null) |
|
| 271 | + * |
|
| 272 | + * @param \EE_Transaction $transaction |
|
| 273 | + * @param array $extra_args |
|
| 274 | + * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
| 275 | + */ |
|
| 276 | + public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
|
| 277 | + { |
|
| 278 | + // has billing form already been regenerated ? or overwrite cache? |
|
| 279 | + if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
| 280 | + $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
| 281 | + } |
|
| 282 | + //if we know who the attendee is, and this is a billing form |
|
| 283 | + //that uses attendee info, populate it |
|
| 284 | + if ( |
|
| 285 | + apply_filters( |
|
| 286 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 287 | + ( |
|
| 288 | + $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 289 | + && $transaction instanceof EE_Transaction |
|
| 290 | + && $transaction->primary_registration() instanceof EE_Registration |
|
| 291 | + && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
| 292 | + ), |
|
| 293 | + $this->_billing_form, |
|
| 294 | + $transaction |
|
| 295 | + ) |
|
| 296 | + ) { |
|
| 297 | + $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
| 298 | + } |
|
| 299 | + return $this->_billing_form; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Creates the billing form for this payment method type |
|
| 305 | + * @param \EE_Transaction $transaction |
|
| 306 | + * @return \EE_Billing_Info_Form |
|
| 307 | + */ |
|
| 308 | + abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * apply_billing_form_debug_settings |
|
| 313 | + * applies debug data to the form |
|
| 314 | + * |
|
| 315 | + * @param \EE_Billing_Info_Form $billing_form |
|
| 316 | + * @return \EE_Billing_Info_Form |
|
| 317 | + */ |
|
| 318 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
| 319 | + { |
|
| 320 | + return $billing_form; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Sets the billing form for this payment method type. You may want to use this |
|
| 326 | + * if you have form |
|
| 327 | + * @param EE_Payment_Method $form |
|
| 328 | + */ |
|
| 329 | + public function set_billing_form($form) |
|
| 330 | + { |
|
| 331 | + $this->_billing_form = $form; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Returns whether or not this payment method requires HTTPS to be used |
|
| 337 | + * @return boolean |
|
| 338 | + */ |
|
| 339 | + function requires_https() |
|
| 340 | + { |
|
| 341 | + return $this->_requires_https; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * |
|
| 347 | + * @param EE_Transaction $transaction |
|
| 348 | + * @param float $amount |
|
| 349 | + * @param EE_Billing_Info_Form $billing_info |
|
| 350 | + * @param string $return_url |
|
| 351 | + * @param string $fail_url |
|
| 352 | + * @param string $method |
|
| 353 | + * @param bool $by_admin |
|
| 354 | + * @return EE_Payment |
|
| 355 | + * @throws EE_Error |
|
| 356 | + */ |
|
| 357 | + function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) |
|
| 358 | + { |
|
| 359 | + // @todo: add surcharge for the payment method, if any |
|
| 360 | + if ($this->_gateway) { |
|
| 361 | + //there is a gateway, so we're going to make a payment object |
|
| 362 | + //but wait! do they already have a payment in progress that we thought was failed? |
|
| 363 | + $duplicate_properties = array( |
|
| 364 | + 'STS_ID' => EEM_Payment::status_id_failed, |
|
| 365 | + 'TXN_ID' => $transaction->ID(), |
|
| 366 | + 'PMD_ID' => $this->_pm_instance->ID(), |
|
| 367 | + 'PAY_source' => $method, |
|
| 368 | + 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
| 369 | + 'PAY_gateway_response' => null, |
|
| 370 | + ); |
|
| 371 | + $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
| 372 | + //if we didn't already have a payment in progress for the same thing, |
|
| 373 | + //then we actually want to make a new payment |
|
| 374 | + if (!$payment instanceof EE_Payment) { |
|
| 375 | + $payment = EE_Payment::new_instance( |
|
| 376 | + array_merge( |
|
| 377 | + $duplicate_properties, |
|
| 378 | + array( |
|
| 379 | + 'PAY_timestamp' => time(), |
|
| 380 | + 'PAY_txn_id_chq_nmbr' => null, |
|
| 381 | + 'PAY_po_number' => null, |
|
| 382 | + 'PAY_extra_accntng' => null, |
|
| 383 | + 'PAY_details' => null, |
|
| 384 | + ) |
|
| 385 | + ) |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | + //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
| 389 | + $payment->save(); |
|
| 390 | + $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
| 391 | + |
|
| 392 | + // Offsite Gateway |
|
| 393 | + if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 394 | + |
|
| 395 | + $payment = $this->_gateway->set_redirection_info( |
|
| 396 | + $payment, |
|
| 397 | + $billing_values, |
|
| 398 | + $return_url, |
|
| 399 | + EE_Config::instance()->core->txn_page_url( |
|
| 400 | + array( |
|
| 401 | + 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
| 402 | + 'ee_payment_method' => $this->_pm_instance->slug() |
|
| 403 | + ) |
|
| 404 | + ), |
|
| 405 | + $fail_url |
|
| 406 | + ); |
|
| 407 | + $payment->save(); |
|
| 408 | + // Onsite Gateway |
|
| 409 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 410 | + |
|
| 411 | + $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
| 412 | + $payment->save(); |
|
| 413 | + |
|
| 414 | + } else { |
|
| 415 | + throw new EE_Error( |
|
| 416 | + sprintf( |
|
| 417 | + __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
| 418 | + get_class($this), |
|
| 419 | + gettype($this->_gateway) |
|
| 420 | + ) |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + } else { |
|
| 425 | + // no gateway provided |
|
| 426 | + // there is no payment. Must be an offline gateway |
|
| 427 | + // create a payment object anyways, but dont save it |
|
| 428 | + $payment = EE_Payment::new_instance( |
|
| 429 | + array( |
|
| 430 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 431 | + 'TXN_ID' => $transaction->ID(), |
|
| 432 | + 'PMD_ID' => $transaction->payment_method_ID(), |
|
| 433 | + 'PAY_amount' => 0.00, |
|
| 434 | + 'PAY_timestamp' => time(), |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // if there is billing info, clean it and save it now |
|
| 441 | + if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
| 442 | + $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + return $payment; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Gets the values we want to pass onto the gateway. Normally these |
|
| 450 | + * are just the 'pretty' values, but there may be times the data may need |
|
| 451 | + * a little massaging. Proper subsections will become arrays of inputs |
|
| 452 | + * @param EE_Billing_Info_Form $billing_form |
|
| 453 | + * @return array |
|
| 454 | + */ |
|
| 455 | + protected function _get_billing_values_from_form($billing_form) |
|
| 456 | + { |
|
| 457 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 458 | + return $billing_form->input_pretty_values(true); |
|
| 459 | + } else { |
|
| 460 | + return NULL; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Handles an instant payment notification when the transaction is known (by default). |
|
| 467 | + * @param array $req_data |
|
| 468 | + * @param EE_Transaction $transaction |
|
| 469 | + * @return EE_Payment |
|
| 470 | + * @throws EE_Error |
|
| 471 | + */ |
|
| 472 | + public function handle_ipn($req_data, $transaction) |
|
| 473 | + { |
|
| 474 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 475 | + if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 476 | + throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
| 477 | + |
|
| 478 | + } |
|
| 479 | + $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
| 480 | + return $payment; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
| 486 | + * cleans it first. |
|
| 487 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 488 | + * @param EE_Transaction $transaction |
|
| 489 | + * @return boolean success |
|
| 490 | + */ |
|
| 491 | + protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
| 492 | + { |
|
| 493 | + if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
| 494 | + EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + $primary_reg = $transaction->primary_registration(); |
|
| 498 | + if (!$primary_reg) { |
|
| 499 | + EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 500 | + return false; |
|
| 501 | + } |
|
| 502 | + $attendee = $primary_reg->attendee(); |
|
| 503 | + if (!$attendee) { |
|
| 504 | + EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 505 | + return false; |
|
| 506 | + } |
|
| 507 | + return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
| 508 | + |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Gets the payment this IPN is for. Children may often want to |
|
| 514 | + * override this to inspect the request |
|
| 515 | + * @param EE_Transaction $transaction |
|
| 516 | + * @param array $req_data |
|
| 517 | + * @return EE_Payment |
|
| 518 | + */ |
|
| 519 | + protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
| 520 | + { |
|
| 521 | + return $transaction->last_payment(); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * In case generic code cannot provide the payment processor with a specific payment method |
|
| 527 | + * and transaction, it will try calling this method on each activate payment method. |
|
| 528 | + * If the payment method is able to identify the request as being for it, it should fetch |
|
| 529 | + * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
| 530 | + * handle the IPN |
|
| 531 | + * @param array $req_data |
|
| 532 | + * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
| 533 | + * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
| 534 | + * @throws EE_Error |
|
| 535 | + */ |
|
| 536 | + public function handle_unclaimed_ipn($req_data = array()) |
|
| 537 | + { |
|
| 538 | + throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Logic to be accomplished when the payment attempt is complete. |
|
| 544 | + * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
| 545 | + * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
| 546 | + * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
| 547 | + * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
| 548 | + * we're dealing with. Returns that last payment (if there is one) |
|
| 549 | + * |
|
| 550 | + * @param EE_Transaction $transaction |
|
| 551 | + * @return EE_Payment |
|
| 552 | + */ |
|
| 553 | + public function finalize_payment_for($transaction) |
|
| 554 | + { |
|
| 555 | + return $transaction->last_payment(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Whether or not this payment method's gateway supports sending refund requests |
|
| 561 | + * @return boolean |
|
| 562 | + */ |
|
| 563 | + public function supports_sending_refunds() |
|
| 564 | + { |
|
| 565 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 566 | + return $this->_gateway->supports_sending_refunds(); |
|
| 567 | + } else { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * |
|
| 575 | + * @param EE_Payment $payment |
|
| 576 | + * @param array $refund_info |
|
| 577 | + * @throws EE_Error |
|
| 578 | + * @return EE_Payment |
|
| 579 | + */ |
|
| 580 | + public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
| 581 | + { |
|
| 582 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 583 | + return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
| 584 | + } else { |
|
| 585 | + throw new EE_Error( |
|
| 586 | + sprintf( |
|
| 587 | + __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
| 588 | + get_class($this) |
|
| 589 | + ) |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
| 597 | + * payment method's gateway. |
|
| 598 | + * @return string |
|
| 599 | + * @throws EE_Error |
|
| 600 | + */ |
|
| 601 | + public function payment_occurs() |
|
| 602 | + { |
|
| 603 | + if (!$this->_gateway) { |
|
| 604 | + return EE_PMT_Base::offline; |
|
| 605 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 606 | + return EE_PMT_Base::onsite; |
|
| 607 | + } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 608 | + return EE_PMT_Base::offsite; |
|
| 609 | + } else { |
|
| 610 | + throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * For adding any html output ab ove the payment overview. |
|
| 617 | + * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
| 618 | + * Other gateways may want to override this, such as offline gateways. |
|
| 619 | + * @param EE_Payment $payment |
|
| 620 | + * @return string |
|
| 621 | + */ |
|
| 622 | + public function payment_overview_content(EE_Payment $payment) |
|
| 623 | + { |
|
| 624 | + return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * @return array where keys are the help tab name, |
|
| 630 | + * values are: array { |
|
| 631 | + * @type string $title i18n name for the help tab |
|
| 632 | + * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
| 633 | + * @type array $template_args any arguments you want passed to the template file while rendering. |
|
| 634 | + * Keys will be variable names and values with be their values. |
|
| 635 | + */ |
|
| 636 | + public function help_tabs_config() |
|
| 637 | + { |
|
| 638 | + return array(); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
| 644 | + * the payment method's table's PMT_type column) |
|
| 645 | + * @return string |
|
| 646 | + */ |
|
| 647 | + public function system_name() |
|
| 648 | + { |
|
| 649 | + $classname = get_class($this); |
|
| 650 | + return str_replace("EE_PMT_", '', $classname); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * A pretty i18n version of the PMT name |
|
| 656 | + * @return string |
|
| 657 | + */ |
|
| 658 | + public function pretty_name() |
|
| 659 | + { |
|
| 660 | + return $this->_pretty_name; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Gets the default absolute URL to the payment method type's button |
|
| 666 | + * @return string |
|
| 667 | + */ |
|
| 668 | + public function default_button_url() |
|
| 669 | + { |
|
| 670 | + return $this->_default_button_url; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Gets the gateway used by this payment method (if any) |
|
| 676 | + * @return EE_Gateway |
|
| 677 | + */ |
|
| 678 | + public function get_gateway() |
|
| 679 | + { |
|
| 680 | + return $this->_gateway; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * @return string html for the link to a help tab |
|
| 686 | + */ |
|
| 687 | + public function get_help_tab_link() |
|
| 688 | + { |
|
| 689 | + return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Returns the name of the help tab for this PMT |
|
| 695 | + * @return string |
|
| 696 | + */ |
|
| 697 | + public function get_help_tab_name() |
|
| 698 | + { |
|
| 699 | + return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * The name of the wp capability that should be associated with the usage of |
|
| 704 | + * this PMT by an admin |
|
| 705 | + * @return string |
|
| 706 | + */ |
|
| 707 | + public function cap_name() |
|
| 708 | + { |
|
| 709 | + return 'ee_payment_method_' . strtolower($this->system_name()); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Called by client code to tell the gateway that if it wants to change |
|
| 714 | + * the transaction or line items or registrations related to teh payment it already |
|
| 715 | + * processed (we think, but possibly not) that now's the time to do it. |
|
| 716 | + * It is expected that gateways will store any info they need for this on the PAY_details, |
|
| 717 | + * or maybe an extra meta value |
|
| 718 | + * @param EE_Payment $payment |
|
| 719 | + * @return void |
|
| 720 | + */ |
|
| 721 | + public function update_txn_based_on_payment($payment) |
|
| 722 | + { |
|
| 723 | + if ($this->_gateway instanceof EE_Gateway) { |
|
| 724 | + $this->_gateway->update_txn_based_on_payment($payment); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Returns a string of HTML describing this payment method type for an admin, |
|
| 730 | + * primarily intended for them to read before activating it. |
|
| 731 | + * The easiest way to set this is to create a folder 'templates' alongside |
|
| 732 | + * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
| 733 | + * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
| 734 | + * then you'd create a file named "templates" in the same folder as it, and name the file |
|
| 735 | + * "foo_bar_intro.template.php", and its content will be returned by this method |
|
| 736 | + * @return string |
|
| 737 | + */ |
|
| 738 | + public function introductory_html() |
|
| 739 | + { |
|
| 740 | + return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | 743 | |
| 744 | 744 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
| 115 | 115 | do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
| 116 | 116 | } |
| 117 | - if (!isset($this->_has_billing_form)) { |
|
| 117 | + if ( ! isset($this->_has_billing_form)) { |
|
| 118 | 118 | // by default, On Site gateways have a billing form |
| 119 | 119 | if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
| 120 | 120 | $this->set_has_billing_form(true); |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if (!$this->_pretty_name) { |
|
| 126 | + if ( ! $this->_pretty_name) { |
|
| 127 | 127 | throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
| 128 | 128 | } |
| 129 | 129 | //if the child didn't specify a default button, use the credit card one |
| 130 | 130 | if ($this->_default_button_url === NULL) { |
| 131 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
| 131 | + $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png'; |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | $reflector = new ReflectionClass(get_class($this)); |
| 151 | 151 | $fn = $reflector->getFileName(); |
| 152 | - $this->_file_folder = dirname($fn) . DS; |
|
| 152 | + $this->_file_folder = dirname($fn).DS; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function file_folder() |
| 182 | 182 | { |
| 183 | - if (!$this->_file_folder) { |
|
| 183 | + if ( ! $this->_file_folder) { |
|
| 184 | 184 | $this->_set_file_folder(); |
| 185 | 185 | } |
| 186 | 186 | return $this->_file_folder; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function file_url() |
| 194 | 194 | { |
| 195 | - if (!$this->_file_url) { |
|
| 195 | + if ( ! $this->_file_url) { |
|
| 196 | 196 | $this->_set_file_url(); |
| 197 | 197 | } |
| 198 | 198 | return $this->_file_url; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function settings_form() |
| 226 | 226 | { |
| 227 | - if (!$this->_settings_form) { |
|
| 227 | + if ( ! $this->_settings_form) { |
|
| 228 | 228 | $this->_settings_form = $this->generate_new_settings_form(); |
| 229 | 229 | $this->_settings_form->set_payment_method_type($this); |
| 230 | 230 | //if we have already assigned a model object to this pmt, make |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
| 277 | 277 | { |
| 278 | 278 | // has billing form already been regenerated ? or overwrite cache? |
| 279 | - if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
| 279 | + if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
| 280 | 280 | $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
| 281 | 281 | } |
| 282 | 282 | //if we know who the attendee is, and this is a billing form |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
| 372 | 372 | //if we didn't already have a payment in progress for the same thing, |
| 373 | 373 | //then we actually want to make a new payment |
| 374 | - if (!$payment instanceof EE_Payment) { |
|
| 374 | + if ( ! $payment instanceof EE_Payment) { |
|
| 375 | 375 | $payment = EE_Payment::new_instance( |
| 376 | 376 | array_merge( |
| 377 | 377 | $duplicate_properties, |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | public function handle_ipn($req_data, $transaction) |
| 473 | 473 | { |
| 474 | 474 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
| 475 | - if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 475 | + if ( ! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 476 | 476 | throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
| 477 | 477 | |
| 478 | 478 | } |
@@ -490,17 +490,17 @@ discard block |
||
| 490 | 490 | */ |
| 491 | 491 | protected function _save_billing_info_to_attendee($billing_form, $transaction) |
| 492 | 492 | { |
| 493 | - if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
| 493 | + if ( ! $transaction || ! $transaction instanceof EE_Transaction) { |
|
| 494 | 494 | EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | 497 | $primary_reg = $transaction->primary_registration(); |
| 498 | - if (!$primary_reg) { |
|
| 498 | + if ( ! $primary_reg) { |
|
| 499 | 499 | EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 500 | 500 | return false; |
| 501 | 501 | } |
| 502 | 502 | $attendee = $primary_reg->attendee(); |
| 503 | - if (!$attendee) { |
|
| 503 | + if ( ! $attendee) { |
|
| 504 | 504 | EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 505 | 505 | return false; |
| 506 | 506 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | public function payment_occurs() |
| 602 | 602 | { |
| 603 | - if (!$this->_gateway) { |
|
| 603 | + if ( ! $this->_gateway) { |
|
| 604 | 604 | return EE_PMT_Base::offline; |
| 605 | 605 | } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
| 606 | 606 | return EE_PMT_Base::onsite; |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | */ |
| 622 | 622 | public function payment_overview_content(EE_Payment $payment) |
| 623 | 623 | { |
| 624 | - return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
| 624 | + return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | */ |
| 697 | 697 | public function get_help_tab_name() |
| 698 | 698 | { |
| 699 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
| 699 | + return 'ee_'.strtolower($this->system_name()).'_help_tab'; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | */ |
| 707 | 707 | public function cap_name() |
| 708 | 708 | { |
| 709 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
| 709 | + return 'ee_payment_method_'.strtolower($this->system_name()); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | */ |
| 738 | 738 | public function introductory_html() |
| 739 | 739 | { |
| 740 | - return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
| 740 | + return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('NO direct script access allowed'); |
|
| 8 | + exit('NO direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -23,2554 +23,2554 @@ discard block |
||
| 23 | 23 | class Messages_Admin_Page extends EE_Admin_Page |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | - */ |
|
| 29 | - protected $_message_resource_manager; |
|
| 26 | + /** |
|
| 27 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | + */ |
|
| 29 | + protected $_message_resource_manager; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @type string $_active_message_type_name |
|
| 33 | - */ |
|
| 34 | - protected $_active_message_type_name = ''; |
|
| 31 | + /** |
|
| 32 | + * @type string $_active_message_type_name |
|
| 33 | + */ |
|
| 34 | + protected $_active_message_type_name = ''; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @type EE_messenger $_active_messenger |
|
| 38 | - */ |
|
| 39 | - protected $_active_messenger; |
|
| 40 | - protected $_activate_state; |
|
| 41 | - protected $_activate_meta_box_type; |
|
| 42 | - protected $_current_message_meta_box; |
|
| 43 | - protected $_current_message_meta_box_object; |
|
| 44 | - protected $_context_switcher; |
|
| 45 | - protected $_shortcodes = array(); |
|
| 46 | - protected $_active_messengers = array(); |
|
| 47 | - protected $_active_message_types = array(); |
|
| 36 | + /** |
|
| 37 | + * @type EE_messenger $_active_messenger |
|
| 38 | + */ |
|
| 39 | + protected $_active_messenger; |
|
| 40 | + protected $_activate_state; |
|
| 41 | + protected $_activate_meta_box_type; |
|
| 42 | + protected $_current_message_meta_box; |
|
| 43 | + protected $_current_message_meta_box_object; |
|
| 44 | + protected $_context_switcher; |
|
| 45 | + protected $_shortcodes = array(); |
|
| 46 | + protected $_active_messengers = array(); |
|
| 47 | + protected $_active_message_types = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | - */ |
|
| 52 | - protected $_message_template_group; |
|
| 53 | - protected $_m_mt_settings = array(); |
|
| 49 | + /** |
|
| 50 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | + */ |
|
| 52 | + protected $_message_template_group; |
|
| 53 | + protected $_m_mt_settings = array(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | - * |
|
| 60 | - * @since 4.5.0 |
|
| 61 | - * |
|
| 62 | - * @var EE_Messages_Template_Pack |
|
| 63 | - */ |
|
| 64 | - protected $_template_pack; |
|
| 56 | + /** |
|
| 57 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | + * |
|
| 60 | + * @since 4.5.0 |
|
| 61 | + * |
|
| 62 | + * @var EE_Messages_Template_Pack |
|
| 63 | + */ |
|
| 64 | + protected $_template_pack; |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | - * group is. If there is no group then it automatically gets set to default. |
|
| 70 | - * |
|
| 71 | - * @since 4.5.0 |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_variation; |
|
| 67 | + /** |
|
| 68 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | + * group is. If there is no group then it automatically gets set to default. |
|
| 70 | + * |
|
| 71 | + * @since 4.5.0 |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_variation; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param bool $routing |
|
| 80 | - * @throws EE_Error |
|
| 81 | - */ |
|
| 82 | - public function __construct($routing = true) |
|
| 83 | - { |
|
| 84 | - //make sure messages autoloader is running |
|
| 85 | - EED_Messages::set_autoloaders(); |
|
| 86 | - parent::__construct($routing); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * @param bool $routing |
|
| 80 | + * @throws EE_Error |
|
| 81 | + */ |
|
| 82 | + public function __construct($routing = true) |
|
| 83 | + { |
|
| 84 | + //make sure messages autoloader is running |
|
| 85 | + EED_Messages::set_autoloaders(); |
|
| 86 | + parent::__construct($routing); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - protected function _init_page_props() |
|
| 91 | - { |
|
| 92 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | - |
|
| 97 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | - |
|
| 99 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | - $this->_load_message_resource_manager(); |
|
| 101 | - } |
|
| 90 | + protected function _init_page_props() |
|
| 91 | + { |
|
| 92 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 93 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 94 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 95 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 96 | + |
|
| 97 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 98 | + |
|
| 99 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 100 | + $this->_load_message_resource_manager(); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | - * |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - * @throws InvalidArgumentException |
|
| 111 | - * @throws ReflectionException |
|
| 112 | - */ |
|
| 113 | - protected function _load_message_resource_manager() |
|
| 114 | - { |
|
| 115 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | - } |
|
| 104 | + /** |
|
| 105 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 106 | + * |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + * @throws InvalidArgumentException |
|
| 111 | + * @throws ReflectionException |
|
| 112 | + */ |
|
| 113 | + protected function _load_message_resource_manager() |
|
| 114 | + { |
|
| 115 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @deprecated 4.9.9.rc.014 |
|
| 121 | - * @return array |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidInterfaceException |
|
| 126 | - */ |
|
| 127 | - public function get_messengers_for_list_table() |
|
| 128 | - { |
|
| 129 | - EE_Error::doing_it_wrong( |
|
| 130 | - __METHOD__, |
|
| 131 | - sprintf( |
|
| 132 | - esc_html__( |
|
| 133 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | - ), |
|
| 138 | - '4.9.9.rc.014' |
|
| 139 | - ); |
|
| 140 | - |
|
| 141 | - $m_values = array(); |
|
| 142 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | - //setup messengers for selects |
|
| 144 | - $i = 1; |
|
| 145 | - foreach ($active_messengers as $active_messenger) { |
|
| 146 | - if ($active_messenger instanceof EE_Message) { |
|
| 147 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | - $i++; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $m_values; |
|
| 154 | - } |
|
| 119 | + /** |
|
| 120 | + * @deprecated 4.9.9.rc.014 |
|
| 121 | + * @return array |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidInterfaceException |
|
| 126 | + */ |
|
| 127 | + public function get_messengers_for_list_table() |
|
| 128 | + { |
|
| 129 | + EE_Error::doing_it_wrong( |
|
| 130 | + __METHOD__, |
|
| 131 | + sprintf( |
|
| 132 | + esc_html__( |
|
| 133 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 137 | + ), |
|
| 138 | + '4.9.9.rc.014' |
|
| 139 | + ); |
|
| 140 | + |
|
| 141 | + $m_values = array(); |
|
| 142 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 143 | + //setup messengers for selects |
|
| 144 | + $i = 1; |
|
| 145 | + foreach ($active_messengers as $active_messenger) { |
|
| 146 | + if ($active_messenger instanceof EE_Message) { |
|
| 147 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 148 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 149 | + $i++; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $m_values; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @deprecated 4.9.9.rc.014 |
|
| 159 | - * @return array |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - */ |
|
| 165 | - public function get_message_types_for_list_table() |
|
| 166 | - { |
|
| 167 | - EE_Error::doing_it_wrong( |
|
| 168 | - __METHOD__, |
|
| 169 | - sprintf( |
|
| 170 | - esc_html__( |
|
| 171 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ), |
|
| 174 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | - ), |
|
| 176 | - '4.9.9.rc.014' |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - $mt_values = array(); |
|
| 180 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | - $i = 1; |
|
| 182 | - foreach ($active_messages as $active_message) { |
|
| 183 | - if ($active_message instanceof EE_Message) { |
|
| 184 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | - $i++; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $mt_values; |
|
| 191 | - } |
|
| 157 | + /** |
|
| 158 | + * @deprecated 4.9.9.rc.014 |
|
| 159 | + * @return array |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + */ |
|
| 165 | + public function get_message_types_for_list_table() |
|
| 166 | + { |
|
| 167 | + EE_Error::doing_it_wrong( |
|
| 168 | + __METHOD__, |
|
| 169 | + sprintf( |
|
| 170 | + esc_html__( |
|
| 171 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ), |
|
| 174 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 175 | + ), |
|
| 176 | + '4.9.9.rc.014' |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + $mt_values = array(); |
|
| 180 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 181 | + $i = 1; |
|
| 182 | + foreach ($active_messages as $active_message) { |
|
| 183 | + if ($active_message instanceof EE_Message) { |
|
| 184 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 185 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 186 | + $i++; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $mt_values; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * @deprecated 4.9.9.rc.014 |
|
| 196 | - * @return array |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - */ |
|
| 202 | - public function get_contexts_for_message_types_for_list_table() |
|
| 203 | - { |
|
| 204 | - EE_Error::doing_it_wrong( |
|
| 205 | - __METHOD__, |
|
| 206 | - sprintf( |
|
| 207 | - esc_html__( |
|
| 208 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | - ), |
|
| 213 | - '4.9.9.rc.014' |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $contexts = array(); |
|
| 217 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | - foreach ($active_message_contexts as $active_message) { |
|
| 219 | - if ($active_message instanceof EE_Message) { |
|
| 220 | - $message_type = $active_message->message_type_object(); |
|
| 221 | - if ($message_type instanceof EE_message_type) { |
|
| 222 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | - $contexts[$context] = $context_details['label']; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $contexts; |
|
| 231 | - } |
|
| 194 | + /** |
|
| 195 | + * @deprecated 4.9.9.rc.014 |
|
| 196 | + * @return array |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + */ |
|
| 202 | + public function get_contexts_for_message_types_for_list_table() |
|
| 203 | + { |
|
| 204 | + EE_Error::doing_it_wrong( |
|
| 205 | + __METHOD__, |
|
| 206 | + sprintf( |
|
| 207 | + esc_html__( |
|
| 208 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 212 | + ), |
|
| 213 | + '4.9.9.rc.014' |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $contexts = array(); |
|
| 217 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 218 | + foreach ($active_message_contexts as $active_message) { |
|
| 219 | + if ($active_message instanceof EE_Message) { |
|
| 220 | + $message_type = $active_message->message_type_object(); |
|
| 221 | + if ($message_type instanceof EE_message_type) { |
|
| 222 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 223 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 224 | + $contexts[$context] = $context_details['label']; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $contexts; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Generate select input with provided messenger options array. |
|
| 236 | - * |
|
| 237 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | - * labels. |
|
| 239 | - * @return string |
|
| 240 | - * @throws EE_Error |
|
| 241 | - */ |
|
| 242 | - public function get_messengers_select_input($messenger_options) |
|
| 243 | - { |
|
| 244 | - //if empty or just one value then just return an empty string |
|
| 245 | - if (empty($messenger_options) |
|
| 246 | - || ! is_array($messenger_options) |
|
| 247 | - || count($messenger_options) === 1 |
|
| 248 | - ) { |
|
| 249 | - return ''; |
|
| 250 | - } |
|
| 251 | - //merge in default |
|
| 252 | - $messenger_options = array_merge( |
|
| 253 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | - $messenger_options |
|
| 255 | - ); |
|
| 256 | - $input = new EE_Select_Input( |
|
| 257 | - $messenger_options, |
|
| 258 | - array( |
|
| 259 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | - 'html_class' => 'wide', |
|
| 262 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | - : 'none_selected' |
|
| 265 | - ) |
|
| 266 | - ); |
|
| 267 | - |
|
| 268 | - return $input->get_html_for_input(); |
|
| 269 | - } |
|
| 234 | + /** |
|
| 235 | + * Generate select input with provided messenger options array. |
|
| 236 | + * |
|
| 237 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 238 | + * labels. |
|
| 239 | + * @return string |
|
| 240 | + * @throws EE_Error |
|
| 241 | + */ |
|
| 242 | + public function get_messengers_select_input($messenger_options) |
|
| 243 | + { |
|
| 244 | + //if empty or just one value then just return an empty string |
|
| 245 | + if (empty($messenger_options) |
|
| 246 | + || ! is_array($messenger_options) |
|
| 247 | + || count($messenger_options) === 1 |
|
| 248 | + ) { |
|
| 249 | + return ''; |
|
| 250 | + } |
|
| 251 | + //merge in default |
|
| 252 | + $messenger_options = array_merge( |
|
| 253 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 254 | + $messenger_options |
|
| 255 | + ); |
|
| 256 | + $input = new EE_Select_Input( |
|
| 257 | + $messenger_options, |
|
| 258 | + array( |
|
| 259 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 260 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 261 | + 'html_class' => 'wide', |
|
| 262 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 264 | + : 'none_selected' |
|
| 265 | + ) |
|
| 266 | + ); |
|
| 267 | + |
|
| 268 | + return $input->get_html_for_input(); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Generate select input with provided message type options array. |
|
| 274 | - * |
|
| 275 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | - * message type labels |
|
| 277 | - * @return string |
|
| 278 | - * @throws EE_Error |
|
| 279 | - */ |
|
| 280 | - public function get_message_types_select_input($message_type_options) |
|
| 281 | - { |
|
| 282 | - //if empty or count of options is 1 then just return an empty string |
|
| 283 | - if (empty($message_type_options) |
|
| 284 | - || ! is_array($message_type_options) |
|
| 285 | - || count($message_type_options) === 1 |
|
| 286 | - ) { |
|
| 287 | - return ''; |
|
| 288 | - } |
|
| 289 | - //merge in default |
|
| 290 | - $message_type_options = array_merge( |
|
| 291 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | - $message_type_options |
|
| 293 | - ); |
|
| 294 | - $input = new EE_Select_Input( |
|
| 295 | - $message_type_options, |
|
| 296 | - array( |
|
| 297 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | - 'html_class' => 'wide', |
|
| 300 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | - : 'none_selected', |
|
| 303 | - ) |
|
| 304 | - ); |
|
| 305 | - |
|
| 306 | - return $input->get_html_for_input(); |
|
| 307 | - } |
|
| 272 | + /** |
|
| 273 | + * Generate select input with provided message type options array. |
|
| 274 | + * |
|
| 275 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 276 | + * message type labels |
|
| 277 | + * @return string |
|
| 278 | + * @throws EE_Error |
|
| 279 | + */ |
|
| 280 | + public function get_message_types_select_input($message_type_options) |
|
| 281 | + { |
|
| 282 | + //if empty or count of options is 1 then just return an empty string |
|
| 283 | + if (empty($message_type_options) |
|
| 284 | + || ! is_array($message_type_options) |
|
| 285 | + || count($message_type_options) === 1 |
|
| 286 | + ) { |
|
| 287 | + return ''; |
|
| 288 | + } |
|
| 289 | + //merge in default |
|
| 290 | + $message_type_options = array_merge( |
|
| 291 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 292 | + $message_type_options |
|
| 293 | + ); |
|
| 294 | + $input = new EE_Select_Input( |
|
| 295 | + $message_type_options, |
|
| 296 | + array( |
|
| 297 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 299 | + 'html_class' => 'wide', |
|
| 300 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 302 | + : 'none_selected', |
|
| 303 | + ) |
|
| 304 | + ); |
|
| 305 | + |
|
| 306 | + return $input->get_html_for_input(); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Generate select input with provide message type contexts array. |
|
| 312 | - * |
|
| 313 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | - * context label. |
|
| 315 | - * @return string |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | - { |
|
| 320 | - //if empty or count of options is one then just return empty string |
|
| 321 | - if (empty($context_options) |
|
| 322 | - || ! is_array($context_options) |
|
| 323 | - || count($context_options) === 1 |
|
| 324 | - ) { |
|
| 325 | - return ''; |
|
| 326 | - } |
|
| 327 | - //merge in default |
|
| 328 | - $context_options = array_merge( |
|
| 329 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | - $context_options |
|
| 331 | - ); |
|
| 332 | - $input = new EE_Select_Input( |
|
| 333 | - $context_options, |
|
| 334 | - array( |
|
| 335 | - 'html_name' => 'ee_context_filter_by', |
|
| 336 | - 'html_id' => 'ee_context_filter_by', |
|
| 337 | - 'html_class' => 'wide', |
|
| 338 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | - : 'none_selected', |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - |
|
| 344 | - return $input->get_html_for_input(); |
|
| 345 | - } |
|
| 310 | + /** |
|
| 311 | + * Generate select input with provide message type contexts array. |
|
| 312 | + * |
|
| 313 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 314 | + * context label. |
|
| 315 | + * @return string |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 319 | + { |
|
| 320 | + //if empty or count of options is one then just return empty string |
|
| 321 | + if (empty($context_options) |
|
| 322 | + || ! is_array($context_options) |
|
| 323 | + || count($context_options) === 1 |
|
| 324 | + ) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 327 | + //merge in default |
|
| 328 | + $context_options = array_merge( |
|
| 329 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | + $context_options |
|
| 331 | + ); |
|
| 332 | + $input = new EE_Select_Input( |
|
| 333 | + $context_options, |
|
| 334 | + array( |
|
| 335 | + 'html_name' => 'ee_context_filter_by', |
|
| 336 | + 'html_id' => 'ee_context_filter_by', |
|
| 337 | + 'html_class' => 'wide', |
|
| 338 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | + : 'none_selected', |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + |
|
| 344 | + return $input->get_html_for_input(); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | 347 | |
| 348 | - protected function _ajax_hooks() |
|
| 349 | - { |
|
| 350 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | - } |
|
| 348 | + protected function _ajax_hooks() |
|
| 349 | + { |
|
| 350 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | |
| 359 | - protected function _define_page_props() |
|
| 360 | - { |
|
| 361 | - $this->_admin_page_title = $this->page_label; |
|
| 362 | - $this->_labels = array( |
|
| 363 | - 'buttons' => array( |
|
| 364 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | - ), |
|
| 368 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | - ); |
|
| 370 | - } |
|
| 359 | + protected function _define_page_props() |
|
| 360 | + { |
|
| 361 | + $this->_admin_page_title = $this->page_label; |
|
| 362 | + $this->_labels = array( |
|
| 363 | + 'buttons' => array( |
|
| 364 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 367 | + ), |
|
| 368 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | - * @access protected |
|
| 376 | - * @return void |
|
| 377 | - */ |
|
| 378 | - protected function _set_page_routes() |
|
| 379 | - { |
|
| 380 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | - ? $this->_req_data['GRP_ID'] |
|
| 382 | - : 0; |
|
| 383 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | - ? $this->_req_data['id'] |
|
| 385 | - : $grp_id; |
|
| 386 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | - ? $this->_req_data['MSG_ID'] |
|
| 388 | - : 0; |
|
| 389 | - |
|
| 390 | - $this->_page_routes = array( |
|
| 391 | - 'default' => array( |
|
| 392 | - 'func' => '_message_queue_list_table', |
|
| 393 | - 'capability' => 'ee_read_global_messages' |
|
| 394 | - ), |
|
| 395 | - 'global_mtps' => array( |
|
| 396 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | - 'capability' => 'ee_read_global_messages' |
|
| 398 | - ), |
|
| 399 | - 'custom_mtps' => array( |
|
| 400 | - 'func' => '_custom_mtps_preview', |
|
| 401 | - 'capability' => 'ee_read_messages' |
|
| 402 | - ), |
|
| 403 | - 'add_new_message_template' => array( |
|
| 404 | - 'func' => '_add_message_template', |
|
| 405 | - 'capability' => 'ee_edit_messages', |
|
| 406 | - 'noheader' => true |
|
| 407 | - ), |
|
| 408 | - 'edit_message_template' => array( |
|
| 409 | - 'func' => '_edit_message_template', |
|
| 410 | - 'capability' => 'ee_edit_message', |
|
| 411 | - 'obj_id' => $grp_id |
|
| 412 | - ), |
|
| 413 | - 'preview_message' => array( |
|
| 414 | - 'func' => '_preview_message', |
|
| 415 | - 'capability' => 'ee_read_message', |
|
| 416 | - 'obj_id' => $grp_id, |
|
| 417 | - 'noheader' => true, |
|
| 418 | - 'headers_sent_route' => 'display_preview_message' |
|
| 419 | - ), |
|
| 420 | - 'display_preview_message' => array( |
|
| 421 | - 'func' => '_display_preview_message', |
|
| 422 | - 'capability' => 'ee_read_message', |
|
| 423 | - 'obj_id' => $grp_id |
|
| 424 | - ), |
|
| 425 | - 'insert_message_template' => array( |
|
| 426 | - 'func' => '_insert_or_update_message_template', |
|
| 427 | - 'capability' => 'ee_edit_messages', |
|
| 428 | - 'args' => array('new_template' => true), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'update_message_template' => array( |
|
| 432 | - 'func' => '_insert_or_update_message_template', |
|
| 433 | - 'capability' => 'ee_edit_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'args' => array('new_template' => false), |
|
| 436 | - 'noheader' => true |
|
| 437 | - ), |
|
| 438 | - 'trash_message_template' => array( |
|
| 439 | - 'func' => '_trash_or_restore_message_template', |
|
| 440 | - 'capability' => 'ee_delete_message', |
|
| 441 | - 'obj_id' => $grp_id, |
|
| 442 | - 'args' => array('trash' => true, 'all' => true), |
|
| 443 | - 'noheader' => true |
|
| 444 | - ), |
|
| 445 | - 'trash_message_template_context' => array( |
|
| 446 | - 'func' => '_trash_or_restore_message_template', |
|
| 447 | - 'capability' => 'ee_delete_message', |
|
| 448 | - 'obj_id' => $grp_id, |
|
| 449 | - 'args' => array('trash' => true), |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'restore_message_template' => array( |
|
| 453 | - 'func' => '_trash_or_restore_message_template', |
|
| 454 | - 'capability' => 'ee_delete_message', |
|
| 455 | - 'obj_id' => $grp_id, |
|
| 456 | - 'args' => array('trash' => false, 'all' => true), |
|
| 457 | - 'noheader' => true |
|
| 458 | - ), |
|
| 459 | - 'restore_message_template_context' => array( |
|
| 460 | - 'func' => '_trash_or_restore_message_template', |
|
| 461 | - 'capability' => 'ee_delete_message', |
|
| 462 | - 'obj_id' => $grp_id, |
|
| 463 | - 'args' => array('trash' => false), |
|
| 464 | - 'noheader' => true |
|
| 465 | - ), |
|
| 466 | - 'delete_message_template' => array( |
|
| 467 | - 'func' => '_delete_message_template', |
|
| 468 | - 'capability' => 'ee_delete_message', |
|
| 469 | - 'obj_id' => $grp_id, |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'reset_to_default' => array( |
|
| 473 | - 'func' => '_reset_to_default_template', |
|
| 474 | - 'capability' => 'ee_edit_message', |
|
| 475 | - 'obj_id' => $grp_id, |
|
| 476 | - 'noheader' => true |
|
| 477 | - ), |
|
| 478 | - 'settings' => array( |
|
| 479 | - 'func' => '_settings', |
|
| 480 | - 'capability' => 'manage_options' |
|
| 481 | - ), |
|
| 482 | - 'update_global_settings' => array( |
|
| 483 | - 'func' => '_update_global_settings', |
|
| 484 | - 'capability' => 'manage_options', |
|
| 485 | - 'noheader' => true |
|
| 486 | - ), |
|
| 487 | - 'generate_now' => array( |
|
| 488 | - 'func' => '_generate_now', |
|
| 489 | - 'capability' => 'ee_send_message', |
|
| 490 | - 'noheader' => true |
|
| 491 | - ), |
|
| 492 | - 'generate_and_send_now' => array( |
|
| 493 | - 'func' => '_generate_and_send_now', |
|
| 494 | - 'capability' => 'ee_send_message', |
|
| 495 | - 'noheader' => true |
|
| 496 | - ), |
|
| 497 | - 'queue_for_resending' => array( |
|
| 498 | - 'func' => '_queue_for_resending', |
|
| 499 | - 'capability' => 'ee_send_message', |
|
| 500 | - 'noheader' => true |
|
| 501 | - ), |
|
| 502 | - 'send_now' => array( |
|
| 503 | - 'func' => '_send_now', |
|
| 504 | - 'capability' => 'ee_send_message', |
|
| 505 | - 'noheader' => true |
|
| 506 | - ), |
|
| 507 | - 'delete_ee_message' => array( |
|
| 508 | - 'func' => '_delete_ee_messages', |
|
| 509 | - 'capability' => 'ee_delete_messages', |
|
| 510 | - 'noheader' => true |
|
| 511 | - ), |
|
| 512 | - 'delete_ee_messages' => array( |
|
| 513 | - 'func' => '_delete_ee_messages', |
|
| 514 | - 'capability' => 'ee_delete_messages', |
|
| 515 | - 'noheader' => true, |
|
| 516 | - 'obj_id' => $msg_id |
|
| 517 | - ) |
|
| 518 | - ); |
|
| 519 | - } |
|
| 373 | + /** |
|
| 374 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | + * @access protected |
|
| 376 | + * @return void |
|
| 377 | + */ |
|
| 378 | + protected function _set_page_routes() |
|
| 379 | + { |
|
| 380 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 381 | + ? $this->_req_data['GRP_ID'] |
|
| 382 | + : 0; |
|
| 383 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 384 | + ? $this->_req_data['id'] |
|
| 385 | + : $grp_id; |
|
| 386 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 387 | + ? $this->_req_data['MSG_ID'] |
|
| 388 | + : 0; |
|
| 389 | + |
|
| 390 | + $this->_page_routes = array( |
|
| 391 | + 'default' => array( |
|
| 392 | + 'func' => '_message_queue_list_table', |
|
| 393 | + 'capability' => 'ee_read_global_messages' |
|
| 394 | + ), |
|
| 395 | + 'global_mtps' => array( |
|
| 396 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 397 | + 'capability' => 'ee_read_global_messages' |
|
| 398 | + ), |
|
| 399 | + 'custom_mtps' => array( |
|
| 400 | + 'func' => '_custom_mtps_preview', |
|
| 401 | + 'capability' => 'ee_read_messages' |
|
| 402 | + ), |
|
| 403 | + 'add_new_message_template' => array( |
|
| 404 | + 'func' => '_add_message_template', |
|
| 405 | + 'capability' => 'ee_edit_messages', |
|
| 406 | + 'noheader' => true |
|
| 407 | + ), |
|
| 408 | + 'edit_message_template' => array( |
|
| 409 | + 'func' => '_edit_message_template', |
|
| 410 | + 'capability' => 'ee_edit_message', |
|
| 411 | + 'obj_id' => $grp_id |
|
| 412 | + ), |
|
| 413 | + 'preview_message' => array( |
|
| 414 | + 'func' => '_preview_message', |
|
| 415 | + 'capability' => 'ee_read_message', |
|
| 416 | + 'obj_id' => $grp_id, |
|
| 417 | + 'noheader' => true, |
|
| 418 | + 'headers_sent_route' => 'display_preview_message' |
|
| 419 | + ), |
|
| 420 | + 'display_preview_message' => array( |
|
| 421 | + 'func' => '_display_preview_message', |
|
| 422 | + 'capability' => 'ee_read_message', |
|
| 423 | + 'obj_id' => $grp_id |
|
| 424 | + ), |
|
| 425 | + 'insert_message_template' => array( |
|
| 426 | + 'func' => '_insert_or_update_message_template', |
|
| 427 | + 'capability' => 'ee_edit_messages', |
|
| 428 | + 'args' => array('new_template' => true), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'update_message_template' => array( |
|
| 432 | + 'func' => '_insert_or_update_message_template', |
|
| 433 | + 'capability' => 'ee_edit_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'args' => array('new_template' => false), |
|
| 436 | + 'noheader' => true |
|
| 437 | + ), |
|
| 438 | + 'trash_message_template' => array( |
|
| 439 | + 'func' => '_trash_or_restore_message_template', |
|
| 440 | + 'capability' => 'ee_delete_message', |
|
| 441 | + 'obj_id' => $grp_id, |
|
| 442 | + 'args' => array('trash' => true, 'all' => true), |
|
| 443 | + 'noheader' => true |
|
| 444 | + ), |
|
| 445 | + 'trash_message_template_context' => array( |
|
| 446 | + 'func' => '_trash_or_restore_message_template', |
|
| 447 | + 'capability' => 'ee_delete_message', |
|
| 448 | + 'obj_id' => $grp_id, |
|
| 449 | + 'args' => array('trash' => true), |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'restore_message_template' => array( |
|
| 453 | + 'func' => '_trash_or_restore_message_template', |
|
| 454 | + 'capability' => 'ee_delete_message', |
|
| 455 | + 'obj_id' => $grp_id, |
|
| 456 | + 'args' => array('trash' => false, 'all' => true), |
|
| 457 | + 'noheader' => true |
|
| 458 | + ), |
|
| 459 | + 'restore_message_template_context' => array( |
|
| 460 | + 'func' => '_trash_or_restore_message_template', |
|
| 461 | + 'capability' => 'ee_delete_message', |
|
| 462 | + 'obj_id' => $grp_id, |
|
| 463 | + 'args' => array('trash' => false), |
|
| 464 | + 'noheader' => true |
|
| 465 | + ), |
|
| 466 | + 'delete_message_template' => array( |
|
| 467 | + 'func' => '_delete_message_template', |
|
| 468 | + 'capability' => 'ee_delete_message', |
|
| 469 | + 'obj_id' => $grp_id, |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'reset_to_default' => array( |
|
| 473 | + 'func' => '_reset_to_default_template', |
|
| 474 | + 'capability' => 'ee_edit_message', |
|
| 475 | + 'obj_id' => $grp_id, |
|
| 476 | + 'noheader' => true |
|
| 477 | + ), |
|
| 478 | + 'settings' => array( |
|
| 479 | + 'func' => '_settings', |
|
| 480 | + 'capability' => 'manage_options' |
|
| 481 | + ), |
|
| 482 | + 'update_global_settings' => array( |
|
| 483 | + 'func' => '_update_global_settings', |
|
| 484 | + 'capability' => 'manage_options', |
|
| 485 | + 'noheader' => true |
|
| 486 | + ), |
|
| 487 | + 'generate_now' => array( |
|
| 488 | + 'func' => '_generate_now', |
|
| 489 | + 'capability' => 'ee_send_message', |
|
| 490 | + 'noheader' => true |
|
| 491 | + ), |
|
| 492 | + 'generate_and_send_now' => array( |
|
| 493 | + 'func' => '_generate_and_send_now', |
|
| 494 | + 'capability' => 'ee_send_message', |
|
| 495 | + 'noheader' => true |
|
| 496 | + ), |
|
| 497 | + 'queue_for_resending' => array( |
|
| 498 | + 'func' => '_queue_for_resending', |
|
| 499 | + 'capability' => 'ee_send_message', |
|
| 500 | + 'noheader' => true |
|
| 501 | + ), |
|
| 502 | + 'send_now' => array( |
|
| 503 | + 'func' => '_send_now', |
|
| 504 | + 'capability' => 'ee_send_message', |
|
| 505 | + 'noheader' => true |
|
| 506 | + ), |
|
| 507 | + 'delete_ee_message' => array( |
|
| 508 | + 'func' => '_delete_ee_messages', |
|
| 509 | + 'capability' => 'ee_delete_messages', |
|
| 510 | + 'noheader' => true |
|
| 511 | + ), |
|
| 512 | + 'delete_ee_messages' => array( |
|
| 513 | + 'func' => '_delete_ee_messages', |
|
| 514 | + 'capability' => 'ee_delete_messages', |
|
| 515 | + 'noheader' => true, |
|
| 516 | + 'obj_id' => $msg_id |
|
| 517 | + ) |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | 520 | |
| 521 | 521 | |
| 522 | - protected function _set_page_config() |
|
| 523 | - { |
|
| 524 | - $this->_page_config = array( |
|
| 525 | - 'default' => array( |
|
| 526 | - 'nav' => array( |
|
| 527 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | - 'order' => 10 |
|
| 529 | - ), |
|
| 530 | - 'list_table' => 'EE_Message_List_Table', |
|
| 531 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | - 'require_nonce' => false |
|
| 533 | - ), |
|
| 534 | - 'global_mtps' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | - 'order' => 20 |
|
| 538 | - ), |
|
| 539 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | - 'help_tabs' => array( |
|
| 541 | - 'messages_overview_help_tab' => array( |
|
| 542 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | - 'filename' => 'messages_overview' |
|
| 544 | - ), |
|
| 545 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | - ), |
|
| 549 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | - 'filename' => 'messages_overview_filters' |
|
| 552 | - ), |
|
| 553 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | - 'filename' => 'messages_overview_views' |
|
| 556 | - ), |
|
| 557 | - 'message_overview_message_types_help_tab' => array( |
|
| 558 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | - 'filename' => 'messages_overview_types' |
|
| 560 | - ), |
|
| 561 | - 'messages_overview_messengers_help_tab' => array( |
|
| 562 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | - 'filename' => 'messages_overview_messengers', |
|
| 564 | - ), |
|
| 565 | - ), |
|
| 566 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | - 'require_nonce' => false |
|
| 568 | - ), |
|
| 569 | - 'custom_mtps' => array( |
|
| 570 | - 'nav' => array( |
|
| 571 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | - 'order' => 30 |
|
| 573 | - ), |
|
| 574 | - 'help_tabs' => array(), |
|
| 575 | - 'help_tour' => array(), |
|
| 576 | - 'require_nonce' => false |
|
| 577 | - ), |
|
| 578 | - 'add_new_message_template' => array( |
|
| 579 | - 'nav' => array( |
|
| 580 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | - 'order' => 5, |
|
| 582 | - 'persistent' => false |
|
| 583 | - ), |
|
| 584 | - 'require_nonce' => false |
|
| 585 | - ), |
|
| 586 | - 'edit_message_template' => array( |
|
| 587 | - 'labels' => array( |
|
| 588 | - 'buttons' => array( |
|
| 589 | - 'reset' => esc_html__('Reset Templates'), |
|
| 590 | - ), |
|
| 591 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | - ), |
|
| 593 | - 'nav' => array( |
|
| 594 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | - 'order' => 5, |
|
| 596 | - 'persistent' => false, |
|
| 597 | - 'url' => '' |
|
| 598 | - ), |
|
| 599 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | - 'has_metaboxes' => true, |
|
| 601 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | - 'help_tabs' => array( |
|
| 603 | - 'edit_message_template' => array( |
|
| 604 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | - 'callback' => 'edit_message_template_help_tab' |
|
| 606 | - ), |
|
| 607 | - 'message_templates_help_tab' => array( |
|
| 608 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | - 'filename' => 'messages_templates' |
|
| 610 | - ), |
|
| 611 | - 'message_template_shortcodes' => array( |
|
| 612 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | - ), |
|
| 615 | - 'message_preview_help_tab' => array( |
|
| 616 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | - 'filename' => 'messages_preview' |
|
| 618 | - ), |
|
| 619 | - 'messages_overview_other_help_tab' => array( |
|
| 620 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | - 'filename' => 'messages_overview_other', |
|
| 622 | - ), |
|
| 623 | - ), |
|
| 624 | - 'require_nonce' => false |
|
| 625 | - ), |
|
| 626 | - 'display_preview_message' => array( |
|
| 627 | - 'nav' => array( |
|
| 628 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | - 'order' => 5, |
|
| 630 | - 'url' => '', |
|
| 631 | - 'persistent' => false |
|
| 632 | - ), |
|
| 633 | - 'help_tabs' => array( |
|
| 634 | - 'preview_message' => array( |
|
| 635 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | - 'callback' => 'preview_message_help_tab' |
|
| 637 | - ) |
|
| 638 | - ), |
|
| 639 | - 'require_nonce' => false |
|
| 640 | - ), |
|
| 641 | - 'settings' => array( |
|
| 642 | - 'nav' => array( |
|
| 643 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | - 'order' => 40 |
|
| 645 | - ), |
|
| 646 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | - 'help_tabs' => array( |
|
| 648 | - 'messages_settings_help_tab' => array( |
|
| 649 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | - 'filename' => 'messages_settings' |
|
| 651 | - ), |
|
| 652 | - 'messages_settings_message_types_help_tab' => array( |
|
| 653 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | - 'filename' => 'messages_settings_message_types' |
|
| 655 | - ), |
|
| 656 | - 'messages_settings_messengers_help_tab' => array( |
|
| 657 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | - 'filename' => 'messages_settings_messengers' |
|
| 659 | - ), |
|
| 660 | - ), |
|
| 661 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | - 'require_nonce' => false |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - } |
|
| 522 | + protected function _set_page_config() |
|
| 523 | + { |
|
| 524 | + $this->_page_config = array( |
|
| 525 | + 'default' => array( |
|
| 526 | + 'nav' => array( |
|
| 527 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 528 | + 'order' => 10 |
|
| 529 | + ), |
|
| 530 | + 'list_table' => 'EE_Message_List_Table', |
|
| 531 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 532 | + 'require_nonce' => false |
|
| 533 | + ), |
|
| 534 | + 'global_mtps' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 537 | + 'order' => 20 |
|
| 538 | + ), |
|
| 539 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 540 | + 'help_tabs' => array( |
|
| 541 | + 'messages_overview_help_tab' => array( |
|
| 542 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 543 | + 'filename' => 'messages_overview' |
|
| 544 | + ), |
|
| 545 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 546 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 547 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 548 | + ), |
|
| 549 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 550 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 551 | + 'filename' => 'messages_overview_filters' |
|
| 552 | + ), |
|
| 553 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 554 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 555 | + 'filename' => 'messages_overview_views' |
|
| 556 | + ), |
|
| 557 | + 'message_overview_message_types_help_tab' => array( |
|
| 558 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 559 | + 'filename' => 'messages_overview_types' |
|
| 560 | + ), |
|
| 561 | + 'messages_overview_messengers_help_tab' => array( |
|
| 562 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 563 | + 'filename' => 'messages_overview_messengers', |
|
| 564 | + ), |
|
| 565 | + ), |
|
| 566 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 567 | + 'require_nonce' => false |
|
| 568 | + ), |
|
| 569 | + 'custom_mtps' => array( |
|
| 570 | + 'nav' => array( |
|
| 571 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 572 | + 'order' => 30 |
|
| 573 | + ), |
|
| 574 | + 'help_tabs' => array(), |
|
| 575 | + 'help_tour' => array(), |
|
| 576 | + 'require_nonce' => false |
|
| 577 | + ), |
|
| 578 | + 'add_new_message_template' => array( |
|
| 579 | + 'nav' => array( |
|
| 580 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 581 | + 'order' => 5, |
|
| 582 | + 'persistent' => false |
|
| 583 | + ), |
|
| 584 | + 'require_nonce' => false |
|
| 585 | + ), |
|
| 586 | + 'edit_message_template' => array( |
|
| 587 | + 'labels' => array( |
|
| 588 | + 'buttons' => array( |
|
| 589 | + 'reset' => esc_html__('Reset Templates'), |
|
| 590 | + ), |
|
| 591 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 592 | + ), |
|
| 593 | + 'nav' => array( |
|
| 594 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 595 | + 'order' => 5, |
|
| 596 | + 'persistent' => false, |
|
| 597 | + 'url' => '' |
|
| 598 | + ), |
|
| 599 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 600 | + 'has_metaboxes' => true, |
|
| 601 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 602 | + 'help_tabs' => array( |
|
| 603 | + 'edit_message_template' => array( |
|
| 604 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 605 | + 'callback' => 'edit_message_template_help_tab' |
|
| 606 | + ), |
|
| 607 | + 'message_templates_help_tab' => array( |
|
| 608 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 609 | + 'filename' => 'messages_templates' |
|
| 610 | + ), |
|
| 611 | + 'message_template_shortcodes' => array( |
|
| 612 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 613 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 614 | + ), |
|
| 615 | + 'message_preview_help_tab' => array( |
|
| 616 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 617 | + 'filename' => 'messages_preview' |
|
| 618 | + ), |
|
| 619 | + 'messages_overview_other_help_tab' => array( |
|
| 620 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 621 | + 'filename' => 'messages_overview_other', |
|
| 622 | + ), |
|
| 623 | + ), |
|
| 624 | + 'require_nonce' => false |
|
| 625 | + ), |
|
| 626 | + 'display_preview_message' => array( |
|
| 627 | + 'nav' => array( |
|
| 628 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 629 | + 'order' => 5, |
|
| 630 | + 'url' => '', |
|
| 631 | + 'persistent' => false |
|
| 632 | + ), |
|
| 633 | + 'help_tabs' => array( |
|
| 634 | + 'preview_message' => array( |
|
| 635 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 636 | + 'callback' => 'preview_message_help_tab' |
|
| 637 | + ) |
|
| 638 | + ), |
|
| 639 | + 'require_nonce' => false |
|
| 640 | + ), |
|
| 641 | + 'settings' => array( |
|
| 642 | + 'nav' => array( |
|
| 643 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 644 | + 'order' => 40 |
|
| 645 | + ), |
|
| 646 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 647 | + 'help_tabs' => array( |
|
| 648 | + 'messages_settings_help_tab' => array( |
|
| 649 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 650 | + 'filename' => 'messages_settings' |
|
| 651 | + ), |
|
| 652 | + 'messages_settings_message_types_help_tab' => array( |
|
| 653 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 654 | + 'filename' => 'messages_settings_message_types' |
|
| 655 | + ), |
|
| 656 | + 'messages_settings_messengers_help_tab' => array( |
|
| 657 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 658 | + 'filename' => 'messages_settings_messengers' |
|
| 659 | + ), |
|
| 660 | + ), |
|
| 661 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 662 | + 'require_nonce' => false |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | 667 | |
| 668 | - protected function _add_screen_options() |
|
| 669 | - { |
|
| 670 | - //todo |
|
| 671 | - } |
|
| 668 | + protected function _add_screen_options() |
|
| 669 | + { |
|
| 670 | + //todo |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | |
| 674 | - protected function _add_screen_options_global_mtps() |
|
| 675 | - { |
|
| 676 | - /** |
|
| 677 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | - */ |
|
| 680 | - $page_title = $this->_admin_page_title; |
|
| 681 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | - $this->_per_page_screen_option(); |
|
| 683 | - $this->_admin_page_title = $page_title; |
|
| 684 | - } |
|
| 674 | + protected function _add_screen_options_global_mtps() |
|
| 675 | + { |
|
| 676 | + /** |
|
| 677 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 678 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 679 | + */ |
|
| 680 | + $page_title = $this->_admin_page_title; |
|
| 681 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 682 | + $this->_per_page_screen_option(); |
|
| 683 | + $this->_admin_page_title = $page_title; |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | 686 | |
| 687 | - protected function _add_screen_options_default() |
|
| 688 | - { |
|
| 689 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | - $this->_per_page_screen_option(); |
|
| 691 | - } |
|
| 687 | + protected function _add_screen_options_default() |
|
| 688 | + { |
|
| 689 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 690 | + $this->_per_page_screen_option(); |
|
| 691 | + } |
|
| 692 | 692 | |
| 693 | 693 | |
| 694 | - //none of the below group are currently used for Messages |
|
| 695 | - protected function _add_feature_pointers() |
|
| 696 | - { |
|
| 697 | - } |
|
| 694 | + //none of the below group are currently used for Messages |
|
| 695 | + protected function _add_feature_pointers() |
|
| 696 | + { |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - public function admin_init() |
|
| 700 | - { |
|
| 701 | - } |
|
| 699 | + public function admin_init() |
|
| 700 | + { |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - public function admin_notices() |
|
| 704 | - { |
|
| 705 | - } |
|
| 703 | + public function admin_notices() |
|
| 704 | + { |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - public function admin_footer_scripts() |
|
| 708 | - { |
|
| 709 | - } |
|
| 707 | + public function admin_footer_scripts() |
|
| 708 | + { |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | 711 | |
| 712 | - public function messages_help_tab() |
|
| 713 | - { |
|
| 714 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | - } |
|
| 712 | + public function messages_help_tab() |
|
| 713 | + { |
|
| 714 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - public function messengers_help_tab() |
|
| 719 | - { |
|
| 720 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | - } |
|
| 718 | + public function messengers_help_tab() |
|
| 719 | + { |
|
| 720 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | 723 | |
| 724 | - public function message_types_help_tab() |
|
| 725 | - { |
|
| 726 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | - } |
|
| 724 | + public function message_types_help_tab() |
|
| 725 | + { |
|
| 726 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | 729 | |
| 730 | - public function messages_overview_help_tab() |
|
| 731 | - { |
|
| 732 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | - } |
|
| 730 | + public function messages_overview_help_tab() |
|
| 731 | + { |
|
| 732 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | |
| 736 | - public function message_templates_help_tab() |
|
| 737 | - { |
|
| 738 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | - } |
|
| 736 | + public function message_templates_help_tab() |
|
| 737 | + { |
|
| 738 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | - public function edit_message_template_help_tab() |
|
| 743 | - { |
|
| 744 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | - . '" />'; |
|
| 747 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | - . '" />'; |
|
| 750 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | - . '" />'; |
|
| 753 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | - . '" />'; |
|
| 756 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | - . '" />'; |
|
| 759 | - EEH_Template::display_template( |
|
| 760 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | - $args |
|
| 762 | - ); |
|
| 763 | - } |
|
| 742 | + public function edit_message_template_help_tab() |
|
| 743 | + { |
|
| 744 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 746 | + . '" />'; |
|
| 747 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 749 | + . '" />'; |
|
| 750 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 752 | + . '" />'; |
|
| 753 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 755 | + . '" />'; |
|
| 756 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 758 | + . '" />'; |
|
| 759 | + EEH_Template::display_template( |
|
| 760 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | + $args |
|
| 762 | + ); |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | |
| 766 | - public function message_template_shortcodes_help_tab() |
|
| 767 | - { |
|
| 768 | - $this->_set_shortcodes(); |
|
| 769 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | - EEH_Template::display_template( |
|
| 771 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | - $args |
|
| 773 | - ); |
|
| 774 | - } |
|
| 766 | + public function message_template_shortcodes_help_tab() |
|
| 767 | + { |
|
| 768 | + $this->_set_shortcodes(); |
|
| 769 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 770 | + EEH_Template::display_template( |
|
| 771 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | + $args |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | 776 | |
| 777 | - public function preview_message_help_tab() |
|
| 778 | - { |
|
| 779 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | - } |
|
| 777 | + public function preview_message_help_tab() |
|
| 778 | + { |
|
| 779 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | + } |
|
| 781 | 781 | |
| 782 | 782 | |
| 783 | - public function settings_help_tab() |
|
| 784 | - { |
|
| 785 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | - $args['img3'] = '<div class="switch">' |
|
| 790 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | - . ' type="checkbox" checked="checked">' |
|
| 792 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | - . '</div>'; |
|
| 794 | - $args['img4'] = '<div class="switch">' |
|
| 795 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | - . ' type="checkbox">' |
|
| 797 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | - . '</div>'; |
|
| 799 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | - } |
|
| 783 | + public function settings_help_tab() |
|
| 784 | + { |
|
| 785 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 786 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 787 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 788 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 789 | + $args['img3'] = '<div class="switch">' |
|
| 790 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 791 | + . ' type="checkbox" checked="checked">' |
|
| 792 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 793 | + . '</div>'; |
|
| 794 | + $args['img4'] = '<div class="switch">' |
|
| 795 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 796 | + . ' type="checkbox">' |
|
| 797 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 798 | + . '</div>'; |
|
| 799 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | 802 | |
| 803 | - public function load_scripts_styles() |
|
| 804 | - { |
|
| 805 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | - |
|
| 808 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | - } |
|
| 803 | + public function load_scripts_styles() |
|
| 804 | + { |
|
| 805 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 807 | + |
|
| 808 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 809 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 810 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 811 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | 814 | |
| 815 | - public function load_scripts_styles_default() |
|
| 816 | - { |
|
| 817 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | - } |
|
| 815 | + public function load_scripts_styles_default() |
|
| 816 | + { |
|
| 817 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | |
| 821 | - public function wp_editor_css($mce_css) |
|
| 822 | - { |
|
| 823 | - //if we're on the edit_message_template route |
|
| 824 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | - $message_type_name = $this->_active_message_type_name; |
|
| 821 | + public function wp_editor_css($mce_css) |
|
| 822 | + { |
|
| 823 | + //if we're on the edit_message_template route |
|
| 824 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 825 | + $message_type_name = $this->_active_message_type_name; |
|
| 826 | 826 | |
| 827 | - //we're going to REPLACE the existing mce css |
|
| 828 | - //we need to get the css file location from the active messenger |
|
| 829 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | - 'wpeditor', $this->_variation); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return $mce_css; |
|
| 834 | - } |
|
| 827 | + //we're going to REPLACE the existing mce css |
|
| 828 | + //we need to get the css file location from the active messenger |
|
| 829 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 830 | + 'wpeditor', $this->_variation); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return $mce_css; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | 836 | |
| 837 | - public function load_scripts_styles_edit_message_template() |
|
| 838 | - { |
|
| 839 | - |
|
| 840 | - $this->_set_shortcodes(); |
|
| 841 | - |
|
| 842 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | - esc_html__( |
|
| 844 | - '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.', |
|
| 845 | - 'event_espresso' |
|
| 846 | - ), |
|
| 847 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | - ); |
|
| 850 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | - '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?', |
|
| 852 | - 'event_espresso' |
|
| 853 | - ); |
|
| 854 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | - 'event_espresso' |
|
| 857 | - ); |
|
| 858 | - |
|
| 859 | - wp_register_script( |
|
| 860 | - 'ee_msgs_edit_js', |
|
| 861 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | - array('jquery'), |
|
| 863 | - EVENT_ESPRESSO_VERSION |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - wp_enqueue_script('ee_admin_js'); |
|
| 867 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | - |
|
| 869 | - //add in special css for tiny_mce |
|
| 870 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | - } |
|
| 837 | + public function load_scripts_styles_edit_message_template() |
|
| 838 | + { |
|
| 839 | + |
|
| 840 | + $this->_set_shortcodes(); |
|
| 841 | + |
|
| 842 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 843 | + esc_html__( |
|
| 844 | + '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.', |
|
| 845 | + 'event_espresso' |
|
| 846 | + ), |
|
| 847 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 848 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 849 | + ); |
|
| 850 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 851 | + '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?', |
|
| 852 | + 'event_espresso' |
|
| 853 | + ); |
|
| 854 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 855 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 856 | + 'event_espresso' |
|
| 857 | + ); |
|
| 858 | + |
|
| 859 | + wp_register_script( |
|
| 860 | + 'ee_msgs_edit_js', |
|
| 861 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 862 | + array('jquery'), |
|
| 863 | + EVENT_ESPRESSO_VERSION |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + wp_enqueue_script('ee_admin_js'); |
|
| 867 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 868 | + |
|
| 869 | + //add in special css for tiny_mce |
|
| 870 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 871 | + } |
|
| 872 | 872 | |
| 873 | 873 | |
| 874 | - public function load_scripts_styles_display_preview_message() |
|
| 875 | - { |
|
| 876 | - |
|
| 877 | - $this->_set_message_template_group(); |
|
| 878 | - |
|
| 879 | - if (isset($this->_req_data['messenger'])) { |
|
| 880 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | - $this->_req_data['messenger'] |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - wp_enqueue_style('espresso_preview_css', |
|
| 889 | - $this->_active_messenger->get_variation( |
|
| 890 | - $this->_template_pack, |
|
| 891 | - $message_type_name, |
|
| 892 | - true, |
|
| 893 | - 'preview', |
|
| 894 | - $this->_variation |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - } |
|
| 874 | + public function load_scripts_styles_display_preview_message() |
|
| 875 | + { |
|
| 876 | + |
|
| 877 | + $this->_set_message_template_group(); |
|
| 878 | + |
|
| 879 | + if (isset($this->_req_data['messenger'])) { |
|
| 880 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 881 | + $this->_req_data['messenger'] |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + wp_enqueue_style('espresso_preview_css', |
|
| 889 | + $this->_active_messenger->get_variation( |
|
| 890 | + $this->_template_pack, |
|
| 891 | + $message_type_name, |
|
| 892 | + true, |
|
| 893 | + 'preview', |
|
| 894 | + $this->_variation |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | 898 | |
| 899 | 899 | |
| 900 | - public function load_scripts_styles_settings() |
|
| 901 | - { |
|
| 902 | - wp_register_style( |
|
| 903 | - 'ee-message-settings', |
|
| 904 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | - array(), |
|
| 906 | - EVENT_ESPRESSO_VERSION |
|
| 907 | - ); |
|
| 908 | - wp_enqueue_style('ee-text-links'); |
|
| 909 | - wp_enqueue_style('ee-message-settings'); |
|
| 910 | - wp_enqueue_script('ee-messages-settings'); |
|
| 911 | - } |
|
| 900 | + public function load_scripts_styles_settings() |
|
| 901 | + { |
|
| 902 | + wp_register_style( |
|
| 903 | + 'ee-message-settings', |
|
| 904 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 905 | + array(), |
|
| 906 | + EVENT_ESPRESSO_VERSION |
|
| 907 | + ); |
|
| 908 | + wp_enqueue_style('ee-text-links'); |
|
| 909 | + wp_enqueue_style('ee-message-settings'); |
|
| 910 | + wp_enqueue_script('ee-messages-settings'); |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | 913 | |
| 914 | - /** |
|
| 915 | - * set views array for List Table |
|
| 916 | - */ |
|
| 917 | - public function _set_list_table_views_global_mtps() |
|
| 918 | - { |
|
| 919 | - $this->_views = array( |
|
| 920 | - 'in_use' => array( |
|
| 921 | - 'slug' => 'in_use', |
|
| 922 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | - 'count' => 0, |
|
| 924 | - ) |
|
| 925 | - ); |
|
| 926 | - } |
|
| 914 | + /** |
|
| 915 | + * set views array for List Table |
|
| 916 | + */ |
|
| 917 | + public function _set_list_table_views_global_mtps() |
|
| 918 | + { |
|
| 919 | + $this->_views = array( |
|
| 920 | + 'in_use' => array( |
|
| 921 | + 'slug' => 'in_use', |
|
| 922 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 923 | + 'count' => 0, |
|
| 924 | + ) |
|
| 925 | + ); |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | 928 | |
| 929 | - /** |
|
| 930 | - * Set views array for the Custom Template List Table |
|
| 931 | - */ |
|
| 932 | - public function _set_list_table_views_custom_mtps() |
|
| 933 | - { |
|
| 934 | - $this->_set_list_table_views_global_mtps(); |
|
| 935 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | - ); |
|
| 938 | - } |
|
| 929 | + /** |
|
| 930 | + * Set views array for the Custom Template List Table |
|
| 931 | + */ |
|
| 932 | + public function _set_list_table_views_custom_mtps() |
|
| 933 | + { |
|
| 934 | + $this->_set_list_table_views_global_mtps(); |
|
| 935 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 936 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | 939 | |
| 940 | 940 | |
| 941 | - /** |
|
| 942 | - * set views array for message queue list table |
|
| 943 | - * |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws InvalidInterfaceException |
|
| 946 | - * @throws InvalidArgumentException |
|
| 947 | - * @throws EE_Error |
|
| 948 | - * @throws ReflectionException |
|
| 949 | - */ |
|
| 950 | - public function _set_list_table_views_default() |
|
| 951 | - { |
|
| 952 | - EE_Registry::instance()->load_helper('Template'); |
|
| 953 | - |
|
| 954 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | - 'ee_send_message', |
|
| 956 | - 'message_list_table_bulk_actions' |
|
| 957 | - ) |
|
| 958 | - ? array( |
|
| 959 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | - 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | - ) |
|
| 964 | - : array(); |
|
| 965 | - |
|
| 966 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | - 'ee_delete_messages', |
|
| 968 | - 'message_list_table_bulk_actions' |
|
| 969 | - ) |
|
| 970 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | - : array(); |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - $this->_views = array( |
|
| 975 | - 'all' => array( |
|
| 976 | - 'slug' => 'all', |
|
| 977 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | - 'count' => 0, |
|
| 979 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | - ) |
|
| 981 | - ); |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | - continue; |
|
| 987 | - } |
|
| 988 | - $status_bulk_actions = $common_bulk_actions; |
|
| 989 | - //unset bulk actions not applying to status |
|
| 990 | - if (! empty($status_bulk_actions)) { |
|
| 991 | - switch ($status) { |
|
| 992 | - case EEM_Message::status_idle: |
|
| 993 | - case EEM_Message::status_resend: |
|
| 994 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | - break; |
|
| 941 | + /** |
|
| 942 | + * set views array for message queue list table |
|
| 943 | + * |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws InvalidInterfaceException |
|
| 946 | + * @throws InvalidArgumentException |
|
| 947 | + * @throws EE_Error |
|
| 948 | + * @throws ReflectionException |
|
| 949 | + */ |
|
| 950 | + public function _set_list_table_views_default() |
|
| 951 | + { |
|
| 952 | + EE_Registry::instance()->load_helper('Template'); |
|
| 953 | + |
|
| 954 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 955 | + 'ee_send_message', |
|
| 956 | + 'message_list_table_bulk_actions' |
|
| 957 | + ) |
|
| 958 | + ? array( |
|
| 959 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 960 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 961 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 962 | + 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 963 | + ) |
|
| 964 | + : array(); |
|
| 965 | + |
|
| 966 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 967 | + 'ee_delete_messages', |
|
| 968 | + 'message_list_table_bulk_actions' |
|
| 969 | + ) |
|
| 970 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 971 | + : array(); |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + $this->_views = array( |
|
| 975 | + 'all' => array( |
|
| 976 | + 'slug' => 'all', |
|
| 977 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 978 | + 'count' => 0, |
|
| 979 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 980 | + ) |
|
| 981 | + ); |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 985 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 986 | + continue; |
|
| 987 | + } |
|
| 988 | + $status_bulk_actions = $common_bulk_actions; |
|
| 989 | + //unset bulk actions not applying to status |
|
| 990 | + if (! empty($status_bulk_actions)) { |
|
| 991 | + switch ($status) { |
|
| 992 | + case EEM_Message::status_idle: |
|
| 993 | + case EEM_Message::status_resend: |
|
| 994 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 995 | + break; |
|
| 996 | 996 | |
| 997 | - case EEM_Message::status_failed: |
|
| 998 | - case EEM_Message::status_debug_only: |
|
| 999 | - case EEM_Message::status_messenger_executing: |
|
| 1000 | - $status_bulk_actions = array(); |
|
| 1001 | - break; |
|
| 997 | + case EEM_Message::status_failed: |
|
| 998 | + case EEM_Message::status_debug_only: |
|
| 999 | + case EEM_Message::status_messenger_executing: |
|
| 1000 | + $status_bulk_actions = array(); |
|
| 1001 | + break; |
|
| 1002 | 1002 | |
| 1003 | - case EEM_Message::status_incomplete: |
|
| 1004 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | - break; |
|
| 1003 | + case EEM_Message::status_incomplete: |
|
| 1004 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1005 | + break; |
|
| 1006 | 1006 | |
| 1007 | - case EEM_Message::status_retry: |
|
| 1008 | - case EEM_Message::status_sent: |
|
| 1009 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | - break; |
|
| 1011 | - } |
|
| 1012 | - } |
|
| 1007 | + case EEM_Message::status_retry: |
|
| 1008 | + case EEM_Message::status_sent: |
|
| 1009 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1010 | + break; |
|
| 1011 | + } |
|
| 1012 | + } |
|
| 1013 | 1013 | |
| 1014 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | - continue; |
|
| 1017 | - } |
|
| 1014 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1015 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1016 | + continue; |
|
| 1017 | + } |
|
| 1018 | 1018 | |
| 1019 | - $this->_views[strtolower($status)] = array( |
|
| 1020 | - 'slug' => strtolower($status), |
|
| 1021 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | - 'count' => 0, |
|
| 1023 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | - ); |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1019 | + $this->_views[strtolower($status)] = array( |
|
| 1020 | + 'slug' => strtolower($status), |
|
| 1021 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1022 | + 'count' => 0, |
|
| 1023 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1024 | + ); |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | 1028 | |
| 1029 | - protected function _ee_default_messages_overview_list_table() |
|
| 1030 | - { |
|
| 1031 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | - } |
|
| 1029 | + protected function _ee_default_messages_overview_list_table() |
|
| 1030 | + { |
|
| 1031 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1032 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1033 | + } |
|
| 1034 | 1034 | |
| 1035 | 1035 | |
| 1036 | - protected function _message_queue_list_table() |
|
| 1037 | - { |
|
| 1038 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | - $this->_template_args['per_column'] = 6; |
|
| 1040 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | - . '</h3>'; |
|
| 1044 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | - } |
|
| 1036 | + protected function _message_queue_list_table() |
|
| 1037 | + { |
|
| 1038 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1039 | + $this->_template_args['per_column'] = 6; |
|
| 1040 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1041 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1042 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1043 | + . '</h3>'; |
|
| 1044 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - protected function _message_legend_items() |
|
| 1049 | - { |
|
| 1050 | - |
|
| 1051 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | - $action_items = array(); |
|
| 1053 | - |
|
| 1054 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | - if ($action_item === 'see_notifications_for') { |
|
| 1056 | - continue; |
|
| 1057 | - } |
|
| 1058 | - $action_items[$action_item] = array( |
|
| 1059 | - 'class' => $action_details['css_class'], |
|
| 1060 | - 'desc' => $action_details['label'] |
|
| 1061 | - ); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - /** @type array $status_items status legend setup */ |
|
| 1065 | - $status_items = array( |
|
| 1066 | - 'sent_status' => array( |
|
| 1067 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | - ), |
|
| 1070 | - 'idle_status' => array( |
|
| 1071 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | - ), |
|
| 1074 | - 'failed_status' => array( |
|
| 1075 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | - ), |
|
| 1078 | - 'messenger_executing_status' => array( |
|
| 1079 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | - ), |
|
| 1082 | - 'resend_status' => array( |
|
| 1083 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | - ), |
|
| 1086 | - 'incomplete_status' => array( |
|
| 1087 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | - ), |
|
| 1090 | - 'retry_status' => array( |
|
| 1091 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | - ) |
|
| 1094 | - ); |
|
| 1095 | - if (EEM_Message::debug()) { |
|
| 1096 | - $status_items['debug_only_status'] = array( |
|
| 1097 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | - ); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - return array_merge($action_items, $status_items); |
|
| 1103 | - } |
|
| 1048 | + protected function _message_legend_items() |
|
| 1049 | + { |
|
| 1050 | + |
|
| 1051 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1052 | + $action_items = array(); |
|
| 1053 | + |
|
| 1054 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1055 | + if ($action_item === 'see_notifications_for') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1058 | + $action_items[$action_item] = array( |
|
| 1059 | + 'class' => $action_details['css_class'], |
|
| 1060 | + 'desc' => $action_details['label'] |
|
| 1061 | + ); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + /** @type array $status_items status legend setup */ |
|
| 1065 | + $status_items = array( |
|
| 1066 | + 'sent_status' => array( |
|
| 1067 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1068 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1069 | + ), |
|
| 1070 | + 'idle_status' => array( |
|
| 1071 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1072 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1073 | + ), |
|
| 1074 | + 'failed_status' => array( |
|
| 1075 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1076 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1077 | + ), |
|
| 1078 | + 'messenger_executing_status' => array( |
|
| 1079 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1080 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1081 | + ), |
|
| 1082 | + 'resend_status' => array( |
|
| 1083 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1084 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1085 | + ), |
|
| 1086 | + 'incomplete_status' => array( |
|
| 1087 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1088 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1089 | + ), |
|
| 1090 | + 'retry_status' => array( |
|
| 1091 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1092 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1093 | + ) |
|
| 1094 | + ); |
|
| 1095 | + if (EEM_Message::debug()) { |
|
| 1096 | + $status_items['debug_only_status'] = array( |
|
| 1097 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1098 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1099 | + ); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + return array_merge($action_items, $status_items); |
|
| 1103 | + } |
|
| 1104 | 1104 | |
| 1105 | 1105 | |
| 1106 | - protected function _custom_mtps_preview() |
|
| 1107 | - { |
|
| 1108 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | - . esc_html__( |
|
| 1113 | - '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.', |
|
| 1114 | - 'event_espresso' |
|
| 1115 | - ) |
|
| 1116 | - . '</strong>'; |
|
| 1106 | + protected function _custom_mtps_preview() |
|
| 1107 | + { |
|
| 1108 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1109 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1110 | + . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1111 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1112 | + . esc_html__( |
|
| 1113 | + '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.', |
|
| 1114 | + 'event_espresso' |
|
| 1115 | + ) |
|
| 1116 | + . '</strong>'; |
|
| 1117 | 1117 | |
| 1118 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | - } |
|
| 1118 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * get_message_templates |
|
| 1124 | - * This gets all the message templates for listing on the overview list. |
|
| 1125 | - * |
|
| 1126 | - * @access public |
|
| 1127 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | - * @param string $type the current _view we're getting templates for |
|
| 1129 | - * @param bool $count return count? |
|
| 1130 | - * @param bool $all disregard any paging info (get all data); |
|
| 1131 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | - * @return array |
|
| 1133 | - * @throws EE_Error |
|
| 1134 | - * @throws InvalidArgumentException |
|
| 1135 | - * @throws InvalidDataTypeException |
|
| 1136 | - * @throws InvalidInterfaceException |
|
| 1137 | - */ |
|
| 1138 | - public function get_message_templates( |
|
| 1139 | - $perpage = 10, |
|
| 1140 | - $type = 'in_use', |
|
| 1141 | - $count = false, |
|
| 1142 | - $all = false, |
|
| 1143 | - $global = true) |
|
| 1144 | - { |
|
| 1145 | - |
|
| 1146 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | - |
|
| 1148 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | - $orderby = $this->_req_data['orderby']; |
|
| 1150 | - |
|
| 1151 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | - ? $this->_req_data['order'] |
|
| 1153 | - : 'ASC'; |
|
| 1154 | - |
|
| 1155 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | - ? $this->_req_data['paged'] |
|
| 1157 | - : 1; |
|
| 1158 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | - ? $this->_req_data['perpage'] |
|
| 1160 | - : $perpage; |
|
| 1161 | - |
|
| 1162 | - $offset = ($current_page - 1) * $per_page; |
|
| 1163 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - //options will match what is in the _views array property |
|
| 1167 | - switch ($type) { |
|
| 1168 | - case 'in_use': |
|
| 1169 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | - break; |
|
| 1171 | - default: |
|
| 1172 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - return $templates; |
|
| 1176 | - } |
|
| 1122 | + /** |
|
| 1123 | + * get_message_templates |
|
| 1124 | + * This gets all the message templates for listing on the overview list. |
|
| 1125 | + * |
|
| 1126 | + * @access public |
|
| 1127 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1128 | + * @param string $type the current _view we're getting templates for |
|
| 1129 | + * @param bool $count return count? |
|
| 1130 | + * @param bool $all disregard any paging info (get all data); |
|
| 1131 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1132 | + * @return array |
|
| 1133 | + * @throws EE_Error |
|
| 1134 | + * @throws InvalidArgumentException |
|
| 1135 | + * @throws InvalidDataTypeException |
|
| 1136 | + * @throws InvalidInterfaceException |
|
| 1137 | + */ |
|
| 1138 | + public function get_message_templates( |
|
| 1139 | + $perpage = 10, |
|
| 1140 | + $type = 'in_use', |
|
| 1141 | + $count = false, |
|
| 1142 | + $all = false, |
|
| 1143 | + $global = true) |
|
| 1144 | + { |
|
| 1145 | + |
|
| 1146 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1147 | + |
|
| 1148 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1149 | + $orderby = $this->_req_data['orderby']; |
|
| 1150 | + |
|
| 1151 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1152 | + ? $this->_req_data['order'] |
|
| 1153 | + : 'ASC'; |
|
| 1154 | + |
|
| 1155 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1156 | + ? $this->_req_data['paged'] |
|
| 1157 | + : 1; |
|
| 1158 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1159 | + ? $this->_req_data['perpage'] |
|
| 1160 | + : $perpage; |
|
| 1161 | + |
|
| 1162 | + $offset = ($current_page - 1) * $per_page; |
|
| 1163 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + //options will match what is in the _views array property |
|
| 1167 | + switch ($type) { |
|
| 1168 | + case 'in_use': |
|
| 1169 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1170 | + break; |
|
| 1171 | + default: |
|
| 1172 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + return $templates; |
|
| 1176 | + } |
|
| 1177 | 1177 | |
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * filters etc might need a list of installed message_types |
|
| 1181 | - * @return array an array of message type objects |
|
| 1182 | - */ |
|
| 1183 | - public function get_installed_message_types() |
|
| 1184 | - { |
|
| 1185 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | - $installed = array(); |
|
| 1187 | - |
|
| 1188 | - foreach ($installed_message_types as $message_type) { |
|
| 1189 | - $installed[$message_type->name] = $message_type; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - return $installed; |
|
| 1193 | - } |
|
| 1179 | + /** |
|
| 1180 | + * filters etc might need a list of installed message_types |
|
| 1181 | + * @return array an array of message type objects |
|
| 1182 | + */ |
|
| 1183 | + public function get_installed_message_types() |
|
| 1184 | + { |
|
| 1185 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1186 | + $installed = array(); |
|
| 1187 | + |
|
| 1188 | + foreach ($installed_message_types as $message_type) { |
|
| 1189 | + $installed[$message_type->name] = $message_type; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + return $installed; |
|
| 1193 | + } |
|
| 1194 | 1194 | |
| 1195 | 1195 | |
| 1196 | - /** |
|
| 1197 | - * _add_message_template |
|
| 1198 | - * |
|
| 1199 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | - * |
|
| 1201 | - * @param string $message_type |
|
| 1202 | - * @param string $messenger |
|
| 1203 | - * @param string $GRP_ID |
|
| 1204 | - * |
|
| 1205 | - * @throws EE_error |
|
| 1206 | - */ |
|
| 1207 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | - { |
|
| 1209 | - //set values override any request data |
|
| 1210 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | - ? $this->_req_data['message_type'] |
|
| 1213 | - : $message_type; |
|
| 1214 | - |
|
| 1215 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | - ? $this->_req_data['messenger'] |
|
| 1218 | - : $messenger; |
|
| 1219 | - |
|
| 1220 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | - |
|
| 1223 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | - if (empty($message_type) || empty($messenger)) { |
|
| 1225 | - throw new EE_Error( |
|
| 1226 | - esc_html__( |
|
| 1227 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | - 'event_espresso' |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | - if (empty($GRP_ID)) { |
|
| 1235 | - throw new EE_Error( |
|
| 1236 | - esc_html__( |
|
| 1237 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | - 'event_espresso' |
|
| 1239 | - ) |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - //let's just make sure the template gets generated! |
|
| 1244 | - |
|
| 1245 | - //we need to reassign some variables for what the insert is expecting |
|
| 1246 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | - $this->_insert_or_update_message_template(true); |
|
| 1250 | - } |
|
| 1196 | + /** |
|
| 1197 | + * _add_message_template |
|
| 1198 | + * |
|
| 1199 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1200 | + * |
|
| 1201 | + * @param string $message_type |
|
| 1202 | + * @param string $messenger |
|
| 1203 | + * @param string $GRP_ID |
|
| 1204 | + * |
|
| 1205 | + * @throws EE_error |
|
| 1206 | + */ |
|
| 1207 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1208 | + { |
|
| 1209 | + //set values override any request data |
|
| 1210 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1211 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1212 | + ? $this->_req_data['message_type'] |
|
| 1213 | + : $message_type; |
|
| 1214 | + |
|
| 1215 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1216 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1217 | + ? $this->_req_data['messenger'] |
|
| 1218 | + : $messenger; |
|
| 1219 | + |
|
| 1220 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1221 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1222 | + |
|
| 1223 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1224 | + if (empty($message_type) || empty($messenger)) { |
|
| 1225 | + throw new EE_Error( |
|
| 1226 | + esc_html__( |
|
| 1227 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1228 | + 'event_espresso' |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1234 | + if (empty($GRP_ID)) { |
|
| 1235 | + throw new EE_Error( |
|
| 1236 | + esc_html__( |
|
| 1237 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1238 | + 'event_espresso' |
|
| 1239 | + ) |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + //let's just make sure the template gets generated! |
|
| 1244 | + |
|
| 1245 | + //we need to reassign some variables for what the insert is expecting |
|
| 1246 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1247 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1248 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1249 | + $this->_insert_or_update_message_template(true); |
|
| 1250 | + } |
|
| 1251 | 1251 | |
| 1252 | 1252 | |
| 1253 | - /** |
|
| 1254 | - * public wrapper for the _add_message_template method |
|
| 1255 | - * |
|
| 1256 | - * @param string $message_type message type slug |
|
| 1257 | - * @param string $messenger messenger slug |
|
| 1258 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | - * off of. |
|
| 1260 | - * @throws EE_error |
|
| 1261 | - */ |
|
| 1262 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | - { |
|
| 1264 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | - } |
|
| 1253 | + /** |
|
| 1254 | + * public wrapper for the _add_message_template method |
|
| 1255 | + * |
|
| 1256 | + * @param string $message_type message type slug |
|
| 1257 | + * @param string $messenger messenger slug |
|
| 1258 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1259 | + * off of. |
|
| 1260 | + * @throws EE_error |
|
| 1261 | + */ |
|
| 1262 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1263 | + { |
|
| 1264 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1265 | + } |
|
| 1266 | 1266 | |
| 1267 | 1267 | |
| 1268 | - /** |
|
| 1269 | - * _edit_message_template |
|
| 1270 | - * |
|
| 1271 | - * @access protected |
|
| 1272 | - * @return void |
|
| 1273 | - * @throws InvalidIdentifierException |
|
| 1274 | - * @throws DomainException |
|
| 1275 | - * @throws EE_Error |
|
| 1276 | - * @throws InvalidArgumentException |
|
| 1277 | - * @throws ReflectionException |
|
| 1278 | - * @throws InvalidDataTypeException |
|
| 1279 | - * @throws InvalidInterfaceException |
|
| 1280 | - */ |
|
| 1281 | - protected function _edit_message_template() |
|
| 1282 | - { |
|
| 1283 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | - $template_fields = ''; |
|
| 1285 | - $sidebar_fields = ''; |
|
| 1286 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | - // valid html in the templates. |
|
| 1288 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | - |
|
| 1290 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | - ? absint($this->_req_data['id']) |
|
| 1292 | - : false; |
|
| 1293 | - |
|
| 1294 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | - $message_template_group = $this->_message_template_group; |
|
| 1296 | - $c_label = $message_template_group->context_label(); |
|
| 1297 | - $c_config = $message_template_group->contexts_config(); |
|
| 1298 | - |
|
| 1299 | - reset($c_config); |
|
| 1300 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | - ? strtolower($this->_req_data['context']) |
|
| 1302 | - : key($c_config); |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - if (empty($GRP_ID)) { |
|
| 1306 | - $action = 'insert_message_template'; |
|
| 1307 | - $edit_message_template_form_url = add_query_arg( |
|
| 1308 | - array('action' => $action, 'noheader' => true), |
|
| 1309 | - EE_MSG_ADMIN_URL |
|
| 1310 | - ); |
|
| 1311 | - } else { |
|
| 1312 | - $action = 'update_message_template'; |
|
| 1313 | - $edit_message_template_form_url = add_query_arg( |
|
| 1314 | - array('action' => $action, 'noheader' => true), |
|
| 1315 | - EE_MSG_ADMIN_URL |
|
| 1316 | - ); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - //set active messenger for this view |
|
| 1320 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | - $message_template_group->messenger() |
|
| 1322 | - ); |
|
| 1323 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - //Do we have any validation errors? |
|
| 1327 | - $validators = $this->_get_transient(); |
|
| 1328 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - //we need to assemble the title from Various details |
|
| 1332 | - $context_label = sprintf( |
|
| 1333 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | - $c_config[$context]['label'], |
|
| 1335 | - ucwords($c_label['label']) |
|
| 1336 | - ); |
|
| 1337 | - |
|
| 1338 | - $title = sprintf( |
|
| 1339 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | - $context_label |
|
| 1343 | - ); |
|
| 1344 | - |
|
| 1345 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | - $message_template_group->messenger(), |
|
| 1353 | - $message_template_group->message_type() |
|
| 1354 | - ); |
|
| 1355 | - |
|
| 1356 | - if ( ! $template_field_structure) { |
|
| 1357 | - $template_field_structure = false; |
|
| 1358 | - $template_fields = esc_html__( |
|
| 1359 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | - 'event_espresso' |
|
| 1361 | - ); |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - $message_templates = $message_template_group->context_templates(); |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | - // will get handled in the "extra" array. |
|
| 1370 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | - if ( ! empty($template_field_structure)) { |
|
| 1378 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | - // the extra array and reset them. |
|
| 1381 | - if ($template_field === 'extra') { |
|
| 1382 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | - $content = $message_template instanceof EE_Message_Template |
|
| 1386 | - ? $message_template->get('MTP_content') |
|
| 1387 | - : ''; |
|
| 1388 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | - $continue = false; |
|
| 1391 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | - $continue = true; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - if ($continue) { |
|
| 1398 | - continue; |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1268 | + /** |
|
| 1269 | + * _edit_message_template |
|
| 1270 | + * |
|
| 1271 | + * @access protected |
|
| 1272 | + * @return void |
|
| 1273 | + * @throws InvalidIdentifierException |
|
| 1274 | + * @throws DomainException |
|
| 1275 | + * @throws EE_Error |
|
| 1276 | + * @throws InvalidArgumentException |
|
| 1277 | + * @throws ReflectionException |
|
| 1278 | + * @throws InvalidDataTypeException |
|
| 1279 | + * @throws InvalidInterfaceException |
|
| 1280 | + */ |
|
| 1281 | + protected function _edit_message_template() |
|
| 1282 | + { |
|
| 1283 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1284 | + $template_fields = ''; |
|
| 1285 | + $sidebar_fields = ''; |
|
| 1286 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1287 | + // valid html in the templates. |
|
| 1288 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1289 | + |
|
| 1290 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1291 | + ? absint($this->_req_data['id']) |
|
| 1292 | + : false; |
|
| 1293 | + |
|
| 1294 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1295 | + $message_template_group = $this->_message_template_group; |
|
| 1296 | + $c_label = $message_template_group->context_label(); |
|
| 1297 | + $c_config = $message_template_group->contexts_config(); |
|
| 1298 | + |
|
| 1299 | + reset($c_config); |
|
| 1300 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1301 | + ? strtolower($this->_req_data['context']) |
|
| 1302 | + : key($c_config); |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + if (empty($GRP_ID)) { |
|
| 1306 | + $action = 'insert_message_template'; |
|
| 1307 | + $edit_message_template_form_url = add_query_arg( |
|
| 1308 | + array('action' => $action, 'noheader' => true), |
|
| 1309 | + EE_MSG_ADMIN_URL |
|
| 1310 | + ); |
|
| 1311 | + } else { |
|
| 1312 | + $action = 'update_message_template'; |
|
| 1313 | + $edit_message_template_form_url = add_query_arg( |
|
| 1314 | + array('action' => $action, 'noheader' => true), |
|
| 1315 | + EE_MSG_ADMIN_URL |
|
| 1316 | + ); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + //set active messenger for this view |
|
| 1320 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1321 | + $message_template_group->messenger() |
|
| 1322 | + ); |
|
| 1323 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + //Do we have any validation errors? |
|
| 1327 | + $validators = $this->_get_transient(); |
|
| 1328 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + //we need to assemble the title from Various details |
|
| 1332 | + $context_label = sprintf( |
|
| 1333 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1334 | + $c_config[$context]['label'], |
|
| 1335 | + ucwords($c_label['label']) |
|
| 1336 | + ); |
|
| 1337 | + |
|
| 1338 | + $title = sprintf( |
|
| 1339 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1340 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1341 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1342 | + $context_label |
|
| 1343 | + ); |
|
| 1344 | + |
|
| 1345 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1346 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1347 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1351 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1352 | + $message_template_group->messenger(), |
|
| 1353 | + $message_template_group->message_type() |
|
| 1354 | + ); |
|
| 1355 | + |
|
| 1356 | + if ( ! $template_field_structure) { |
|
| 1357 | + $template_field_structure = false; |
|
| 1358 | + $template_fields = esc_html__( |
|
| 1359 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1360 | + 'event_espresso' |
|
| 1361 | + ); |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + $message_templates = $message_template_group->context_templates(); |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1369 | + // will get handled in the "extra" array. |
|
| 1370 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1371 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1372 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1377 | + if ( ! empty($template_field_structure)) { |
|
| 1378 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1379 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1380 | + // the extra array and reset them. |
|
| 1381 | + if ($template_field === 'extra') { |
|
| 1382 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1383 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1384 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1385 | + $content = $message_template instanceof EE_Message_Template |
|
| 1386 | + ? $message_template->get('MTP_content') |
|
| 1387 | + : ''; |
|
| 1388 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1389 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1390 | + $continue = false; |
|
| 1391 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1392 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1393 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1394 | + $continue = true; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + if ($continue) { |
|
| 1398 | + continue; |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | 1401 | |
| 1402 | - $field_id = $reference_field |
|
| 1403 | - . '-' |
|
| 1404 | - . $extra_field |
|
| 1405 | - . '-content'; |
|
| 1406 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | - . $reference_field |
|
| 1409 | - . '][content][' |
|
| 1410 | - . $extra_field . ']'; |
|
| 1411 | - $css_class = isset($extra_array['css_class']) |
|
| 1412 | - ? $extra_array['css_class'] |
|
| 1413 | - : ''; |
|
| 1402 | + $field_id = $reference_field |
|
| 1403 | + . '-' |
|
| 1404 | + . $extra_field |
|
| 1405 | + . '-content'; |
|
| 1406 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1407 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1408 | + . $reference_field |
|
| 1409 | + . '][content][' |
|
| 1410 | + . $extra_field . ']'; |
|
| 1411 | + $css_class = isset($extra_array['css_class']) |
|
| 1412 | + ? $extra_array['css_class'] |
|
| 1413 | + : ''; |
|
| 1414 | 1414 | |
| 1415 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | - && in_array($extra_field, $v_fields, true) |
|
| 1417 | - && |
|
| 1418 | - ( |
|
| 1419 | - is_array($validators[$extra_field]) |
|
| 1420 | - && isset($validators[$extra_field]['msg']) |
|
| 1421 | - ) |
|
| 1422 | - ? 'validate-error ' . $css_class |
|
| 1423 | - : $css_class; |
|
| 1415 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1416 | + && in_array($extra_field, $v_fields, true) |
|
| 1417 | + && |
|
| 1418 | + ( |
|
| 1419 | + is_array($validators[$extra_field]) |
|
| 1420 | + && isset($validators[$extra_field]['msg']) |
|
| 1421 | + ) |
|
| 1422 | + ? 'validate-error ' . $css_class |
|
| 1423 | + : $css_class; |
|
| 1424 | 1424 | |
| 1425 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | - && isset($content[$extra_field]) |
|
| 1427 | - ? $content[$extra_field] |
|
| 1428 | - : ''; |
|
| 1425 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1426 | + && isset($content[$extra_field]) |
|
| 1427 | + ? $content[$extra_field] |
|
| 1428 | + : ''; |
|
| 1429 | 1429 | |
| 1430 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | - ? $validators[$extra_field]['value'] |
|
| 1433 | - : $template_form_fields[$field_id]['value']; |
|
| 1430 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1431 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1432 | + ? $validators[$extra_field]['value'] |
|
| 1433 | + : $template_form_fields[$field_id]['value']; |
|
| 1434 | 1434 | |
| 1435 | 1435 | |
| 1436 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1436 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1437 | 1437 | |
| 1438 | - //shortcode selector |
|
| 1439 | - $field_name_to_use = $extra_field === 'main' |
|
| 1440 | - ? 'content' |
|
| 1441 | - : $extra_field; |
|
| 1442 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | - $field_name_to_use, |
|
| 1444 | - $field_id |
|
| 1445 | - ); |
|
| 1438 | + //shortcode selector |
|
| 1439 | + $field_name_to_use = $extra_field === 'main' |
|
| 1440 | + ? 'content' |
|
| 1441 | + : $extra_field; |
|
| 1442 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1443 | + $field_name_to_use, |
|
| 1444 | + $field_id |
|
| 1445 | + ); |
|
| 1446 | 1446 | |
| 1447 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | - //we want to decode the entities |
|
| 1449 | - $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
|
| 1447 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1448 | + //we want to decode the entities |
|
| 1449 | + $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
|
| 1450 | 1450 | |
| 1451 | - }/**/ |
|
| 1452 | - } |
|
| 1453 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1451 | + }/**/ |
|
| 1452 | + } |
|
| 1453 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1455 | 1455 | |
| 1456 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1457 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1458 | - 'label' => null, |
|
| 1459 | - 'input' => 'hidden', |
|
| 1460 | - 'type' => 'int', |
|
| 1461 | - 'required' => false, |
|
| 1462 | - 'validation' => false, |
|
| 1463 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1464 | - 'css_class' => '', |
|
| 1465 | - 'format' => '%d', |
|
| 1466 | - 'db-col' => 'MTP_ID' |
|
| 1467 | - ); |
|
| 1456 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1457 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1458 | + 'label' => null, |
|
| 1459 | + 'input' => 'hidden', |
|
| 1460 | + 'type' => 'int', |
|
| 1461 | + 'required' => false, |
|
| 1462 | + 'validation' => false, |
|
| 1463 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1464 | + 'css_class' => '', |
|
| 1465 | + 'format' => '%d', |
|
| 1466 | + 'db-col' => 'MTP_ID' |
|
| 1467 | + ); |
|
| 1468 | 1468 | |
| 1469 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1470 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1471 | - 'label' => null, |
|
| 1472 | - 'input' => 'hidden', |
|
| 1473 | - 'type' => 'string', |
|
| 1474 | - 'required' => false, |
|
| 1475 | - 'validation' => true, |
|
| 1476 | - 'value' => $reference_field, |
|
| 1477 | - 'css_class' => '', |
|
| 1478 | - 'format' => '%s', |
|
| 1479 | - 'db-col' => 'MTP_template_field' |
|
| 1480 | - ); |
|
| 1481 | - } |
|
| 1482 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1483 | - } else { |
|
| 1484 | - $field_id = $template_field . '-content'; |
|
| 1485 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1486 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1487 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1488 | - ? $message_templates[$context][$template_field] |
|
| 1489 | - : null; |
|
| 1490 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1491 | - && is_array($message_templates[$context]) |
|
| 1492 | - && $message_template instanceof EE_Message_Template |
|
| 1493 | - ? $message_template->get('MTP_content') |
|
| 1494 | - : ''; |
|
| 1469 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1470 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1471 | + 'label' => null, |
|
| 1472 | + 'input' => 'hidden', |
|
| 1473 | + 'type' => 'string', |
|
| 1474 | + 'required' => false, |
|
| 1475 | + 'validation' => true, |
|
| 1476 | + 'value' => $reference_field, |
|
| 1477 | + 'css_class' => '', |
|
| 1478 | + 'format' => '%s', |
|
| 1479 | + 'db-col' => 'MTP_template_field' |
|
| 1480 | + ); |
|
| 1481 | + } |
|
| 1482 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1483 | + } else { |
|
| 1484 | + $field_id = $template_field . '-content'; |
|
| 1485 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1486 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1487 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1488 | + ? $message_templates[$context][$template_field] |
|
| 1489 | + : null; |
|
| 1490 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1491 | + && is_array($message_templates[$context]) |
|
| 1492 | + && $message_template instanceof EE_Message_Template |
|
| 1493 | + ? $message_template->get('MTP_content') |
|
| 1494 | + : ''; |
|
| 1495 | 1495 | |
| 1496 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1497 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1498 | - ? $validators[$template_field]['value'] |
|
| 1499 | - : $template_form_fields[$field_id]['value']; |
|
| 1496 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1497 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1498 | + ? $validators[$template_field]['value'] |
|
| 1499 | + : $template_form_fields[$field_id]['value']; |
|
| 1500 | 1500 | |
| 1501 | 1501 | |
| 1502 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1503 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1504 | - ? $field_setup_array['css_class'] |
|
| 1505 | - : ''; |
|
| 1506 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1507 | - && in_array($template_field, $v_fields, true) |
|
| 1508 | - && isset($validators[$template_field]['msg']) |
|
| 1509 | - ? 'validate-error ' . $css_class |
|
| 1510 | - : $css_class; |
|
| 1502 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1503 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1504 | + ? $field_setup_array['css_class'] |
|
| 1505 | + : ''; |
|
| 1506 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1507 | + && in_array($template_field, $v_fields, true) |
|
| 1508 | + && isset($validators[$template_field]['msg']) |
|
| 1509 | + ? 'validate-error ' . $css_class |
|
| 1510 | + : $css_class; |
|
| 1511 | 1511 | |
| 1512 | - //shortcode selector |
|
| 1513 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1514 | - $template_field, $field_id |
|
| 1515 | - ); |
|
| 1516 | - } |
|
| 1512 | + //shortcode selector |
|
| 1513 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1514 | + $template_field, $field_id |
|
| 1515 | + ); |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - //k took care of content field(s) now let's take care of others. |
|
| 1518 | + //k took care of content field(s) now let's take care of others. |
|
| 1519 | 1519 | |
| 1520 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1521 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1520 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1521 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1522 | 1522 | |
| 1523 | - //foreach template field there are actually two form fields created |
|
| 1524 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1525 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1526 | - 'label' => null, |
|
| 1527 | - 'input' => 'hidden', |
|
| 1528 | - 'type' => 'int', |
|
| 1529 | - 'required' => false, |
|
| 1530 | - 'validation' => true, |
|
| 1531 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1532 | - 'css_class' => '', |
|
| 1533 | - 'format' => '%d', |
|
| 1534 | - 'db-col' => 'MTP_ID' |
|
| 1535 | - ); |
|
| 1523 | + //foreach template field there are actually two form fields created |
|
| 1524 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1525 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1526 | + 'label' => null, |
|
| 1527 | + 'input' => 'hidden', |
|
| 1528 | + 'type' => 'int', |
|
| 1529 | + 'required' => false, |
|
| 1530 | + 'validation' => true, |
|
| 1531 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1532 | + 'css_class' => '', |
|
| 1533 | + 'format' => '%d', |
|
| 1534 | + 'db-col' => 'MTP_ID' |
|
| 1535 | + ); |
|
| 1536 | 1536 | |
| 1537 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1538 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1539 | - 'label' => null, |
|
| 1540 | - 'input' => 'hidden', |
|
| 1541 | - 'type' => 'string', |
|
| 1542 | - 'required' => false, |
|
| 1543 | - 'validation' => true, |
|
| 1544 | - 'value' => $template_field, |
|
| 1545 | - 'css_class' => '', |
|
| 1546 | - 'format' => '%s', |
|
| 1547 | - 'db-col' => 'MTP_template_field' |
|
| 1548 | - ); |
|
| 1537 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1538 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1539 | + 'label' => null, |
|
| 1540 | + 'input' => 'hidden', |
|
| 1541 | + 'type' => 'string', |
|
| 1542 | + 'required' => false, |
|
| 1543 | + 'validation' => true, |
|
| 1544 | + 'value' => $template_field, |
|
| 1545 | + 'css_class' => '', |
|
| 1546 | + 'format' => '%s', |
|
| 1547 | + 'db-col' => 'MTP_template_field' |
|
| 1548 | + ); |
|
| 1549 | 1549 | |
| 1550 | - } |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - //add other fields |
|
| 1553 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1554 | - 'name' => 'MTP_context', |
|
| 1555 | - 'label' => null, |
|
| 1556 | - 'input' => 'hidden', |
|
| 1557 | - 'type' => 'string', |
|
| 1558 | - 'required' => false, |
|
| 1559 | - 'validation' => true, |
|
| 1560 | - 'value' => $context, |
|
| 1561 | - 'css_class' => '', |
|
| 1562 | - 'format' => '%s', |
|
| 1563 | - 'db-col' => 'MTP_context' |
|
| 1564 | - ); |
|
| 1552 | + //add other fields |
|
| 1553 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1554 | + 'name' => 'MTP_context', |
|
| 1555 | + 'label' => null, |
|
| 1556 | + 'input' => 'hidden', |
|
| 1557 | + 'type' => 'string', |
|
| 1558 | + 'required' => false, |
|
| 1559 | + 'validation' => true, |
|
| 1560 | + 'value' => $context, |
|
| 1561 | + 'css_class' => '', |
|
| 1562 | + 'format' => '%s', |
|
| 1563 | + 'db-col' => 'MTP_context' |
|
| 1564 | + ); |
|
| 1565 | 1565 | |
| 1566 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1567 | - 'name' => 'GRP_ID', |
|
| 1568 | - 'label' => null, |
|
| 1569 | - 'input' => 'hidden', |
|
| 1570 | - 'type' => 'int', |
|
| 1571 | - 'required' => false, |
|
| 1572 | - 'validation' => true, |
|
| 1573 | - 'value' => $GRP_ID, |
|
| 1574 | - 'css_class' => '', |
|
| 1575 | - 'format' => '%d', |
|
| 1576 | - 'db-col' => 'GRP_ID' |
|
| 1577 | - ); |
|
| 1566 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1567 | + 'name' => 'GRP_ID', |
|
| 1568 | + 'label' => null, |
|
| 1569 | + 'input' => 'hidden', |
|
| 1570 | + 'type' => 'int', |
|
| 1571 | + 'required' => false, |
|
| 1572 | + 'validation' => true, |
|
| 1573 | + 'value' => $GRP_ID, |
|
| 1574 | + 'css_class' => '', |
|
| 1575 | + 'format' => '%d', |
|
| 1576 | + 'db-col' => 'GRP_ID' |
|
| 1577 | + ); |
|
| 1578 | 1578 | |
| 1579 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1580 | - 'name' => 'MTP_messenger', |
|
| 1581 | - 'label' => null, |
|
| 1582 | - 'input' => 'hidden', |
|
| 1583 | - 'type' => 'string', |
|
| 1584 | - 'required' => false, |
|
| 1585 | - 'validation' => true, |
|
| 1586 | - 'value' => $message_template_group->messenger(), |
|
| 1587 | - 'css_class' => '', |
|
| 1588 | - 'format' => '%s', |
|
| 1589 | - 'db-col' => 'MTP_messenger' |
|
| 1590 | - ); |
|
| 1579 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1580 | + 'name' => 'MTP_messenger', |
|
| 1581 | + 'label' => null, |
|
| 1582 | + 'input' => 'hidden', |
|
| 1583 | + 'type' => 'string', |
|
| 1584 | + 'required' => false, |
|
| 1585 | + 'validation' => true, |
|
| 1586 | + 'value' => $message_template_group->messenger(), |
|
| 1587 | + 'css_class' => '', |
|
| 1588 | + 'format' => '%s', |
|
| 1589 | + 'db-col' => 'MTP_messenger' |
|
| 1590 | + ); |
|
| 1591 | 1591 | |
| 1592 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1593 | - 'name' => 'MTP_message_type', |
|
| 1594 | - 'label' => null, |
|
| 1595 | - 'input' => 'hidden', |
|
| 1596 | - 'type' => 'string', |
|
| 1597 | - 'required' => false, |
|
| 1598 | - 'validation' => true, |
|
| 1599 | - 'value' => $message_template_group->message_type(), |
|
| 1600 | - 'css_class' => '', |
|
| 1601 | - 'format' => '%s', |
|
| 1602 | - 'db-col' => 'MTP_message_type' |
|
| 1603 | - ); |
|
| 1592 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1593 | + 'name' => 'MTP_message_type', |
|
| 1594 | + 'label' => null, |
|
| 1595 | + 'input' => 'hidden', |
|
| 1596 | + 'type' => 'string', |
|
| 1597 | + 'required' => false, |
|
| 1598 | + 'validation' => true, |
|
| 1599 | + 'value' => $message_template_group->message_type(), |
|
| 1600 | + 'css_class' => '', |
|
| 1601 | + 'format' => '%s', |
|
| 1602 | + 'db-col' => 'MTP_message_type' |
|
| 1603 | + ); |
|
| 1604 | 1604 | |
| 1605 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1606 | - 'name' => 'MTP_is_global', |
|
| 1607 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1608 | - 'input' => 'hidden', |
|
| 1609 | - 'type' => 'int', |
|
| 1610 | - 'required' => false, |
|
| 1611 | - 'validation' => true, |
|
| 1612 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1613 | - 'css_class' => '', |
|
| 1614 | - 'format' => '%d', |
|
| 1615 | - 'db-col' => 'MTP_is_global' |
|
| 1616 | - ); |
|
| 1605 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1606 | + 'name' => 'MTP_is_global', |
|
| 1607 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1608 | + 'input' => 'hidden', |
|
| 1609 | + 'type' => 'int', |
|
| 1610 | + 'required' => false, |
|
| 1611 | + 'validation' => true, |
|
| 1612 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1613 | + 'css_class' => '', |
|
| 1614 | + 'format' => '%d', |
|
| 1615 | + 'db-col' => 'MTP_is_global' |
|
| 1616 | + ); |
|
| 1617 | 1617 | |
| 1618 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1619 | - 'name' => 'MTP_is_override', |
|
| 1620 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1621 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1622 | - 'type' => 'int', |
|
| 1623 | - 'required' => false, |
|
| 1624 | - 'validation' => true, |
|
| 1625 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1626 | - 'css_class' => '', |
|
| 1627 | - 'format' => '%d', |
|
| 1628 | - 'db-col' => 'MTP_is_override' |
|
| 1629 | - ); |
|
| 1618 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1619 | + 'name' => 'MTP_is_override', |
|
| 1620 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1621 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1622 | + 'type' => 'int', |
|
| 1623 | + 'required' => false, |
|
| 1624 | + 'validation' => true, |
|
| 1625 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1626 | + 'css_class' => '', |
|
| 1627 | + 'format' => '%d', |
|
| 1628 | + 'db-col' => 'MTP_is_override' |
|
| 1629 | + ); |
|
| 1630 | 1630 | |
| 1631 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1632 | - 'name' => 'MTP_is_active', |
|
| 1633 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1634 | - 'input' => 'hidden', |
|
| 1635 | - 'type' => 'int', |
|
| 1636 | - 'required' => false, |
|
| 1637 | - 'validation' => true, |
|
| 1638 | - 'value' => $message_template_group->is_active(), |
|
| 1639 | - 'css_class' => '', |
|
| 1640 | - 'format' => '%d', |
|
| 1641 | - 'db-col' => 'MTP_is_active' |
|
| 1642 | - ); |
|
| 1631 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1632 | + 'name' => 'MTP_is_active', |
|
| 1633 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1634 | + 'input' => 'hidden', |
|
| 1635 | + 'type' => 'int', |
|
| 1636 | + 'required' => false, |
|
| 1637 | + 'validation' => true, |
|
| 1638 | + 'value' => $message_template_group->is_active(), |
|
| 1639 | + 'css_class' => '', |
|
| 1640 | + 'format' => '%d', |
|
| 1641 | + 'db-col' => 'MTP_is_active' |
|
| 1642 | + ); |
|
| 1643 | 1643 | |
| 1644 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1645 | - 'name' => 'MTP_deleted', |
|
| 1646 | - 'label' => null, |
|
| 1647 | - 'input' => 'hidden', |
|
| 1648 | - 'type' => 'int', |
|
| 1649 | - 'required' => false, |
|
| 1650 | - 'validation' => true, |
|
| 1651 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1652 | - 'css_class' => '', |
|
| 1653 | - 'format' => '%d', |
|
| 1654 | - 'db-col' => 'MTP_deleted' |
|
| 1655 | - ); |
|
| 1656 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | - 'name' => 'MTP_user_id', |
|
| 1658 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1659 | - 'input' => 'hidden', |
|
| 1660 | - 'type' => 'int', |
|
| 1661 | - 'required' => false, |
|
| 1662 | - 'validation' => false, |
|
| 1663 | - 'value' => $message_template_group->user(), |
|
| 1664 | - 'format' => '%d', |
|
| 1665 | - 'db-col' => 'MTP_user_id' |
|
| 1666 | - ); |
|
| 1644 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1645 | + 'name' => 'MTP_deleted', |
|
| 1646 | + 'label' => null, |
|
| 1647 | + 'input' => 'hidden', |
|
| 1648 | + 'type' => 'int', |
|
| 1649 | + 'required' => false, |
|
| 1650 | + 'validation' => true, |
|
| 1651 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1652 | + 'css_class' => '', |
|
| 1653 | + 'format' => '%d', |
|
| 1654 | + 'db-col' => 'MTP_deleted' |
|
| 1655 | + ); |
|
| 1656 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | + 'name' => 'MTP_user_id', |
|
| 1658 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1659 | + 'input' => 'hidden', |
|
| 1660 | + 'type' => 'int', |
|
| 1661 | + 'required' => false, |
|
| 1662 | + 'validation' => false, |
|
| 1663 | + 'value' => $message_template_group->user(), |
|
| 1664 | + 'format' => '%d', |
|
| 1665 | + 'db-col' => 'MTP_user_id' |
|
| 1666 | + ); |
|
| 1667 | 1667 | |
| 1668 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1669 | - 'name' => 'action', |
|
| 1670 | - 'input' => 'hidden', |
|
| 1671 | - 'type' => 'string', |
|
| 1672 | - 'value' => $action |
|
| 1673 | - ); |
|
| 1668 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1669 | + 'name' => 'action', |
|
| 1670 | + 'input' => 'hidden', |
|
| 1671 | + 'type' => 'string', |
|
| 1672 | + 'value' => $action |
|
| 1673 | + ); |
|
| 1674 | 1674 | |
| 1675 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | - 'name' => 'id', |
|
| 1677 | - 'input' => 'hidden', |
|
| 1678 | - 'type' => 'int', |
|
| 1679 | - 'value' => $GRP_ID |
|
| 1680 | - ); |
|
| 1681 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1682 | - 'name' => $action . '_nonce', |
|
| 1683 | - 'input' => 'hidden', |
|
| 1684 | - 'type' => 'string', |
|
| 1685 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1686 | - ); |
|
| 1675 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | + 'name' => 'id', |
|
| 1677 | + 'input' => 'hidden', |
|
| 1678 | + 'type' => 'int', |
|
| 1679 | + 'value' => $GRP_ID |
|
| 1680 | + ); |
|
| 1681 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1682 | + 'name' => $action . '_nonce', |
|
| 1683 | + 'input' => 'hidden', |
|
| 1684 | + 'type' => 'string', |
|
| 1685 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1686 | + ); |
|
| 1687 | 1687 | |
| 1688 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1689 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1690 | - 'name' => 'template_switch', |
|
| 1691 | - 'input' => 'hidden', |
|
| 1692 | - 'type' => 'int', |
|
| 1693 | - 'value' => 1 |
|
| 1694 | - ); |
|
| 1695 | - } |
|
| 1688 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1689 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1690 | + 'name' => 'template_switch', |
|
| 1691 | + 'input' => 'hidden', |
|
| 1692 | + 'type' => 'int', |
|
| 1693 | + 'value' => 1 |
|
| 1694 | + ); |
|
| 1695 | + } |
|
| 1696 | 1696 | |
| 1697 | 1697 | |
| 1698 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1699 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1698 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1699 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1700 | 1700 | |
| 1701 | 1701 | |
| 1702 | - } //end if ( !empty($template_field_structure) ) |
|
| 1703 | - |
|
| 1704 | - //set extra content for publish box |
|
| 1705 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1706 | - $this->_set_publish_post_box_vars( |
|
| 1707 | - 'id', |
|
| 1708 | - $GRP_ID, |
|
| 1709 | - false, |
|
| 1710 | - add_query_arg( |
|
| 1711 | - array('action' => 'global_mtps'), |
|
| 1712 | - $this->_admin_base_url |
|
| 1713 | - ) |
|
| 1714 | - ); |
|
| 1715 | - |
|
| 1716 | - //add preview button |
|
| 1717 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | - array( |
|
| 1719 | - 'message_type' => $message_template_group->message_type(), |
|
| 1720 | - 'messenger' => $message_template_group->messenger(), |
|
| 1721 | - 'context' => $context, |
|
| 1722 | - 'GRP_ID' => $GRP_ID, |
|
| 1723 | - 'action' => 'preview_message' |
|
| 1724 | - ), |
|
| 1725 | - $this->_admin_base_url |
|
| 1726 | - ); |
|
| 1727 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1728 | - . esc_html__('Preview', 'event_espresso') |
|
| 1729 | - . '</a>'; |
|
| 1730 | - |
|
| 1731 | - |
|
| 1732 | - //setup context switcher |
|
| 1733 | - $context_switcher_args = array( |
|
| 1734 | - 'page' => 'espresso_messages', |
|
| 1735 | - 'action' => 'edit_message_template', |
|
| 1736 | - 'id' => $GRP_ID, |
|
| 1737 | - 'context' => $context, |
|
| 1738 | - 'extra' => $preview_button |
|
| 1739 | - ); |
|
| 1740 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1741 | - |
|
| 1742 | - |
|
| 1743 | - //main box |
|
| 1744 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1745 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1746 | - $this->_template_args['action'] = $action; |
|
| 1747 | - $this->_template_args['context'] = $context; |
|
| 1748 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1749 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1750 | - $this->_learn_more_about_message_templates_link(); |
|
| 1751 | - |
|
| 1752 | - |
|
| 1753 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1754 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1755 | - $message_template_group, |
|
| 1756 | - $context, |
|
| 1757 | - $context_label |
|
| 1758 | - ); |
|
| 1759 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1760 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1761 | - |
|
| 1762 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1763 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1764 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | - |
|
| 1766 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1767 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1768 | - |
|
| 1769 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1770 | - $this->_template_path, |
|
| 1771 | - $this->_template_args, |
|
| 1772 | - true |
|
| 1773 | - ); |
|
| 1774 | - |
|
| 1775 | - |
|
| 1776 | - //finally, let's set the admin_page title |
|
| 1777 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1781 | - $this->_set_shortcodes(); |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - //final template wrapper |
|
| 1785 | - $this->display_admin_page_with_sidebar(); |
|
| 1786 | - } |
|
| 1702 | + } //end if ( !empty($template_field_structure) ) |
|
| 1703 | + |
|
| 1704 | + //set extra content for publish box |
|
| 1705 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1706 | + $this->_set_publish_post_box_vars( |
|
| 1707 | + 'id', |
|
| 1708 | + $GRP_ID, |
|
| 1709 | + false, |
|
| 1710 | + add_query_arg( |
|
| 1711 | + array('action' => 'global_mtps'), |
|
| 1712 | + $this->_admin_base_url |
|
| 1713 | + ) |
|
| 1714 | + ); |
|
| 1715 | + |
|
| 1716 | + //add preview button |
|
| 1717 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | + array( |
|
| 1719 | + 'message_type' => $message_template_group->message_type(), |
|
| 1720 | + 'messenger' => $message_template_group->messenger(), |
|
| 1721 | + 'context' => $context, |
|
| 1722 | + 'GRP_ID' => $GRP_ID, |
|
| 1723 | + 'action' => 'preview_message' |
|
| 1724 | + ), |
|
| 1725 | + $this->_admin_base_url |
|
| 1726 | + ); |
|
| 1727 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1728 | + . esc_html__('Preview', 'event_espresso') |
|
| 1729 | + . '</a>'; |
|
| 1730 | + |
|
| 1731 | + |
|
| 1732 | + //setup context switcher |
|
| 1733 | + $context_switcher_args = array( |
|
| 1734 | + 'page' => 'espresso_messages', |
|
| 1735 | + 'action' => 'edit_message_template', |
|
| 1736 | + 'id' => $GRP_ID, |
|
| 1737 | + 'context' => $context, |
|
| 1738 | + 'extra' => $preview_button |
|
| 1739 | + ); |
|
| 1740 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1741 | + |
|
| 1742 | + |
|
| 1743 | + //main box |
|
| 1744 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1745 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1746 | + $this->_template_args['action'] = $action; |
|
| 1747 | + $this->_template_args['context'] = $context; |
|
| 1748 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1749 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1750 | + $this->_learn_more_about_message_templates_link(); |
|
| 1751 | + |
|
| 1752 | + |
|
| 1753 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1754 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1755 | + $message_template_group, |
|
| 1756 | + $context, |
|
| 1757 | + $context_label |
|
| 1758 | + ); |
|
| 1759 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1760 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1761 | + |
|
| 1762 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1763 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1764 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | + |
|
| 1766 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1767 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1768 | + |
|
| 1769 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1770 | + $this->_template_path, |
|
| 1771 | + $this->_template_args, |
|
| 1772 | + true |
|
| 1773 | + ); |
|
| 1774 | + |
|
| 1775 | + |
|
| 1776 | + //finally, let's set the admin_page title |
|
| 1777 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1781 | + $this->_set_shortcodes(); |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + //final template wrapper |
|
| 1785 | + $this->display_admin_page_with_sidebar(); |
|
| 1786 | + } |
|
| 1787 | 1787 | |
| 1788 | 1788 | |
| 1789 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1790 | - { |
|
| 1791 | - return $mceInit; |
|
| 1792 | - } |
|
| 1789 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1790 | + { |
|
| 1791 | + return $mceInit; |
|
| 1792 | + } |
|
| 1793 | 1793 | |
| 1794 | 1794 | |
| 1795 | - public function add_context_switcher() |
|
| 1796 | - { |
|
| 1797 | - return $this->_context_switcher; |
|
| 1798 | - } |
|
| 1795 | + public function add_context_switcher() |
|
| 1796 | + { |
|
| 1797 | + return $this->_context_switcher; |
|
| 1798 | + } |
|
| 1799 | 1799 | |
| 1800 | 1800 | |
| 1801 | - /** |
|
| 1802 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1803 | - * |
|
| 1804 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1805 | - * @param string $context |
|
| 1806 | - * @param string $context_label |
|
| 1807 | - * @return string |
|
| 1808 | - * @throws DomainException |
|
| 1809 | - * @throws EE_Error |
|
| 1810 | - * @throws InvalidIdentifierException |
|
| 1811 | - */ |
|
| 1812 | - protected function add_active_context_element( |
|
| 1813 | - EE_Message_Template_Group $message_template_group, |
|
| 1814 | - $context, |
|
| 1815 | - $context_label |
|
| 1816 | - ) { |
|
| 1817 | - $template_args = array( |
|
| 1818 | - 'context' => $context, |
|
| 1819 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1820 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1821 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1822 | - ? 'context-off' |
|
| 1823 | - : 'context-on', |
|
| 1824 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1825 | - 'message_template_group_id' => $message_template_group->ID() |
|
| 1826 | - ); |
|
| 1827 | - return EEH_Template::display_template( |
|
| 1828 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | - $template_args, |
|
| 1830 | - true |
|
| 1831 | - ); |
|
| 1832 | - } |
|
| 1801 | + /** |
|
| 1802 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1803 | + * |
|
| 1804 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1805 | + * @param string $context |
|
| 1806 | + * @param string $context_label |
|
| 1807 | + * @return string |
|
| 1808 | + * @throws DomainException |
|
| 1809 | + * @throws EE_Error |
|
| 1810 | + * @throws InvalidIdentifierException |
|
| 1811 | + */ |
|
| 1812 | + protected function add_active_context_element( |
|
| 1813 | + EE_Message_Template_Group $message_template_group, |
|
| 1814 | + $context, |
|
| 1815 | + $context_label |
|
| 1816 | + ) { |
|
| 1817 | + $template_args = array( |
|
| 1818 | + 'context' => $context, |
|
| 1819 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1820 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1821 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1822 | + ? 'context-off' |
|
| 1823 | + : 'context-on', |
|
| 1824 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1825 | + 'message_template_group_id' => $message_template_group->ID() |
|
| 1826 | + ); |
|
| 1827 | + return EEH_Template::display_template( |
|
| 1828 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | + $template_args, |
|
| 1830 | + true |
|
| 1831 | + ); |
|
| 1832 | + } |
|
| 1833 | 1833 | |
| 1834 | 1834 | |
| 1835 | - /** |
|
| 1836 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1837 | - * Handles toggling the message context on or off. |
|
| 1838 | - * @throws EE_Error |
|
| 1839 | - * @throws InvalidArgumentException |
|
| 1840 | - * @throws InvalidDataTypeException |
|
| 1841 | - * @throws InvalidIdentifierException |
|
| 1842 | - * @throws InvalidInterfaceException |
|
| 1843 | - */ |
|
| 1844 | - public function toggle_context_template() |
|
| 1845 | - { |
|
| 1846 | - $success = true; |
|
| 1847 | - //check for required data |
|
| 1848 | - if (!isset( |
|
| 1849 | - $this->_req_data['message_template_group_id'], |
|
| 1850 | - $this->_req_data['context'], |
|
| 1851 | - $this->_req_data['status'] |
|
| 1852 | - )) { |
|
| 1853 | - EE_Error::add_error( |
|
| 1854 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1855 | - __FILE__, |
|
| 1856 | - __FUNCTION__, |
|
| 1857 | - __LINE__ |
|
| 1858 | - ); |
|
| 1859 | - $success = false; |
|
| 1860 | - } |
|
| 1835 | + /** |
|
| 1836 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1837 | + * Handles toggling the message context on or off. |
|
| 1838 | + * @throws EE_Error |
|
| 1839 | + * @throws InvalidArgumentException |
|
| 1840 | + * @throws InvalidDataTypeException |
|
| 1841 | + * @throws InvalidIdentifierException |
|
| 1842 | + * @throws InvalidInterfaceException |
|
| 1843 | + */ |
|
| 1844 | + public function toggle_context_template() |
|
| 1845 | + { |
|
| 1846 | + $success = true; |
|
| 1847 | + //check for required data |
|
| 1848 | + if (!isset( |
|
| 1849 | + $this->_req_data['message_template_group_id'], |
|
| 1850 | + $this->_req_data['context'], |
|
| 1851 | + $this->_req_data['status'] |
|
| 1852 | + )) { |
|
| 1853 | + EE_Error::add_error( |
|
| 1854 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1855 | + __FILE__, |
|
| 1856 | + __FUNCTION__, |
|
| 1857 | + __LINE__ |
|
| 1858 | + ); |
|
| 1859 | + $success = false; |
|
| 1860 | + } |
|
| 1861 | 1861 | |
| 1862 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1863 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1864 | - : ''; |
|
| 1865 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1866 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1867 | - $status = $this->_req_data['status']; |
|
| 1868 | - if ($status !== 'off' && $status !=='on') { |
|
| 1869 | - EE_Error::add_error( |
|
| 1870 | - sprintf( |
|
| 1871 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1872 | - $this->_req_data['status'] |
|
| 1873 | - ), |
|
| 1874 | - __FILE__, |
|
| 1875 | - __FUNCTION__, |
|
| 1876 | - __LINE__ |
|
| 1877 | - ); |
|
| 1878 | - $success = false; |
|
| 1879 | - } |
|
| 1880 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1881 | - $this->_req_data['message_template_group_id'] |
|
| 1882 | - ); |
|
| 1883 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | - EE_Error::add_error( |
|
| 1885 | - sprintf( |
|
| 1886 | - esc_html__( |
|
| 1887 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1888 | - 'event_espresso' |
|
| 1889 | - ), |
|
| 1890 | - $this->_req_data['message_template_group_id'], |
|
| 1891 | - 'EE_Message_Template_Group' |
|
| 1892 | - ), |
|
| 1893 | - __FILE__, |
|
| 1894 | - __FUNCTION__, |
|
| 1895 | - __LINE__ |
|
| 1896 | - ); |
|
| 1897 | - $success = false; |
|
| 1898 | - } |
|
| 1899 | - if ($success) { |
|
| 1900 | - $success = $status === 'off' |
|
| 1901 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1902 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1903 | - } |
|
| 1904 | - $this->_template_args['success'] = $success; |
|
| 1905 | - $this->_return_json(); |
|
| 1906 | - } |
|
| 1862 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1863 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1864 | + : ''; |
|
| 1865 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1866 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1867 | + $status = $this->_req_data['status']; |
|
| 1868 | + if ($status !== 'off' && $status !=='on') { |
|
| 1869 | + EE_Error::add_error( |
|
| 1870 | + sprintf( |
|
| 1871 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1872 | + $this->_req_data['status'] |
|
| 1873 | + ), |
|
| 1874 | + __FILE__, |
|
| 1875 | + __FUNCTION__, |
|
| 1876 | + __LINE__ |
|
| 1877 | + ); |
|
| 1878 | + $success = false; |
|
| 1879 | + } |
|
| 1880 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1881 | + $this->_req_data['message_template_group_id'] |
|
| 1882 | + ); |
|
| 1883 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | + EE_Error::add_error( |
|
| 1885 | + sprintf( |
|
| 1886 | + esc_html__( |
|
| 1887 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1888 | + 'event_espresso' |
|
| 1889 | + ), |
|
| 1890 | + $this->_req_data['message_template_group_id'], |
|
| 1891 | + 'EE_Message_Template_Group' |
|
| 1892 | + ), |
|
| 1893 | + __FILE__, |
|
| 1894 | + __FUNCTION__, |
|
| 1895 | + __LINE__ |
|
| 1896 | + ); |
|
| 1897 | + $success = false; |
|
| 1898 | + } |
|
| 1899 | + if ($success) { |
|
| 1900 | + $success = $status === 'off' |
|
| 1901 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1902 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1903 | + } |
|
| 1904 | + $this->_template_args['success'] = $success; |
|
| 1905 | + $this->_return_json(); |
|
| 1906 | + } |
|
| 1907 | 1907 | |
| 1908 | 1908 | |
| 1909 | 1909 | |
| 1910 | - public function _add_form_element_before() |
|
| 1911 | - { |
|
| 1912 | - return '<form method="post" action="' |
|
| 1913 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1914 | - . '" id="ee-msg-edit-frm">'; |
|
| 1915 | - } |
|
| 1910 | + public function _add_form_element_before() |
|
| 1911 | + { |
|
| 1912 | + return '<form method="post" action="' |
|
| 1913 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1914 | + . '" id="ee-msg-edit-frm">'; |
|
| 1915 | + } |
|
| 1916 | 1916 | |
| 1917 | - public function _add_form_element_after() |
|
| 1918 | - { |
|
| 1919 | - return '</form>'; |
|
| 1920 | - } |
|
| 1917 | + public function _add_form_element_after() |
|
| 1918 | + { |
|
| 1919 | + return '</form>'; |
|
| 1920 | + } |
|
| 1921 | 1921 | |
| 1922 | 1922 | |
| 1923 | - /** |
|
| 1924 | - * This executes switching the template pack for a message template. |
|
| 1925 | - * |
|
| 1926 | - * @since 4.5.0 |
|
| 1927 | - * @throws EE_Error |
|
| 1928 | - * @throws InvalidDataTypeException |
|
| 1929 | - * @throws InvalidInterfaceException |
|
| 1930 | - * @throws InvalidArgumentException |
|
| 1931 | - * @throws ReflectionException |
|
| 1932 | - */ |
|
| 1933 | - public function switch_template_pack() |
|
| 1934 | - { |
|
| 1935 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1936 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1937 | - |
|
| 1938 | - //verify we have needed values. |
|
| 1939 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1940 | - $this->_template_args['error'] = true; |
|
| 1941 | - EE_Error::add_error( |
|
| 1942 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1943 | - __FILE__, |
|
| 1944 | - __FUNCTION__, |
|
| 1945 | - __LINE__ |
|
| 1946 | - ); |
|
| 1947 | - } else { |
|
| 1948 | - //get template, set the new template_pack and then reset to default |
|
| 1949 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1950 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1923 | + /** |
|
| 1924 | + * This executes switching the template pack for a message template. |
|
| 1925 | + * |
|
| 1926 | + * @since 4.5.0 |
|
| 1927 | + * @throws EE_Error |
|
| 1928 | + * @throws InvalidDataTypeException |
|
| 1929 | + * @throws InvalidInterfaceException |
|
| 1930 | + * @throws InvalidArgumentException |
|
| 1931 | + * @throws ReflectionException |
|
| 1932 | + */ |
|
| 1933 | + public function switch_template_pack() |
|
| 1934 | + { |
|
| 1935 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1936 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1937 | + |
|
| 1938 | + //verify we have needed values. |
|
| 1939 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1940 | + $this->_template_args['error'] = true; |
|
| 1941 | + EE_Error::add_error( |
|
| 1942 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1943 | + __FILE__, |
|
| 1944 | + __FUNCTION__, |
|
| 1945 | + __LINE__ |
|
| 1946 | + ); |
|
| 1947 | + } else { |
|
| 1948 | + //get template, set the new template_pack and then reset to default |
|
| 1949 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1950 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1951 | 1951 | |
| 1952 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1953 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1954 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1952 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1953 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1954 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1955 | 1955 | |
| 1956 | - $query_args = $this->_reset_to_default_template(); |
|
| 1956 | + $query_args = $this->_reset_to_default_template(); |
|
| 1957 | 1957 | |
| 1958 | - if (empty($query_args['id'])) { |
|
| 1959 | - EE_Error::add_error( |
|
| 1960 | - esc_html__( |
|
| 1961 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1962 | - 'event_espresso' |
|
| 1963 | - ), |
|
| 1964 | - __FILE__, |
|
| 1965 | - __FUNCTION__, |
|
| 1966 | - __LINE__ |
|
| 1967 | - ); |
|
| 1968 | - $this->_template_args['error'] = true; |
|
| 1969 | - } else { |
|
| 1970 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1971 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1972 | - EE_Error::add_success( |
|
| 1973 | - sprintf( |
|
| 1974 | - esc_html__( |
|
| 1975 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1976 | - 'event_espresso' |
|
| 1977 | - ), |
|
| 1978 | - $template_label, |
|
| 1979 | - $template_pack_labels->template_pack |
|
| 1980 | - ) |
|
| 1981 | - ); |
|
| 1982 | - //generate the redirect url for js. |
|
| 1983 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1984 | - $this->_admin_base_url); |
|
| 1985 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1986 | - $this->_template_args['success'] = true; |
|
| 1987 | - } |
|
| 1958 | + if (empty($query_args['id'])) { |
|
| 1959 | + EE_Error::add_error( |
|
| 1960 | + esc_html__( |
|
| 1961 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1962 | + 'event_espresso' |
|
| 1963 | + ), |
|
| 1964 | + __FILE__, |
|
| 1965 | + __FUNCTION__, |
|
| 1966 | + __LINE__ |
|
| 1967 | + ); |
|
| 1968 | + $this->_template_args['error'] = true; |
|
| 1969 | + } else { |
|
| 1970 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1971 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1972 | + EE_Error::add_success( |
|
| 1973 | + sprintf( |
|
| 1974 | + esc_html__( |
|
| 1975 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1976 | + 'event_espresso' |
|
| 1977 | + ), |
|
| 1978 | + $template_label, |
|
| 1979 | + $template_pack_labels->template_pack |
|
| 1980 | + ) |
|
| 1981 | + ); |
|
| 1982 | + //generate the redirect url for js. |
|
| 1983 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1984 | + $this->_admin_base_url); |
|
| 1985 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1986 | + $this->_template_args['success'] = true; |
|
| 1987 | + } |
|
| 1988 | 1988 | |
| 1989 | - $this->_return_json(); |
|
| 1989 | + $this->_return_json(); |
|
| 1990 | 1990 | |
| 1991 | - } |
|
| 1992 | - } |
|
| 1991 | + } |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | 1994 | |
| 1995 | - /** |
|
| 1996 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1997 | - * they want. |
|
| 1998 | - * |
|
| 1999 | - * @access protected |
|
| 2000 | - * @return array|null |
|
| 2001 | - * @throws EE_Error |
|
| 2002 | - * @throws InvalidArgumentException |
|
| 2003 | - * @throws InvalidDataTypeException |
|
| 2004 | - * @throws InvalidInterfaceException |
|
| 2005 | - */ |
|
| 2006 | - protected function _reset_to_default_template() |
|
| 2007 | - { |
|
| 2008 | - |
|
| 2009 | - $templates = array(); |
|
| 2010 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2011 | - //we need to make sure we've got the info we need. |
|
| 2012 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2013 | - EE_Error::add_error( |
|
| 2014 | - esc_html__( |
|
| 2015 | - '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.', |
|
| 2016 | - 'event_espresso' |
|
| 2017 | - ), |
|
| 2018 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2019 | - ); |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - // all templates will be reset to whatever the defaults are |
|
| 2023 | - // for the global template matching the messenger and message type. |
|
| 2024 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2025 | - |
|
| 2026 | - if ($success) { |
|
| 1995 | + /** |
|
| 1996 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1997 | + * they want. |
|
| 1998 | + * |
|
| 1999 | + * @access protected |
|
| 2000 | + * @return array|null |
|
| 2001 | + * @throws EE_Error |
|
| 2002 | + * @throws InvalidArgumentException |
|
| 2003 | + * @throws InvalidDataTypeException |
|
| 2004 | + * @throws InvalidInterfaceException |
|
| 2005 | + */ |
|
| 2006 | + protected function _reset_to_default_template() |
|
| 2007 | + { |
|
| 2008 | + |
|
| 2009 | + $templates = array(); |
|
| 2010 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2011 | + //we need to make sure we've got the info we need. |
|
| 2012 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2013 | + EE_Error::add_error( |
|
| 2014 | + esc_html__( |
|
| 2015 | + '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.', |
|
| 2016 | + 'event_espresso' |
|
| 2017 | + ), |
|
| 2018 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2019 | + ); |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + // all templates will be reset to whatever the defaults are |
|
| 2023 | + // for the global template matching the messenger and message type. |
|
| 2024 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2025 | + |
|
| 2026 | + if ($success) { |
|
| 2027 | 2027 | |
| 2028 | - //let's first determine if the incoming template is a global template, |
|
| 2029 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2030 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2028 | + //let's first determine if the incoming template is a global template, |
|
| 2029 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2030 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2031 | 2031 | |
| 2032 | 2032 | |
| 2033 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2034 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2033 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2034 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2035 | 2035 | |
| 2036 | - if ($success) { |
|
| 2037 | - // if successfully deleted, lets generate the new ones. |
|
| 2038 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2039 | - // will use the related global template defaults for regeneration. |
|
| 2040 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2041 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2042 | - // for the current custom template when resetting. |
|
| 2043 | - $templates = $this->_generate_new_templates( |
|
| 2044 | - $this->_req_data['msgr'], |
|
| 2045 | - $this->_req_data['mt'], |
|
| 2046 | - $GRP_ID, |
|
| 2047 | - true |
|
| 2048 | - ); |
|
| 2049 | - } |
|
| 2036 | + if ($success) { |
|
| 2037 | + // if successfully deleted, lets generate the new ones. |
|
| 2038 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2039 | + // will use the related global template defaults for regeneration. |
|
| 2040 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2041 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2042 | + // for the current custom template when resetting. |
|
| 2043 | + $templates = $this->_generate_new_templates( |
|
| 2044 | + $this->_req_data['msgr'], |
|
| 2045 | + $this->_req_data['mt'], |
|
| 2046 | + $GRP_ID, |
|
| 2047 | + true |
|
| 2048 | + ); |
|
| 2049 | + } |
|
| 2050 | 2050 | |
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - //any error messages? |
|
| 2054 | - if ( ! $success) { |
|
| 2055 | - EE_Error::add_error( |
|
| 2056 | - esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2057 | - 'event_espresso'), |
|
| 2058 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2059 | - ); |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - //all good, let's add a success message! |
|
| 2063 | - if ($success && ! empty($templates)) { |
|
| 2064 | - //the info for the template we generated is the first element in the returned array |
|
| 2065 | - // $templates = $templates[0]; |
|
| 2066 | - EE_Error::overwrite_success(); |
|
| 2067 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - |
|
| 2071 | - $query_args = array( |
|
| 2072 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2073 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2074 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2075 | - ); |
|
| 2076 | - |
|
| 2077 | - //if called via ajax then we return query args otherwise redirect |
|
| 2078 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2079 | - return $query_args; |
|
| 2080 | - } else { |
|
| 2081 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + //any error messages? |
|
| 2054 | + if ( ! $success) { |
|
| 2055 | + EE_Error::add_error( |
|
| 2056 | + esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2057 | + 'event_espresso'), |
|
| 2058 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2059 | + ); |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + //all good, let's add a success message! |
|
| 2063 | + if ($success && ! empty($templates)) { |
|
| 2064 | + //the info for the template we generated is the first element in the returned array |
|
| 2065 | + // $templates = $templates[0]; |
|
| 2066 | + EE_Error::overwrite_success(); |
|
| 2067 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + |
|
| 2071 | + $query_args = array( |
|
| 2072 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2073 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2074 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2075 | + ); |
|
| 2076 | + |
|
| 2077 | + //if called via ajax then we return query args otherwise redirect |
|
| 2078 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2079 | + return $query_args; |
|
| 2080 | + } else { |
|
| 2081 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2082 | 2082 | |
| 2083 | - return null; |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2083 | + return null; |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | 2086 | |
| 2087 | 2087 | |
| 2088 | - /** |
|
| 2089 | - * Retrieve and set the message preview for display. |
|
| 2090 | - * |
|
| 2091 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2092 | - * @return string |
|
| 2093 | - * @throws ReflectionException |
|
| 2094 | - * @throws EE_Error |
|
| 2095 | - * @throws InvalidArgumentException |
|
| 2096 | - * @throws InvalidDataTypeException |
|
| 2097 | - * @throws InvalidInterfaceException |
|
| 2098 | - */ |
|
| 2099 | - public function _preview_message($send = false) |
|
| 2100 | - { |
|
| 2101 | - //first make sure we've got the necessary parameters |
|
| 2102 | - if ( |
|
| 2103 | - ! isset( |
|
| 2104 | - $this->_req_data['message_type'], |
|
| 2105 | - $this->_req_data['messenger'], |
|
| 2106 | - $this->_req_data['messenger'], |
|
| 2107 | - $this->_req_data['GRP_ID'] |
|
| 2108 | - ) |
|
| 2109 | - ) { |
|
| 2110 | - EE_Error::add_error( |
|
| 2111 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2112 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | - ); |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2117 | - |
|
| 2118 | - |
|
| 2119 | - //get the preview! |
|
| 2120 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2121 | - $this->_req_data['messenger'], $send); |
|
| 2122 | - |
|
| 2123 | - if ($send) { |
|
| 2124 | - return $preview; |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - //let's add a button to go back to the edit view |
|
| 2128 | - $query_args = array( |
|
| 2129 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2130 | - 'context' => $this->_req_data['context'], |
|
| 2131 | - 'action' => 'edit_message_template' |
|
| 2132 | - ); |
|
| 2133 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2134 | - $preview_button = '<a href="' |
|
| 2135 | - . $go_back_url |
|
| 2136 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2137 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2138 | - . '</a>'; |
|
| 2139 | - $message_types = $this->get_installed_message_types(); |
|
| 2140 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2141 | - $this->_req_data['messenger'] |
|
| 2142 | - ); |
|
| 2143 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2144 | - ? ucwords($active_messenger->label['singular']) |
|
| 2145 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2146 | - //let's provide a helpful title for context |
|
| 2147 | - $preview_title = sprintf( |
|
| 2148 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2149 | - $active_messenger_label, |
|
| 2150 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2151 | - ); |
|
| 2152 | - //setup display of preview. |
|
| 2153 | - $this->_admin_page_title = $preview_title; |
|
| 2154 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2155 | - $this->_template_args['data']['force_json'] = true; |
|
| 2156 | - |
|
| 2157 | - return ''; |
|
| 2158 | - } |
|
| 2088 | + /** |
|
| 2089 | + * Retrieve and set the message preview for display. |
|
| 2090 | + * |
|
| 2091 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2092 | + * @return string |
|
| 2093 | + * @throws ReflectionException |
|
| 2094 | + * @throws EE_Error |
|
| 2095 | + * @throws InvalidArgumentException |
|
| 2096 | + * @throws InvalidDataTypeException |
|
| 2097 | + * @throws InvalidInterfaceException |
|
| 2098 | + */ |
|
| 2099 | + public function _preview_message($send = false) |
|
| 2100 | + { |
|
| 2101 | + //first make sure we've got the necessary parameters |
|
| 2102 | + if ( |
|
| 2103 | + ! isset( |
|
| 2104 | + $this->_req_data['message_type'], |
|
| 2105 | + $this->_req_data['messenger'], |
|
| 2106 | + $this->_req_data['messenger'], |
|
| 2107 | + $this->_req_data['GRP_ID'] |
|
| 2108 | + ) |
|
| 2109 | + ) { |
|
| 2110 | + EE_Error::add_error( |
|
| 2111 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2112 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | + ); |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2117 | + |
|
| 2118 | + |
|
| 2119 | + //get the preview! |
|
| 2120 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2121 | + $this->_req_data['messenger'], $send); |
|
| 2122 | + |
|
| 2123 | + if ($send) { |
|
| 2124 | + return $preview; |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + //let's add a button to go back to the edit view |
|
| 2128 | + $query_args = array( |
|
| 2129 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2130 | + 'context' => $this->_req_data['context'], |
|
| 2131 | + 'action' => 'edit_message_template' |
|
| 2132 | + ); |
|
| 2133 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2134 | + $preview_button = '<a href="' |
|
| 2135 | + . $go_back_url |
|
| 2136 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2137 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2138 | + . '</a>'; |
|
| 2139 | + $message_types = $this->get_installed_message_types(); |
|
| 2140 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2141 | + $this->_req_data['messenger'] |
|
| 2142 | + ); |
|
| 2143 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2144 | + ? ucwords($active_messenger->label['singular']) |
|
| 2145 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2146 | + //let's provide a helpful title for context |
|
| 2147 | + $preview_title = sprintf( |
|
| 2148 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2149 | + $active_messenger_label, |
|
| 2150 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2151 | + ); |
|
| 2152 | + //setup display of preview. |
|
| 2153 | + $this->_admin_page_title = $preview_title; |
|
| 2154 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2155 | + $this->_template_args['data']['force_json'] = true; |
|
| 2156 | + |
|
| 2157 | + return ''; |
|
| 2158 | + } |
|
| 2159 | 2159 | |
| 2160 | 2160 | |
| 2161 | - /** |
|
| 2162 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2163 | - * gets called automatically. |
|
| 2164 | - * |
|
| 2165 | - * @since 4.5.0 |
|
| 2166 | - * |
|
| 2167 | - * @return string |
|
| 2168 | - */ |
|
| 2169 | - protected function _display_preview_message() |
|
| 2170 | - { |
|
| 2171 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2172 | - } |
|
| 2161 | + /** |
|
| 2162 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2163 | + * gets called automatically. |
|
| 2164 | + * |
|
| 2165 | + * @since 4.5.0 |
|
| 2166 | + * |
|
| 2167 | + * @return string |
|
| 2168 | + */ |
|
| 2169 | + protected function _display_preview_message() |
|
| 2170 | + { |
|
| 2171 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2172 | + } |
|
| 2173 | 2173 | |
| 2174 | 2174 | |
| 2175 | - /** |
|
| 2176 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2177 | - * |
|
| 2178 | - * @access protected |
|
| 2179 | - * @return void |
|
| 2180 | - */ |
|
| 2181 | - protected function _register_edit_meta_boxes() |
|
| 2182 | - { |
|
| 2183 | - add_meta_box( |
|
| 2184 | - 'mtp_valid_shortcodes', |
|
| 2185 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2186 | - array($this, 'shortcode_meta_box'), |
|
| 2187 | - $this->_current_screen->id, |
|
| 2188 | - 'side', |
|
| 2189 | - 'default'); |
|
| 2190 | - add_meta_box( |
|
| 2191 | - 'mtp_extra_actions', |
|
| 2192 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2193 | - array($this, 'extra_actions_meta_box'), |
|
| 2194 | - $this->_current_screen->id, |
|
| 2195 | - 'side', |
|
| 2196 | - 'high' |
|
| 2197 | - ); |
|
| 2198 | - add_meta_box( |
|
| 2199 | - 'mtp_templates', |
|
| 2200 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2201 | - array($this, 'template_pack_meta_box'), |
|
| 2202 | - $this->_current_screen->id, |
|
| 2203 | - 'side', |
|
| 2204 | - 'high' |
|
| 2205 | - ); |
|
| 2206 | - } |
|
| 2175 | + /** |
|
| 2176 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2177 | + * |
|
| 2178 | + * @access protected |
|
| 2179 | + * @return void |
|
| 2180 | + */ |
|
| 2181 | + protected function _register_edit_meta_boxes() |
|
| 2182 | + { |
|
| 2183 | + add_meta_box( |
|
| 2184 | + 'mtp_valid_shortcodes', |
|
| 2185 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2186 | + array($this, 'shortcode_meta_box'), |
|
| 2187 | + $this->_current_screen->id, |
|
| 2188 | + 'side', |
|
| 2189 | + 'default'); |
|
| 2190 | + add_meta_box( |
|
| 2191 | + 'mtp_extra_actions', |
|
| 2192 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2193 | + array($this, 'extra_actions_meta_box'), |
|
| 2194 | + $this->_current_screen->id, |
|
| 2195 | + 'side', |
|
| 2196 | + 'high' |
|
| 2197 | + ); |
|
| 2198 | + add_meta_box( |
|
| 2199 | + 'mtp_templates', |
|
| 2200 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2201 | + array($this, 'template_pack_meta_box'), |
|
| 2202 | + $this->_current_screen->id, |
|
| 2203 | + 'side', |
|
| 2204 | + 'high' |
|
| 2205 | + ); |
|
| 2206 | + } |
|
| 2207 | 2207 | |
| 2208 | 2208 | |
| 2209 | - /** |
|
| 2210 | - * metabox content for all template pack and variation selection. |
|
| 2211 | - * |
|
| 2212 | - * @since 4.5.0 |
|
| 2213 | - * @return string |
|
| 2214 | - * @throws DomainException |
|
| 2215 | - * @throws EE_Error |
|
| 2216 | - * @throws InvalidArgumentException |
|
| 2217 | - * @throws ReflectionException |
|
| 2218 | - * @throws InvalidDataTypeException |
|
| 2219 | - * @throws InvalidInterfaceException |
|
| 2220 | - */ |
|
| 2221 | - public function template_pack_meta_box() |
|
| 2222 | - { |
|
| 2223 | - $this->_set_message_template_group(); |
|
| 2224 | - |
|
| 2225 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2226 | - |
|
| 2227 | - $tp_select_values = array(); |
|
| 2228 | - |
|
| 2229 | - foreach ($tp_collection as $tp) { |
|
| 2230 | - //only include template packs that support this messenger and message type! |
|
| 2231 | - $supports = $tp->get_supports(); |
|
| 2232 | - if ( |
|
| 2233 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2234 | - || ! in_array( |
|
| 2235 | - $this->_message_template_group->message_type(), |
|
| 2236 | - $supports[$this->_message_template_group->messenger()], |
|
| 2237 | - true |
|
| 2238 | - ) |
|
| 2239 | - ) { |
|
| 2240 | - //not supported |
|
| 2241 | - continue; |
|
| 2242 | - } |
|
| 2209 | + /** |
|
| 2210 | + * metabox content for all template pack and variation selection. |
|
| 2211 | + * |
|
| 2212 | + * @since 4.5.0 |
|
| 2213 | + * @return string |
|
| 2214 | + * @throws DomainException |
|
| 2215 | + * @throws EE_Error |
|
| 2216 | + * @throws InvalidArgumentException |
|
| 2217 | + * @throws ReflectionException |
|
| 2218 | + * @throws InvalidDataTypeException |
|
| 2219 | + * @throws InvalidInterfaceException |
|
| 2220 | + */ |
|
| 2221 | + public function template_pack_meta_box() |
|
| 2222 | + { |
|
| 2223 | + $this->_set_message_template_group(); |
|
| 2224 | + |
|
| 2225 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2226 | + |
|
| 2227 | + $tp_select_values = array(); |
|
| 2228 | + |
|
| 2229 | + foreach ($tp_collection as $tp) { |
|
| 2230 | + //only include template packs that support this messenger and message type! |
|
| 2231 | + $supports = $tp->get_supports(); |
|
| 2232 | + if ( |
|
| 2233 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2234 | + || ! in_array( |
|
| 2235 | + $this->_message_template_group->message_type(), |
|
| 2236 | + $supports[$this->_message_template_group->messenger()], |
|
| 2237 | + true |
|
| 2238 | + ) |
|
| 2239 | + ) { |
|
| 2240 | + //not supported |
|
| 2241 | + continue; |
|
| 2242 | + } |
|
| 2243 | 2243 | |
| 2244 | - $tp_select_values[] = array( |
|
| 2245 | - 'text' => $tp->label, |
|
| 2246 | - 'id' => $tp->dbref |
|
| 2247 | - ); |
|
| 2248 | - } |
|
| 2249 | - |
|
| 2250 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2251 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2252 | - if (empty($tp_select_values)) { |
|
| 2253 | - $tp_select_values[] = array( |
|
| 2254 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2255 | - 'id' => 'default' |
|
| 2256 | - ); |
|
| 2257 | - } |
|
| 2258 | - |
|
| 2259 | - //setup variation select values for the currently selected template. |
|
| 2260 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2261 | - $this->_message_template_group->messenger(), |
|
| 2262 | - $this->_message_template_group->message_type() |
|
| 2263 | - ); |
|
| 2264 | - $variations_select_values = array(); |
|
| 2265 | - foreach ($variations as $variation => $label) { |
|
| 2266 | - $variations_select_values[] = array( |
|
| 2267 | - 'text' => $label, |
|
| 2268 | - 'id' => $variation |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2273 | - |
|
| 2274 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2275 | - 'MTP_template_pack', |
|
| 2276 | - $tp_select_values, |
|
| 2277 | - $this->_message_template_group->get_template_pack_name() |
|
| 2278 | - ); |
|
| 2279 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | - 'MTP_template_variation', |
|
| 2281 | - $variations_select_values, |
|
| 2282 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2283 | - ); |
|
| 2284 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2285 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2286 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2287 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2288 | - |
|
| 2289 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2290 | - |
|
| 2291 | - EEH_Template::display_template($template, $template_args); |
|
| 2292 | - } |
|
| 2244 | + $tp_select_values[] = array( |
|
| 2245 | + 'text' => $tp->label, |
|
| 2246 | + 'id' => $tp->dbref |
|
| 2247 | + ); |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2251 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2252 | + if (empty($tp_select_values)) { |
|
| 2253 | + $tp_select_values[] = array( |
|
| 2254 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2255 | + 'id' => 'default' |
|
| 2256 | + ); |
|
| 2257 | + } |
|
| 2258 | + |
|
| 2259 | + //setup variation select values for the currently selected template. |
|
| 2260 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2261 | + $this->_message_template_group->messenger(), |
|
| 2262 | + $this->_message_template_group->message_type() |
|
| 2263 | + ); |
|
| 2264 | + $variations_select_values = array(); |
|
| 2265 | + foreach ($variations as $variation => $label) { |
|
| 2266 | + $variations_select_values[] = array( |
|
| 2267 | + 'text' => $label, |
|
| 2268 | + 'id' => $variation |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2273 | + |
|
| 2274 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2275 | + 'MTP_template_pack', |
|
| 2276 | + $tp_select_values, |
|
| 2277 | + $this->_message_template_group->get_template_pack_name() |
|
| 2278 | + ); |
|
| 2279 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2280 | + 'MTP_template_variation', |
|
| 2281 | + $variations_select_values, |
|
| 2282 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2283 | + ); |
|
| 2284 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2285 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2286 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2287 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2288 | + |
|
| 2289 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2290 | + |
|
| 2291 | + EEH_Template::display_template($template, $template_args); |
|
| 2292 | + } |
|
| 2293 | 2293 | |
| 2294 | 2294 | |
| 2295 | - /** |
|
| 2296 | - * This meta box holds any extra actions related to Message Templates |
|
| 2297 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2298 | - * |
|
| 2299 | - * @access public |
|
| 2300 | - * @return void |
|
| 2301 | - * @throws EE_Error |
|
| 2302 | - */ |
|
| 2303 | - public function extra_actions_meta_box() |
|
| 2304 | - { |
|
| 2305 | - $template_form_fields = array(); |
|
| 2306 | - |
|
| 2307 | - $extra_args = array( |
|
| 2308 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2309 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2310 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2311 | - ); |
|
| 2312 | - //first we need to see if there are any fields |
|
| 2313 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2314 | - |
|
| 2315 | - if ( ! empty($fields)) { |
|
| 2316 | - //yup there be fields |
|
| 2317 | - foreach ($fields as $field => $config) { |
|
| 2318 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2319 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2320 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2321 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2295 | + /** |
|
| 2296 | + * This meta box holds any extra actions related to Message Templates |
|
| 2297 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2298 | + * |
|
| 2299 | + * @access public |
|
| 2300 | + * @return void |
|
| 2301 | + * @throws EE_Error |
|
| 2302 | + */ |
|
| 2303 | + public function extra_actions_meta_box() |
|
| 2304 | + { |
|
| 2305 | + $template_form_fields = array(); |
|
| 2306 | + |
|
| 2307 | + $extra_args = array( |
|
| 2308 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2309 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2310 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2311 | + ); |
|
| 2312 | + //first we need to see if there are any fields |
|
| 2313 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2314 | + |
|
| 2315 | + if ( ! empty($fields)) { |
|
| 2316 | + //yup there be fields |
|
| 2317 | + foreach ($fields as $field => $config) { |
|
| 2318 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2319 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2320 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2321 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2322 | 2322 | |
| 2323 | - // if type is hidden and the value is empty |
|
| 2324 | - // something may have gone wrong so let's correct with the defaults |
|
| 2325 | - $fix = $config['input'] === 'hidden' |
|
| 2326 | - && isset($existing[$field]) |
|
| 2327 | - && empty($existing[$field]) |
|
| 2328 | - ? $default |
|
| 2329 | - : ''; |
|
| 2330 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2331 | - ? $existing[$field] |
|
| 2332 | - : $fix; |
|
| 2323 | + // if type is hidden and the value is empty |
|
| 2324 | + // something may have gone wrong so let's correct with the defaults |
|
| 2325 | + $fix = $config['input'] === 'hidden' |
|
| 2326 | + && isset($existing[$field]) |
|
| 2327 | + && empty($existing[$field]) |
|
| 2328 | + ? $default |
|
| 2329 | + : ''; |
|
| 2330 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2331 | + ? $existing[$field] |
|
| 2332 | + : $fix; |
|
| 2333 | 2333 | |
| 2334 | - $template_form_fields[$field_id] = array( |
|
| 2335 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2336 | - 'label' => $config['label'], |
|
| 2337 | - 'input' => $config['input'], |
|
| 2338 | - 'type' => $config['type'], |
|
| 2339 | - 'required' => $config['required'], |
|
| 2340 | - 'validation' => $config['validation'], |
|
| 2341 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2342 | - 'css_class' => $config['css_class'], |
|
| 2343 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2344 | - 'default' => $default, |
|
| 2345 | - 'format' => $config['format'] |
|
| 2346 | - ); |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2351 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2352 | - : ''; |
|
| 2353 | - |
|
| 2354 | - $test_settings_html = ''; |
|
| 2355 | - //print out $test_settings_fields |
|
| 2356 | - if ( ! empty($test_settings_fields)) { |
|
| 2357 | - echo $test_settings_fields; |
|
| 2358 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2359 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2360 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2361 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - //and button |
|
| 2365 | - $test_settings_html .= '<p>' |
|
| 2366 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2367 | - . '</p>'; |
|
| 2368 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2369 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2370 | - 'reset_to_default', |
|
| 2371 | - 'reset', |
|
| 2372 | - $extra_args, |
|
| 2373 | - 'button-primary reset-default-button' |
|
| 2374 | - ); |
|
| 2375 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2376 | - echo $test_settings_html; |
|
| 2377 | - } |
|
| 2334 | + $template_form_fields[$field_id] = array( |
|
| 2335 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2336 | + 'label' => $config['label'], |
|
| 2337 | + 'input' => $config['input'], |
|
| 2338 | + 'type' => $config['type'], |
|
| 2339 | + 'required' => $config['required'], |
|
| 2340 | + 'validation' => $config['validation'], |
|
| 2341 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2342 | + 'css_class' => $config['css_class'], |
|
| 2343 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2344 | + 'default' => $default, |
|
| 2345 | + 'format' => $config['format'] |
|
| 2346 | + ); |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2351 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2352 | + : ''; |
|
| 2353 | + |
|
| 2354 | + $test_settings_html = ''; |
|
| 2355 | + //print out $test_settings_fields |
|
| 2356 | + if ( ! empty($test_settings_fields)) { |
|
| 2357 | + echo $test_settings_fields; |
|
| 2358 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2359 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2360 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2361 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + //and button |
|
| 2365 | + $test_settings_html .= '<p>' |
|
| 2366 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2367 | + . '</p>'; |
|
| 2368 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2369 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2370 | + 'reset_to_default', |
|
| 2371 | + 'reset', |
|
| 2372 | + $extra_args, |
|
| 2373 | + 'button-primary reset-default-button' |
|
| 2374 | + ); |
|
| 2375 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2376 | + echo $test_settings_html; |
|
| 2377 | + } |
|
| 2378 | 2378 | |
| 2379 | 2379 | |
| 2380 | - /** |
|
| 2381 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2382 | - * |
|
| 2383 | - * @since 4.9.rc.000 |
|
| 2384 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2385 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2386 | - * @return string |
|
| 2387 | - * @throws DomainException |
|
| 2388 | - * @throws EE_Error |
|
| 2389 | - * @throws InvalidArgumentException |
|
| 2390 | - * @throws ReflectionException |
|
| 2391 | - * @throws InvalidDataTypeException |
|
| 2392 | - * @throws InvalidInterfaceException |
|
| 2393 | - */ |
|
| 2394 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2395 | - { |
|
| 2396 | - $template_args = array( |
|
| 2397 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2398 | - 'fieldname' => $field, |
|
| 2399 | - 'linked_input_id' => $linked_input_id |
|
| 2400 | - ); |
|
| 2401 | - |
|
| 2402 | - return EEH_Template::display_template( |
|
| 2403 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2404 | - $template_args, |
|
| 2405 | - true |
|
| 2406 | - ); |
|
| 2407 | - } |
|
| 2380 | + /** |
|
| 2381 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2382 | + * |
|
| 2383 | + * @since 4.9.rc.000 |
|
| 2384 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2385 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2386 | + * @return string |
|
| 2387 | + * @throws DomainException |
|
| 2388 | + * @throws EE_Error |
|
| 2389 | + * @throws InvalidArgumentException |
|
| 2390 | + * @throws ReflectionException |
|
| 2391 | + * @throws InvalidDataTypeException |
|
| 2392 | + * @throws InvalidInterfaceException |
|
| 2393 | + */ |
|
| 2394 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2395 | + { |
|
| 2396 | + $template_args = array( |
|
| 2397 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2398 | + 'fieldname' => $field, |
|
| 2399 | + 'linked_input_id' => $linked_input_id |
|
| 2400 | + ); |
|
| 2401 | + |
|
| 2402 | + return EEH_Template::display_template( |
|
| 2403 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2404 | + $template_args, |
|
| 2405 | + true |
|
| 2406 | + ); |
|
| 2407 | + } |
|
| 2408 | 2408 | |
| 2409 | 2409 | |
| 2410 | - /** |
|
| 2411 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2412 | - * page) |
|
| 2413 | - * |
|
| 2414 | - * @access public |
|
| 2415 | - * @return void |
|
| 2416 | - * @throws EE_Error |
|
| 2417 | - * @throws InvalidArgumentException |
|
| 2418 | - * @throws ReflectionException |
|
| 2419 | - * @throws InvalidDataTypeException |
|
| 2420 | - * @throws InvalidInterfaceException |
|
| 2421 | - */ |
|
| 2422 | - public function shortcode_meta_box() |
|
| 2423 | - { |
|
| 2424 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2425 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2426 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2427 | - if (empty($shortcodes)) { |
|
| 2428 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2429 | - echo $content; |
|
| 2430 | - } else { |
|
| 2431 | - //$alt = 0; |
|
| 2432 | - ?> |
|
| 2410 | + /** |
|
| 2411 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2412 | + * page) |
|
| 2413 | + * |
|
| 2414 | + * @access public |
|
| 2415 | + * @return void |
|
| 2416 | + * @throws EE_Error |
|
| 2417 | + * @throws InvalidArgumentException |
|
| 2418 | + * @throws ReflectionException |
|
| 2419 | + * @throws InvalidDataTypeException |
|
| 2420 | + * @throws InvalidInterfaceException |
|
| 2421 | + */ |
|
| 2422 | + public function shortcode_meta_box() |
|
| 2423 | + { |
|
| 2424 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2425 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2426 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2427 | + if (empty($shortcodes)) { |
|
| 2428 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2429 | + echo $content; |
|
| 2430 | + } else { |
|
| 2431 | + //$alt = 0; |
|
| 2432 | + ?> |
|
| 2433 | 2433 | <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2434 | 2434 | <p class="small-text"><?php printf( |
| 2435 | - esc_html__( |
|
| 2436 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2437 | - 'event_espresso' |
|
| 2438 | - ), |
|
| 2439 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2440 | - ); ?></p> |
|
| 2435 | + esc_html__( |
|
| 2436 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2437 | + 'event_espresso' |
|
| 2438 | + ), |
|
| 2439 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2440 | + ); ?></p> |
|
| 2441 | 2441 | <?php |
| 2442 | - } |
|
| 2442 | + } |
|
| 2443 | 2443 | |
| 2444 | 2444 | |
| 2445 | - } |
|
| 2445 | + } |
|
| 2446 | 2446 | |
| 2447 | 2447 | |
| 2448 | - /** |
|
| 2449 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2450 | - * |
|
| 2451 | - * @access protected |
|
| 2452 | - * @return void |
|
| 2453 | - * @throws EE_Error |
|
| 2454 | - * @throws InvalidArgumentException |
|
| 2455 | - * @throws ReflectionException |
|
| 2456 | - * @throws InvalidDataTypeException |
|
| 2457 | - * @throws InvalidInterfaceException |
|
| 2458 | - */ |
|
| 2459 | - protected function _set_shortcodes() |
|
| 2460 | - { |
|
| 2461 | - |
|
| 2462 | - //no need to run this if the property is already set |
|
| 2463 | - if ( ! empty($this->_shortcodes)) { |
|
| 2464 | - return; |
|
| 2465 | - } |
|
| 2466 | - |
|
| 2467 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2468 | - } |
|
| 2448 | + /** |
|
| 2449 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2450 | + * |
|
| 2451 | + * @access protected |
|
| 2452 | + * @return void |
|
| 2453 | + * @throws EE_Error |
|
| 2454 | + * @throws InvalidArgumentException |
|
| 2455 | + * @throws ReflectionException |
|
| 2456 | + * @throws InvalidDataTypeException |
|
| 2457 | + * @throws InvalidInterfaceException |
|
| 2458 | + */ |
|
| 2459 | + protected function _set_shortcodes() |
|
| 2460 | + { |
|
| 2461 | + |
|
| 2462 | + //no need to run this if the property is already set |
|
| 2463 | + if ( ! empty($this->_shortcodes)) { |
|
| 2464 | + return; |
|
| 2465 | + } |
|
| 2466 | + |
|
| 2467 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2468 | + } |
|
| 2469 | 2469 | |
| 2470 | 2470 | |
| 2471 | - /** |
|
| 2472 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2473 | - * property) |
|
| 2474 | - * |
|
| 2475 | - * @access protected |
|
| 2476 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2477 | - * for. Defaults to all (for the given context) |
|
| 2478 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2479 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2480 | - * true just an array of shortcode/label pairs. |
|
| 2481 | - * @throws EE_Error |
|
| 2482 | - * @throws InvalidArgumentException |
|
| 2483 | - * @throws ReflectionException |
|
| 2484 | - * @throws InvalidDataTypeException |
|
| 2485 | - * @throws InvalidInterfaceException |
|
| 2486 | - */ |
|
| 2487 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2488 | - { |
|
| 2489 | - $this->_set_message_template_group(); |
|
| 2490 | - |
|
| 2491 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2492 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2493 | - ? absint($this->_req_data['id']) |
|
| 2494 | - : false; |
|
| 2495 | - $context = isset($this->_req_data['context']) |
|
| 2496 | - ? $this->_req_data['context'] |
|
| 2497 | - : key($this->_message_template_group->contexts_config()); |
|
| 2498 | - |
|
| 2499 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2500 | - } |
|
| 2471 | + /** |
|
| 2472 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2473 | + * property) |
|
| 2474 | + * |
|
| 2475 | + * @access protected |
|
| 2476 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2477 | + * for. Defaults to all (for the given context) |
|
| 2478 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2479 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2480 | + * true just an array of shortcode/label pairs. |
|
| 2481 | + * @throws EE_Error |
|
| 2482 | + * @throws InvalidArgumentException |
|
| 2483 | + * @throws ReflectionException |
|
| 2484 | + * @throws InvalidDataTypeException |
|
| 2485 | + * @throws InvalidInterfaceException |
|
| 2486 | + */ |
|
| 2487 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2488 | + { |
|
| 2489 | + $this->_set_message_template_group(); |
|
| 2490 | + |
|
| 2491 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2492 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2493 | + ? absint($this->_req_data['id']) |
|
| 2494 | + : false; |
|
| 2495 | + $context = isset($this->_req_data['context']) |
|
| 2496 | + ? $this->_req_data['context'] |
|
| 2497 | + : key($this->_message_template_group->contexts_config()); |
|
| 2498 | + |
|
| 2499 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2500 | + } |
|
| 2501 | 2501 | |
| 2502 | 2502 | |
| 2503 | - /** |
|
| 2504 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2505 | - * |
|
| 2506 | - * @access protected |
|
| 2507 | - * @return void |
|
| 2508 | - * @throws EE_Error |
|
| 2509 | - * @throws InvalidArgumentException |
|
| 2510 | - * @throws ReflectionException |
|
| 2511 | - * @throws InvalidDataTypeException |
|
| 2512 | - * @throws InvalidInterfaceException |
|
| 2513 | - */ |
|
| 2514 | - protected function _set_message_template_group() |
|
| 2515 | - { |
|
| 2516 | - |
|
| 2517 | - if ( ! empty($this->_message_template_group)) { |
|
| 2518 | - return; |
|
| 2519 | - } //get out if this is already set. |
|
| 2520 | - |
|
| 2521 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2522 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2523 | - |
|
| 2524 | - //let's get the message templates |
|
| 2525 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2526 | - |
|
| 2527 | - if (empty($GRP_ID)) { |
|
| 2528 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2529 | - } else { |
|
| 2530 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2531 | - } |
|
| 2532 | - |
|
| 2533 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2534 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2535 | - |
|
| 2536 | - } |
|
| 2503 | + /** |
|
| 2504 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2505 | + * |
|
| 2506 | + * @access protected |
|
| 2507 | + * @return void |
|
| 2508 | + * @throws EE_Error |
|
| 2509 | + * @throws InvalidArgumentException |
|
| 2510 | + * @throws ReflectionException |
|
| 2511 | + * @throws InvalidDataTypeException |
|
| 2512 | + * @throws InvalidInterfaceException |
|
| 2513 | + */ |
|
| 2514 | + protected function _set_message_template_group() |
|
| 2515 | + { |
|
| 2516 | + |
|
| 2517 | + if ( ! empty($this->_message_template_group)) { |
|
| 2518 | + return; |
|
| 2519 | + } //get out if this is already set. |
|
| 2520 | + |
|
| 2521 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2522 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2523 | + |
|
| 2524 | + //let's get the message templates |
|
| 2525 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2526 | + |
|
| 2527 | + if (empty($GRP_ID)) { |
|
| 2528 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2529 | + } else { |
|
| 2530 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2534 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2535 | + |
|
| 2536 | + } |
|
| 2537 | 2537 | |
| 2538 | 2538 | |
| 2539 | - /** |
|
| 2540 | - * sets up a context switcher for edit forms |
|
| 2541 | - * |
|
| 2542 | - * @access protected |
|
| 2543 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2544 | - * @param array $args various things the context switcher needs. |
|
| 2545 | - * @throws EE_Error |
|
| 2546 | - */ |
|
| 2547 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2548 | - { |
|
| 2549 | - $context_details = $template_group_object->contexts_config(); |
|
| 2550 | - $context_label = $template_group_object->context_label(); |
|
| 2551 | - ob_start(); |
|
| 2552 | - ?> |
|
| 2539 | + /** |
|
| 2540 | + * sets up a context switcher for edit forms |
|
| 2541 | + * |
|
| 2542 | + * @access protected |
|
| 2543 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2544 | + * @param array $args various things the context switcher needs. |
|
| 2545 | + * @throws EE_Error |
|
| 2546 | + */ |
|
| 2547 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2548 | + { |
|
| 2549 | + $context_details = $template_group_object->contexts_config(); |
|
| 2550 | + $context_label = $template_group_object->context_label(); |
|
| 2551 | + ob_start(); |
|
| 2552 | + ?> |
|
| 2553 | 2553 | <div class="ee-msg-switcher-container"> |
| 2554 | 2554 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2555 | 2555 | <?php |
| 2556 | - foreach ($args as $name => $value) { |
|
| 2557 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2558 | - continue; |
|
| 2559 | - } |
|
| 2560 | - ?> |
|
| 2556 | + foreach ($args as $name => $value) { |
|
| 2557 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2558 | + continue; |
|
| 2559 | + } |
|
| 2560 | + ?> |
|
| 2561 | 2561 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2562 | 2562 | <?php |
| 2563 | - } |
|
| 2564 | - //setup nonce_url |
|
| 2565 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2566 | - ?> |
|
| 2563 | + } |
|
| 2564 | + //setup nonce_url |
|
| 2565 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2566 | + ?> |
|
| 2567 | 2567 | <select name="context"> |
| 2568 | 2568 | <?php |
| 2569 | - $context_templates = $template_group_object->context_templates(); |
|
| 2570 | - if (is_array($context_templates)) : |
|
| 2571 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2572 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2573 | - ?> |
|
| 2569 | + $context_templates = $template_group_object->context_templates(); |
|
| 2570 | + if (is_array($context_templates)) : |
|
| 2571 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2572 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2573 | + ?> |
|
| 2574 | 2574 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2575 | 2575 | <?php echo $context_details[$context]['label']; ?> |
| 2576 | 2576 | </option> |
@@ -2583,1863 +2583,1863 @@ discard block |
||
| 2583 | 2583 | <?php echo $args['extra']; ?> |
| 2584 | 2584 | </div> <!-- end .ee-msg-switcher-container --> |
| 2585 | 2585 | <?php |
| 2586 | - $output = ob_get_contents(); |
|
| 2587 | - ob_clean(); |
|
| 2588 | - $this->_context_switcher = $output; |
|
| 2589 | - } |
|
| 2586 | + $output = ob_get_contents(); |
|
| 2587 | + ob_clean(); |
|
| 2588 | + $this->_context_switcher = $output; |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | 2591 | |
| 2592 | - /** |
|
| 2593 | - * utility for sanitizing new values coming in. |
|
| 2594 | - * Note: this is only used when updating a context. |
|
| 2595 | - * |
|
| 2596 | - * @access protected |
|
| 2597 | - * |
|
| 2598 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2599 | - * |
|
| 2600 | - * @return array |
|
| 2601 | - */ |
|
| 2602 | - protected function _set_message_template_column_values($index) |
|
| 2603 | - { |
|
| 2604 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2605 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2606 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2607 | - } |
|
| 2608 | - } |
|
| 2609 | - |
|
| 2610 | - |
|
| 2611 | - $set_column_values = array( |
|
| 2612 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2613 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2614 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2615 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2616 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2617 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2618 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2619 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2620 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2621 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2622 | - : 0, |
|
| 2623 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2624 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2625 | - : 0, |
|
| 2626 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2627 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2628 | - ); |
|
| 2629 | - |
|
| 2630 | - |
|
| 2631 | - return $set_column_values; |
|
| 2632 | - } |
|
| 2592 | + /** |
|
| 2593 | + * utility for sanitizing new values coming in. |
|
| 2594 | + * Note: this is only used when updating a context. |
|
| 2595 | + * |
|
| 2596 | + * @access protected |
|
| 2597 | + * |
|
| 2598 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2599 | + * |
|
| 2600 | + * @return array |
|
| 2601 | + */ |
|
| 2602 | + protected function _set_message_template_column_values($index) |
|
| 2603 | + { |
|
| 2604 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2605 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2606 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2607 | + } |
|
| 2608 | + } |
|
| 2609 | + |
|
| 2610 | + |
|
| 2611 | + $set_column_values = array( |
|
| 2612 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2613 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2614 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2615 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2616 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2617 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2618 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2619 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2620 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2621 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2622 | + : 0, |
|
| 2623 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2624 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2625 | + : 0, |
|
| 2626 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2627 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2628 | + ); |
|
| 2629 | + |
|
| 2630 | + |
|
| 2631 | + return $set_column_values; |
|
| 2632 | + } |
|
| 2633 | 2633 | |
| 2634 | 2634 | |
| 2635 | - protected function _insert_or_update_message_template($new = false) |
|
| 2636 | - { |
|
| 2637 | - |
|
| 2638 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2639 | - $success = 0; |
|
| 2640 | - $override = false; |
|
| 2641 | - |
|
| 2642 | - //setup notices description |
|
| 2643 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2644 | - |
|
| 2645 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2646 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2647 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2648 | - ? ucwords($messenger_object->label['singular']) |
|
| 2649 | - : ''; |
|
| 2650 | - |
|
| 2651 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2652 | - ? $this->_req_data['MTP_message_type'] |
|
| 2653 | - : ''; |
|
| 2654 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2655 | - |
|
| 2656 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2657 | - ? ucwords($message_type_object->label['singular']) |
|
| 2658 | - : ''; |
|
| 2659 | - |
|
| 2660 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2661 | - ? $this->_req_data['MTP_context'] |
|
| 2662 | - : ''; |
|
| 2663 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2664 | - |
|
| 2665 | - $item_desc = $messenger_label && $message_type_label |
|
| 2666 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2667 | - : ''; |
|
| 2668 | - $item_desc .= 'Message Template'; |
|
| 2669 | - $query_args = array(); |
|
| 2670 | - $edit_array = array(); |
|
| 2671 | - $action_desc = ''; |
|
| 2672 | - |
|
| 2673 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2674 | - // user to edit. |
|
| 2675 | - if ($new) { |
|
| 2676 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2677 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2678 | - if (empty($edit_array)) { |
|
| 2679 | - $success = 0; |
|
| 2680 | - } else { |
|
| 2681 | - $success = 1; |
|
| 2682 | - $edit_array = $edit_array[0]; |
|
| 2683 | - $query_args = array( |
|
| 2684 | - 'id' => $edit_array['GRP_ID'], |
|
| 2685 | - 'context' => $edit_array['MTP_context'], |
|
| 2686 | - 'action' => 'edit_message_template' |
|
| 2687 | - ); |
|
| 2688 | - } |
|
| 2689 | - } |
|
| 2690 | - $action_desc = 'created'; |
|
| 2691 | - } else { |
|
| 2692 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2693 | - $MTP = EEM_Message_Template::instance(); |
|
| 2635 | + protected function _insert_or_update_message_template($new = false) |
|
| 2636 | + { |
|
| 2637 | + |
|
| 2638 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2639 | + $success = 0; |
|
| 2640 | + $override = false; |
|
| 2641 | + |
|
| 2642 | + //setup notices description |
|
| 2643 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2644 | + |
|
| 2645 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2646 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2647 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2648 | + ? ucwords($messenger_object->label['singular']) |
|
| 2649 | + : ''; |
|
| 2650 | + |
|
| 2651 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2652 | + ? $this->_req_data['MTP_message_type'] |
|
| 2653 | + : ''; |
|
| 2654 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2655 | + |
|
| 2656 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2657 | + ? ucwords($message_type_object->label['singular']) |
|
| 2658 | + : ''; |
|
| 2659 | + |
|
| 2660 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2661 | + ? $this->_req_data['MTP_context'] |
|
| 2662 | + : ''; |
|
| 2663 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2664 | + |
|
| 2665 | + $item_desc = $messenger_label && $message_type_label |
|
| 2666 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2667 | + : ''; |
|
| 2668 | + $item_desc .= 'Message Template'; |
|
| 2669 | + $query_args = array(); |
|
| 2670 | + $edit_array = array(); |
|
| 2671 | + $action_desc = ''; |
|
| 2672 | + |
|
| 2673 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2674 | + // user to edit. |
|
| 2675 | + if ($new) { |
|
| 2676 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2677 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2678 | + if (empty($edit_array)) { |
|
| 2679 | + $success = 0; |
|
| 2680 | + } else { |
|
| 2681 | + $success = 1; |
|
| 2682 | + $edit_array = $edit_array[0]; |
|
| 2683 | + $query_args = array( |
|
| 2684 | + 'id' => $edit_array['GRP_ID'], |
|
| 2685 | + 'context' => $edit_array['MTP_context'], |
|
| 2686 | + 'action' => 'edit_message_template' |
|
| 2687 | + ); |
|
| 2688 | + } |
|
| 2689 | + } |
|
| 2690 | + $action_desc = 'created'; |
|
| 2691 | + } else { |
|
| 2692 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2693 | + $MTP = EEM_Message_Template::instance(); |
|
| 2694 | 2694 | |
| 2695 | 2695 | |
| 2696 | - //run update for each template field in displayed context |
|
| 2697 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2698 | - EE_Error::add_error( |
|
| 2699 | - esc_html__( |
|
| 2700 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2701 | - 'event_espresso' |
|
| 2702 | - ), |
|
| 2703 | - __FILE__, |
|
| 2704 | - __FUNCTION__, |
|
| 2705 | - __LINE__ |
|
| 2706 | - ); |
|
| 2707 | - $success = 0; |
|
| 2696 | + //run update for each template field in displayed context |
|
| 2697 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2698 | + EE_Error::add_error( |
|
| 2699 | + esc_html__( |
|
| 2700 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2701 | + 'event_espresso' |
|
| 2702 | + ), |
|
| 2703 | + __FILE__, |
|
| 2704 | + __FUNCTION__, |
|
| 2705 | + __LINE__ |
|
| 2706 | + ); |
|
| 2707 | + $success = 0; |
|
| 2708 | 2708 | |
| 2709 | - } else { |
|
| 2710 | - //first validate all fields! |
|
| 2711 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2712 | - $message_type_slug); |
|
| 2709 | + } else { |
|
| 2710 | + //first validate all fields! |
|
| 2711 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2712 | + $message_type_slug); |
|
| 2713 | 2713 | |
| 2714 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2715 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2716 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2717 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2718 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2719 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2714 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2715 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2716 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2717 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2718 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2719 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2720 | 2720 | |
| 2721 | - $success = 0; |
|
| 2721 | + $success = 0; |
|
| 2722 | 2722 | |
| 2723 | - //setup notices |
|
| 2724 | - foreach ($validates as $field => $error) { |
|
| 2725 | - if (isset($error['msg'])) { |
|
| 2726 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2723 | + //setup notices |
|
| 2724 | + foreach ($validates as $field => $error) { |
|
| 2725 | + if (isset($error['msg'])) { |
|
| 2726 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | 2729 | |
| 2730 | - } else { |
|
| 2731 | - $set_column_values = array(); |
|
| 2732 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2733 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2730 | + } else { |
|
| 2731 | + $set_column_values = array(); |
|
| 2732 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2733 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2734 | 2734 | |
| 2735 | - $where_cols_n_values = array( |
|
| 2736 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2737 | - ); |
|
| 2738 | - //if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2739 | - if (! current_user_can('unfiltered_html')){ |
|
| 2740 | - if (is_array($set_column_values['MTP_content'])){ |
|
| 2741 | - foreach($set_column_values['MTP_content'] as $key => $value) { |
|
| 2742 | - //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2743 | - //only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2744 | - //appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2745 | - //runs we need to re-slash the data. Sheesh. See |
|
| 2746 | - //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2747 | - $set_column_values['MTP_content'][$key] = addslashes( |
|
| 2748 | - wp_kses( |
|
| 2749 | - stripslashes($value), |
|
| 2750 | - wp_kses_allowed_html('post') |
|
| 2751 | - ) |
|
| 2752 | - ); |
|
| 2753 | - } |
|
| 2754 | - } else { |
|
| 2755 | - $set_column_values['MTP_content'] = wp_kses( |
|
| 2756 | - $set_column_values['MTP_content'], |
|
| 2757 | - wp_kses_allowed_html('post') |
|
| 2758 | - ); |
|
| 2759 | - } |
|
| 2760 | - } |
|
| 2761 | - $message_template_fields = array( |
|
| 2762 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2763 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2764 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2765 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2766 | - ); |
|
| 2767 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2768 | - if ($updated === false) { |
|
| 2769 | - EE_Error::add_error( |
|
| 2770 | - sprintf( |
|
| 2771 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2772 | - $template_field |
|
| 2773 | - ), |
|
| 2774 | - __FILE__, |
|
| 2775 | - __FUNCTION__, |
|
| 2776 | - __LINE__ |
|
| 2777 | - ); |
|
| 2778 | - } else { |
|
| 2779 | - $success = 1; |
|
| 2780 | - } |
|
| 2781 | - } else { |
|
| 2782 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2783 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2784 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2785 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2786 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2787 | - //default setup for it. |
|
| 2788 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2789 | - $updated = $MTP->insert($message_template_fields); |
|
| 2790 | - if (! $updated || is_wp_error($updated)) { |
|
| 2791 | - EE_Error::add_error( |
|
| 2792 | - sprintf( |
|
| 2793 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2794 | - $template_field |
|
| 2795 | - ), |
|
| 2796 | - __FILE__, |
|
| 2797 | - __FUNCTION__, |
|
| 2798 | - __LINE__ |
|
| 2799 | - ); |
|
| 2800 | - $success = 0; |
|
| 2801 | - } else { |
|
| 2802 | - $success = 1; |
|
| 2803 | - } |
|
| 2804 | - } |
|
| 2805 | - } |
|
| 2806 | - $action_desc = 'updated'; |
|
| 2807 | - } |
|
| 2735 | + $where_cols_n_values = array( |
|
| 2736 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2737 | + ); |
|
| 2738 | + //if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2739 | + if (! current_user_can('unfiltered_html')){ |
|
| 2740 | + if (is_array($set_column_values['MTP_content'])){ |
|
| 2741 | + foreach($set_column_values['MTP_content'] as $key => $value) { |
|
| 2742 | + //remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2743 | + //only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2744 | + //appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2745 | + //runs we need to re-slash the data. Sheesh. See |
|
| 2746 | + //https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2747 | + $set_column_values['MTP_content'][$key] = addslashes( |
|
| 2748 | + wp_kses( |
|
| 2749 | + stripslashes($value), |
|
| 2750 | + wp_kses_allowed_html('post') |
|
| 2751 | + ) |
|
| 2752 | + ); |
|
| 2753 | + } |
|
| 2754 | + } else { |
|
| 2755 | + $set_column_values['MTP_content'] = wp_kses( |
|
| 2756 | + $set_column_values['MTP_content'], |
|
| 2757 | + wp_kses_allowed_html('post') |
|
| 2758 | + ); |
|
| 2759 | + } |
|
| 2760 | + } |
|
| 2761 | + $message_template_fields = array( |
|
| 2762 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2763 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2764 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2765 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2766 | + ); |
|
| 2767 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2768 | + if ($updated === false) { |
|
| 2769 | + EE_Error::add_error( |
|
| 2770 | + sprintf( |
|
| 2771 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2772 | + $template_field |
|
| 2773 | + ), |
|
| 2774 | + __FILE__, |
|
| 2775 | + __FUNCTION__, |
|
| 2776 | + __LINE__ |
|
| 2777 | + ); |
|
| 2778 | + } else { |
|
| 2779 | + $success = 1; |
|
| 2780 | + } |
|
| 2781 | + } else { |
|
| 2782 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2783 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2784 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2785 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2786 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2787 | + //default setup for it. |
|
| 2788 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2789 | + $updated = $MTP->insert($message_template_fields); |
|
| 2790 | + if (! $updated || is_wp_error($updated)) { |
|
| 2791 | + EE_Error::add_error( |
|
| 2792 | + sprintf( |
|
| 2793 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2794 | + $template_field |
|
| 2795 | + ), |
|
| 2796 | + __FILE__, |
|
| 2797 | + __FUNCTION__, |
|
| 2798 | + __LINE__ |
|
| 2799 | + ); |
|
| 2800 | + $success = 0; |
|
| 2801 | + } else { |
|
| 2802 | + $success = 1; |
|
| 2803 | + } |
|
| 2804 | + } |
|
| 2805 | + } |
|
| 2806 | + $action_desc = 'updated'; |
|
| 2807 | + } |
|
| 2808 | 2808 | |
| 2809 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2810 | - $mtpg_fields = array( |
|
| 2811 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2812 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2813 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2814 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2815 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2816 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2817 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2818 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2819 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2820 | - : '', |
|
| 2821 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2822 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2823 | - : '' |
|
| 2824 | - ); |
|
| 2809 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2810 | + $mtpg_fields = array( |
|
| 2811 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2812 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2813 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2814 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2815 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2816 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2817 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2818 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2819 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2820 | + : '', |
|
| 2821 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2822 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2823 | + : '' |
|
| 2824 | + ); |
|
| 2825 | 2825 | |
| 2826 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2827 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2826 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2827 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2828 | 2828 | |
| 2829 | - if ($updated === false) { |
|
| 2830 | - EE_Error::add_error( |
|
| 2831 | - sprintf( |
|
| 2832 | - esc_html__( |
|
| 2833 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2834 | - 'event_espresso' |
|
| 2835 | - ), |
|
| 2836 | - $set_column_values['GRP_ID'] |
|
| 2837 | - ), |
|
| 2838 | - __FILE__, |
|
| 2839 | - __FUNCTION__, |
|
| 2840 | - __LINE__ |
|
| 2841 | - ); |
|
| 2842 | - } else { |
|
| 2843 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2844 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2845 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2846 | - : 'default'; |
|
| 2829 | + if ($updated === false) { |
|
| 2830 | + EE_Error::add_error( |
|
| 2831 | + sprintf( |
|
| 2832 | + esc_html__( |
|
| 2833 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2834 | + 'event_espresso' |
|
| 2835 | + ), |
|
| 2836 | + $set_column_values['GRP_ID'] |
|
| 2837 | + ), |
|
| 2838 | + __FILE__, |
|
| 2839 | + __FUNCTION__, |
|
| 2840 | + __LINE__ |
|
| 2841 | + ); |
|
| 2842 | + } else { |
|
| 2843 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2844 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2845 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2846 | + : 'default'; |
|
| 2847 | 2847 | |
| 2848 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2849 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2850 | - : 'default'; |
|
| 2848 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2849 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2850 | + : 'default'; |
|
| 2851 | 2851 | |
| 2852 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2853 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2854 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2855 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2856 | - } |
|
| 2857 | - $success = 1; |
|
| 2858 | - } |
|
| 2859 | - } |
|
| 2860 | - } |
|
| 2852 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2853 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2854 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2855 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2856 | + } |
|
| 2857 | + $success = 1; |
|
| 2858 | + } |
|
| 2859 | + } |
|
| 2860 | + } |
|
| 2861 | 2861 | |
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - //we return things differently if doing ajax |
|
| 2865 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2866 | - $this->_template_args['success'] = $success; |
|
| 2867 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2868 | - $this->_template_args['content'] = ''; |
|
| 2869 | - $this->_template_args['data'] = array( |
|
| 2870 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2871 | - 'templateName' => $edit_array['template_name'] |
|
| 2872 | - ); |
|
| 2873 | - if ($success) { |
|
| 2874 | - EE_Error::overwrite_success(); |
|
| 2875 | - EE_Error::add_success( |
|
| 2876 | - esc_html__( |
|
| 2877 | - '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.', |
|
| 2878 | - 'event_espresso' |
|
| 2879 | - ) |
|
| 2880 | - ); |
|
| 2881 | - } |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + //we return things differently if doing ajax |
|
| 2865 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2866 | + $this->_template_args['success'] = $success; |
|
| 2867 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2868 | + $this->_template_args['content'] = ''; |
|
| 2869 | + $this->_template_args['data'] = array( |
|
| 2870 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2871 | + 'templateName' => $edit_array['template_name'] |
|
| 2872 | + ); |
|
| 2873 | + if ($success) { |
|
| 2874 | + EE_Error::overwrite_success(); |
|
| 2875 | + EE_Error::add_success( |
|
| 2876 | + esc_html__( |
|
| 2877 | + '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.', |
|
| 2878 | + 'event_espresso' |
|
| 2879 | + ) |
|
| 2880 | + ); |
|
| 2881 | + } |
|
| 2882 | 2882 | |
| 2883 | - $this->_return_json(); |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - |
|
| 2887 | - //was a test send triggered? |
|
| 2888 | - if (isset($this->_req_data['test_button'])) { |
|
| 2889 | - EE_Error::overwrite_success(); |
|
| 2890 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2891 | - $override = true; |
|
| 2892 | - } |
|
| 2893 | - |
|
| 2894 | - if (empty($query_args)) { |
|
| 2895 | - $query_args = array( |
|
| 2896 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2897 | - 'context' => $context_slug, |
|
| 2898 | - 'action' => 'edit_message_template' |
|
| 2899 | - ); |
|
| 2900 | - } |
|
| 2901 | - |
|
| 2902 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2903 | - } |
|
| 2883 | + $this->_return_json(); |
|
| 2884 | + } |
|
| 2885 | + |
|
| 2886 | + |
|
| 2887 | + //was a test send triggered? |
|
| 2888 | + if (isset($this->_req_data['test_button'])) { |
|
| 2889 | + EE_Error::overwrite_success(); |
|
| 2890 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2891 | + $override = true; |
|
| 2892 | + } |
|
| 2893 | + |
|
| 2894 | + if (empty($query_args)) { |
|
| 2895 | + $query_args = array( |
|
| 2896 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2897 | + 'context' => $context_slug, |
|
| 2898 | + 'action' => 'edit_message_template' |
|
| 2899 | + ); |
|
| 2900 | + } |
|
| 2901 | + |
|
| 2902 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2903 | + } |
|
| 2904 | 2904 | |
| 2905 | 2905 | |
| 2906 | - /** |
|
| 2907 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2908 | - * |
|
| 2909 | - * @param string $context what context being tested |
|
| 2910 | - * @param string $messenger messenger being tested |
|
| 2911 | - * @param string $message_type message type being tested |
|
| 2912 | - * @throws EE_Error |
|
| 2913 | - * @throws InvalidArgumentException |
|
| 2914 | - * @throws InvalidDataTypeException |
|
| 2915 | - * @throws InvalidInterfaceException |
|
| 2916 | - */ |
|
| 2917 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2918 | - { |
|
| 2919 | - //set things up for preview |
|
| 2920 | - $this->_req_data['messenger'] = $messenger; |
|
| 2921 | - $this->_req_data['message_type'] = $message_type; |
|
| 2922 | - $this->_req_data['context'] = $context; |
|
| 2923 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2924 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2925 | - |
|
| 2926 | - //let's save any existing fields that might be required by the messenger |
|
| 2927 | - if ( |
|
| 2928 | - isset($this->_req_data['test_settings_fld']) |
|
| 2929 | - && $active_messenger instanceof EE_messenger |
|
| 2930 | - && apply_filters( |
|
| 2931 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2932 | - true, |
|
| 2933 | - $this->_req_data['test_settings_fld'], |
|
| 2934 | - $active_messenger |
|
| 2935 | - ) |
|
| 2936 | - ) { |
|
| 2937 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2938 | - } |
|
| 2939 | - |
|
| 2940 | - $success = $this->_preview_message(true); |
|
| 2941 | - |
|
| 2942 | - if ($success) { |
|
| 2943 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2944 | - } else { |
|
| 2945 | - EE_Error::add_error( |
|
| 2946 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2947 | - __FILE__, |
|
| 2948 | - __FUNCTION__, |
|
| 2949 | - __LINE__ |
|
| 2950 | - ); |
|
| 2951 | - } |
|
| 2952 | - } |
|
| 2906 | + /** |
|
| 2907 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2908 | + * |
|
| 2909 | + * @param string $context what context being tested |
|
| 2910 | + * @param string $messenger messenger being tested |
|
| 2911 | + * @param string $message_type message type being tested |
|
| 2912 | + * @throws EE_Error |
|
| 2913 | + * @throws InvalidArgumentException |
|
| 2914 | + * @throws InvalidDataTypeException |
|
| 2915 | + * @throws InvalidInterfaceException |
|
| 2916 | + */ |
|
| 2917 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2918 | + { |
|
| 2919 | + //set things up for preview |
|
| 2920 | + $this->_req_data['messenger'] = $messenger; |
|
| 2921 | + $this->_req_data['message_type'] = $message_type; |
|
| 2922 | + $this->_req_data['context'] = $context; |
|
| 2923 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2924 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2925 | + |
|
| 2926 | + //let's save any existing fields that might be required by the messenger |
|
| 2927 | + if ( |
|
| 2928 | + isset($this->_req_data['test_settings_fld']) |
|
| 2929 | + && $active_messenger instanceof EE_messenger |
|
| 2930 | + && apply_filters( |
|
| 2931 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2932 | + true, |
|
| 2933 | + $this->_req_data['test_settings_fld'], |
|
| 2934 | + $active_messenger |
|
| 2935 | + ) |
|
| 2936 | + ) { |
|
| 2937 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2938 | + } |
|
| 2939 | + |
|
| 2940 | + $success = $this->_preview_message(true); |
|
| 2941 | + |
|
| 2942 | + if ($success) { |
|
| 2943 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2944 | + } else { |
|
| 2945 | + EE_Error::add_error( |
|
| 2946 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2947 | + __FILE__, |
|
| 2948 | + __FUNCTION__, |
|
| 2949 | + __LINE__ |
|
| 2950 | + ); |
|
| 2951 | + } |
|
| 2952 | + } |
|
| 2953 | 2953 | |
| 2954 | 2954 | |
| 2955 | - /** |
|
| 2956 | - * _generate_new_templates |
|
| 2957 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2958 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2959 | - * for the event. |
|
| 2960 | - * |
|
| 2961 | - * |
|
| 2962 | - * @param string $messenger the messenger we are generating templates for |
|
| 2963 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2964 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2965 | - * indicate the message_template_group being used as the base. |
|
| 2966 | - * |
|
| 2967 | - * @param bool $global |
|
| 2968 | - * |
|
| 2969 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2970 | - * encountering problems. |
|
| 2971 | - * @throws EE_Error |
|
| 2972 | - */ |
|
| 2973 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2974 | - { |
|
| 2975 | - |
|
| 2976 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2977 | - // just don't generate any templates. |
|
| 2978 | - if (empty($message_types)) { |
|
| 2979 | - return true; |
|
| 2980 | - } |
|
| 2981 | - |
|
| 2982 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2983 | - } |
|
| 2955 | + /** |
|
| 2956 | + * _generate_new_templates |
|
| 2957 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2958 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2959 | + * for the event. |
|
| 2960 | + * |
|
| 2961 | + * |
|
| 2962 | + * @param string $messenger the messenger we are generating templates for |
|
| 2963 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2964 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2965 | + * indicate the message_template_group being used as the base. |
|
| 2966 | + * |
|
| 2967 | + * @param bool $global |
|
| 2968 | + * |
|
| 2969 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2970 | + * encountering problems. |
|
| 2971 | + * @throws EE_Error |
|
| 2972 | + */ |
|
| 2973 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2974 | + { |
|
| 2975 | + |
|
| 2976 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2977 | + // just don't generate any templates. |
|
| 2978 | + if (empty($message_types)) { |
|
| 2979 | + return true; |
|
| 2980 | + } |
|
| 2981 | + |
|
| 2982 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2983 | + } |
|
| 2984 | 2984 | |
| 2985 | 2985 | |
| 2986 | - /** |
|
| 2987 | - * [_trash_or_restore_message_template] |
|
| 2988 | - * |
|
| 2989 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2990 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2991 | - * an individual context (FALSE). |
|
| 2992 | - * @return void |
|
| 2993 | - * @throws EE_Error |
|
| 2994 | - * @throws InvalidArgumentException |
|
| 2995 | - * @throws InvalidDataTypeException |
|
| 2996 | - * @throws InvalidInterfaceException |
|
| 2997 | - */ |
|
| 2998 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2999 | - { |
|
| 3000 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3001 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 3002 | - |
|
| 3003 | - $success = 1; |
|
| 3004 | - |
|
| 3005 | - //incoming GRP_IDs |
|
| 3006 | - if ($all) { |
|
| 3007 | - //Checkboxes |
|
| 3008 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3009 | - //if array has more than one element then success message should be plural. |
|
| 3010 | - //todo: what about nonce? |
|
| 3011 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2986 | + /** |
|
| 2987 | + * [_trash_or_restore_message_template] |
|
| 2988 | + * |
|
| 2989 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2990 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2991 | + * an individual context (FALSE). |
|
| 2992 | + * @return void |
|
| 2993 | + * @throws EE_Error |
|
| 2994 | + * @throws InvalidArgumentException |
|
| 2995 | + * @throws InvalidDataTypeException |
|
| 2996 | + * @throws InvalidInterfaceException |
|
| 2997 | + */ |
|
| 2998 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2999 | + { |
|
| 3000 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3001 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 3002 | + |
|
| 3003 | + $success = 1; |
|
| 3004 | + |
|
| 3005 | + //incoming GRP_IDs |
|
| 3006 | + if ($all) { |
|
| 3007 | + //Checkboxes |
|
| 3008 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3009 | + //if array has more than one element then success message should be plural. |
|
| 3010 | + //todo: what about nonce? |
|
| 3011 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3012 | 3012 | |
| 3013 | - //cycle through checkboxes |
|
| 3014 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3015 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3016 | - if ( ! $trashed_or_restored) { |
|
| 3017 | - $success = 0; |
|
| 3018 | - } |
|
| 3019 | - } |
|
| 3020 | - } else { |
|
| 3021 | - //grab single GRP_ID and handle |
|
| 3022 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3023 | - if ( ! empty($GRP_ID)) { |
|
| 3024 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3025 | - if ( ! $trashed_or_restored) { |
|
| 3026 | - $success = 0; |
|
| 3027 | - } |
|
| 3028 | - } else { |
|
| 3029 | - $success = 0; |
|
| 3030 | - } |
|
| 3031 | - } |
|
| 3013 | + //cycle through checkboxes |
|
| 3014 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3015 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3016 | + if ( ! $trashed_or_restored) { |
|
| 3017 | + $success = 0; |
|
| 3018 | + } |
|
| 3019 | + } |
|
| 3020 | + } else { |
|
| 3021 | + //grab single GRP_ID and handle |
|
| 3022 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3023 | + if ( ! empty($GRP_ID)) { |
|
| 3024 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3025 | + if ( ! $trashed_or_restored) { |
|
| 3026 | + $success = 0; |
|
| 3027 | + } |
|
| 3028 | + } else { |
|
| 3029 | + $success = 0; |
|
| 3030 | + } |
|
| 3031 | + } |
|
| 3032 | 3032 | |
| 3033 | - } |
|
| 3033 | + } |
|
| 3034 | 3034 | |
| 3035 | - $action_desc = $trash |
|
| 3036 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3037 | - : esc_html__('restored', 'event_espresso'); |
|
| 3035 | + $action_desc = $trash |
|
| 3036 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3037 | + : esc_html__('restored', 'event_espresso'); |
|
| 3038 | 3038 | |
| 3039 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3039 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3040 | 3040 | |
| 3041 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3042 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3041 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3042 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3043 | 3043 | |
| 3044 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3045 | - 'event_espresso') : $item_desc; |
|
| 3044 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3045 | + 'event_espresso') : $item_desc; |
|
| 3046 | 3046 | |
| 3047 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3047 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3048 | 3048 | |
| 3049 | - } |
|
| 3049 | + } |
|
| 3050 | 3050 | |
| 3051 | 3051 | |
| 3052 | - /** |
|
| 3053 | - * [_delete_message_template] |
|
| 3054 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3055 | - * |
|
| 3056 | - * @return void |
|
| 3057 | - * @throws EE_Error |
|
| 3058 | - * @throws InvalidArgumentException |
|
| 3059 | - * @throws InvalidDataTypeException |
|
| 3060 | - * @throws InvalidInterfaceException |
|
| 3061 | - */ |
|
| 3062 | - protected function _delete_message_template() |
|
| 3063 | - { |
|
| 3064 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3065 | - |
|
| 3066 | - //checkboxes |
|
| 3067 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3068 | - //if array has more than one element then success message should be plural |
|
| 3069 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3052 | + /** |
|
| 3053 | + * [_delete_message_template] |
|
| 3054 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3055 | + * |
|
| 3056 | + * @return void |
|
| 3057 | + * @throws EE_Error |
|
| 3058 | + * @throws InvalidArgumentException |
|
| 3059 | + * @throws InvalidDataTypeException |
|
| 3060 | + * @throws InvalidInterfaceException |
|
| 3061 | + */ |
|
| 3062 | + protected function _delete_message_template() |
|
| 3063 | + { |
|
| 3064 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3065 | + |
|
| 3066 | + //checkboxes |
|
| 3067 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3068 | + //if array has more than one element then success message should be plural |
|
| 3069 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3070 | 3070 | |
| 3071 | - //cycle through bulk action checkboxes |
|
| 3072 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3073 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3074 | - } |
|
| 3075 | - } else { |
|
| 3076 | - //grab single grp_id and delete |
|
| 3077 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3078 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3079 | - } |
|
| 3080 | - |
|
| 3081 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3082 | - |
|
| 3083 | - } |
|
| 3071 | + //cycle through bulk action checkboxes |
|
| 3072 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3073 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3074 | + } |
|
| 3075 | + } else { |
|
| 3076 | + //grab single grp_id and delete |
|
| 3077 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3078 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3079 | + } |
|
| 3080 | + |
|
| 3081 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3082 | + |
|
| 3083 | + } |
|
| 3084 | 3084 | |
| 3085 | 3085 | |
| 3086 | - /** |
|
| 3087 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3088 | - * |
|
| 3089 | - * @param int $GRP_ID The group being deleted |
|
| 3090 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3091 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3092 | - * @throws EE_Error |
|
| 3093 | - * @throws InvalidArgumentException |
|
| 3094 | - * @throws InvalidDataTypeException |
|
| 3095 | - * @throws InvalidInterfaceException |
|
| 3096 | - */ |
|
| 3097 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3098 | - { |
|
| 3099 | - $success = 1; |
|
| 3100 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3101 | - //first let's GET this group |
|
| 3102 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3103 | - //then delete permanently all the related Message Templates |
|
| 3104 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3105 | - |
|
| 3106 | - if ($deleted === 0) { |
|
| 3107 | - $success = 0; |
|
| 3108 | - } |
|
| 3109 | - |
|
| 3110 | - //now delete permanently this particular group |
|
| 3111 | - |
|
| 3112 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3113 | - $success = 0; |
|
| 3114 | - } |
|
| 3115 | - |
|
| 3116 | - return $success; |
|
| 3117 | - } |
|
| 3086 | + /** |
|
| 3087 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3088 | + * |
|
| 3089 | + * @param int $GRP_ID The group being deleted |
|
| 3090 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3091 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3092 | + * @throws EE_Error |
|
| 3093 | + * @throws InvalidArgumentException |
|
| 3094 | + * @throws InvalidDataTypeException |
|
| 3095 | + * @throws InvalidInterfaceException |
|
| 3096 | + */ |
|
| 3097 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3098 | + { |
|
| 3099 | + $success = 1; |
|
| 3100 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3101 | + //first let's GET this group |
|
| 3102 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3103 | + //then delete permanently all the related Message Templates |
|
| 3104 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3105 | + |
|
| 3106 | + if ($deleted === 0) { |
|
| 3107 | + $success = 0; |
|
| 3108 | + } |
|
| 3109 | + |
|
| 3110 | + //now delete permanently this particular group |
|
| 3111 | + |
|
| 3112 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3113 | + $success = 0; |
|
| 3114 | + } |
|
| 3115 | + |
|
| 3116 | + return $success; |
|
| 3117 | + } |
|
| 3118 | 3118 | |
| 3119 | 3119 | |
| 3120 | - /** |
|
| 3121 | - * _learn_more_about_message_templates_link |
|
| 3122 | - * @access protected |
|
| 3123 | - * @return string |
|
| 3124 | - */ |
|
| 3125 | - protected function _learn_more_about_message_templates_link() |
|
| 3126 | - { |
|
| 3127 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3128 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3129 | - . '</a>'; |
|
| 3130 | - } |
|
| 3120 | + /** |
|
| 3121 | + * _learn_more_about_message_templates_link |
|
| 3122 | + * @access protected |
|
| 3123 | + * @return string |
|
| 3124 | + */ |
|
| 3125 | + protected function _learn_more_about_message_templates_link() |
|
| 3126 | + { |
|
| 3127 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3128 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3129 | + . '</a>'; |
|
| 3130 | + } |
|
| 3131 | 3131 | |
| 3132 | 3132 | |
| 3133 | - /** |
|
| 3134 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3135 | - * ajax and other routes. |
|
| 3136 | - * |
|
| 3137 | - * @return void |
|
| 3138 | - * @throws DomainException |
|
| 3139 | - */ |
|
| 3140 | - protected function _settings() |
|
| 3141 | - { |
|
| 3142 | - |
|
| 3143 | - |
|
| 3144 | - $this->_set_m_mt_settings(); |
|
| 3145 | - |
|
| 3146 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3147 | - ? $this->_req_data['selected_messenger'] |
|
| 3148 | - : 'email'; |
|
| 3149 | - |
|
| 3150 | - //let's setup the messenger tabs |
|
| 3151 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3152 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3153 | - 'messenger_links', |
|
| 3154 | - '|', |
|
| 3155 | - $selected_messenger |
|
| 3156 | - ); |
|
| 3157 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3158 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3159 | - |
|
| 3160 | - $this->display_admin_page_with_sidebar(); |
|
| 3161 | - |
|
| 3162 | - } |
|
| 3133 | + /** |
|
| 3134 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3135 | + * ajax and other routes. |
|
| 3136 | + * |
|
| 3137 | + * @return void |
|
| 3138 | + * @throws DomainException |
|
| 3139 | + */ |
|
| 3140 | + protected function _settings() |
|
| 3141 | + { |
|
| 3142 | + |
|
| 3143 | + |
|
| 3144 | + $this->_set_m_mt_settings(); |
|
| 3145 | + |
|
| 3146 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3147 | + ? $this->_req_data['selected_messenger'] |
|
| 3148 | + : 'email'; |
|
| 3149 | + |
|
| 3150 | + //let's setup the messenger tabs |
|
| 3151 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3152 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3153 | + 'messenger_links', |
|
| 3154 | + '|', |
|
| 3155 | + $selected_messenger |
|
| 3156 | + ); |
|
| 3157 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3158 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3159 | + |
|
| 3160 | + $this->display_admin_page_with_sidebar(); |
|
| 3161 | + |
|
| 3162 | + } |
|
| 3163 | 3163 | |
| 3164 | 3164 | |
| 3165 | - /** |
|
| 3166 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3167 | - * |
|
| 3168 | - * @access protected |
|
| 3169 | - * @return void |
|
| 3170 | - * @throws DomainException |
|
| 3171 | - */ |
|
| 3172 | - protected function _set_m_mt_settings() |
|
| 3173 | - { |
|
| 3174 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 3175 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 3176 | - return; |
|
| 3177 | - } |
|
| 3178 | - |
|
| 3179 | - //get all installed messengers and message_types |
|
| 3180 | - /** @type EE_messenger[] $messengers */ |
|
| 3181 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3182 | - /** @type EE_message_type[] $message_types */ |
|
| 3183 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3184 | - |
|
| 3185 | - |
|
| 3186 | - //assemble the array for the _tab_text_links helper |
|
| 3187 | - |
|
| 3188 | - foreach ($messengers as $messenger) { |
|
| 3189 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3190 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3191 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3192 | - ? 'messenger-active' |
|
| 3193 | - : '', |
|
| 3194 | - 'href' => $messenger->name, |
|
| 3195 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3196 | - 'slug' => $messenger->name, |
|
| 3197 | - 'obj' => $messenger |
|
| 3198 | - ); |
|
| 3165 | + /** |
|
| 3166 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3167 | + * |
|
| 3168 | + * @access protected |
|
| 3169 | + * @return void |
|
| 3170 | + * @throws DomainException |
|
| 3171 | + */ |
|
| 3172 | + protected function _set_m_mt_settings() |
|
| 3173 | + { |
|
| 3174 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 3175 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3176 | + return; |
|
| 3177 | + } |
|
| 3178 | + |
|
| 3179 | + //get all installed messengers and message_types |
|
| 3180 | + /** @type EE_messenger[] $messengers */ |
|
| 3181 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3182 | + /** @type EE_message_type[] $message_types */ |
|
| 3183 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3184 | + |
|
| 3185 | + |
|
| 3186 | + //assemble the array for the _tab_text_links helper |
|
| 3187 | + |
|
| 3188 | + foreach ($messengers as $messenger) { |
|
| 3189 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3190 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3191 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3192 | + ? 'messenger-active' |
|
| 3193 | + : '', |
|
| 3194 | + 'href' => $messenger->name, |
|
| 3195 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3196 | + 'slug' => $messenger->name, |
|
| 3197 | + 'obj' => $messenger |
|
| 3198 | + ); |
|
| 3199 | 3199 | |
| 3200 | 3200 | |
| 3201 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3201 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3202 | 3202 | |
| 3203 | - foreach ($message_types as $message_type) { |
|
| 3204 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3205 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3206 | - if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3207 | - continue; |
|
| 3208 | - } |
|
| 3203 | + foreach ($message_types as $message_type) { |
|
| 3204 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3205 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3206 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3207 | + continue; |
|
| 3208 | + } |
|
| 3209 | 3209 | |
| 3210 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3211 | - $messenger->name, |
|
| 3212 | - $message_type->name |
|
| 3213 | - ) |
|
| 3214 | - ? 'active' |
|
| 3215 | - : 'inactive'; |
|
| 3210 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3211 | + $messenger->name, |
|
| 3212 | + $message_type->name |
|
| 3213 | + ) |
|
| 3214 | + ? 'active' |
|
| 3215 | + : 'inactive'; |
|
| 3216 | 3216 | |
| 3217 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3218 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3219 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3220 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3221 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3222 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3223 | - 'title' => $a_or_i === 'active' |
|
| 3224 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3225 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3226 | - 'content' => $a_or_i === 'active' |
|
| 3227 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3228 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3229 | - 'slug' => $message_type->name, |
|
| 3230 | - 'active' => $a_or_i === 'active', |
|
| 3231 | - 'obj' => $message_type |
|
| 3232 | - ); |
|
| 3233 | - } |
|
| 3234 | - } |
|
| 3235 | - } |
|
| 3217 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3218 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3219 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3220 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3221 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3222 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3223 | + 'title' => $a_or_i === 'active' |
|
| 3224 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3225 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3226 | + 'content' => $a_or_i === 'active' |
|
| 3227 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3228 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3229 | + 'slug' => $message_type->name, |
|
| 3230 | + 'active' => $a_or_i === 'active', |
|
| 3231 | + 'obj' => $message_type |
|
| 3232 | + ); |
|
| 3233 | + } |
|
| 3234 | + } |
|
| 3235 | + } |
|
| 3236 | 3236 | |
| 3237 | 3237 | |
| 3238 | - /** |
|
| 3239 | - * This just prepares the content for the message type settings |
|
| 3240 | - * |
|
| 3241 | - * @param EE_message_type $message_type The message type object |
|
| 3242 | - * @param EE_messenger $messenger The messenger object |
|
| 3243 | - * @param boolean $active Whether the message type is active or not |
|
| 3244 | - * @return string html output for the content |
|
| 3245 | - * @throws DomainException |
|
| 3246 | - */ |
|
| 3247 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3248 | - { |
|
| 3249 | - //get message type fields |
|
| 3250 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3251 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3252 | - |
|
| 3253 | - if ( ! empty($fields) && $active) { |
|
| 3238 | + /** |
|
| 3239 | + * This just prepares the content for the message type settings |
|
| 3240 | + * |
|
| 3241 | + * @param EE_message_type $message_type The message type object |
|
| 3242 | + * @param EE_messenger $messenger The messenger object |
|
| 3243 | + * @param boolean $active Whether the message type is active or not |
|
| 3244 | + * @return string html output for the content |
|
| 3245 | + * @throws DomainException |
|
| 3246 | + */ |
|
| 3247 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3248 | + { |
|
| 3249 | + //get message type fields |
|
| 3250 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3251 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3252 | + |
|
| 3253 | + if ( ! empty($fields) && $active) { |
|
| 3254 | 3254 | |
| 3255 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3255 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3256 | 3256 | |
| 3257 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3258 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3259 | - $template_form_field[$field_id] = array( |
|
| 3260 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3261 | - 'label' => $fldprops['label'], |
|
| 3262 | - 'input' => $fldprops['field_type'], |
|
| 3263 | - 'type' => $fldprops['value_type'], |
|
| 3264 | - 'required' => $fldprops['required'], |
|
| 3265 | - 'validation' => $fldprops['validation'], |
|
| 3266 | - 'value' => isset($existing_settings[$fldname]) |
|
| 3267 | - ? $existing_settings[$fldname] |
|
| 3268 | - : $fldprops['default'], |
|
| 3269 | - 'options' => isset($fldprops['options']) |
|
| 3270 | - ? $fldprops['options'] |
|
| 3271 | - : array(), |
|
| 3272 | - 'default' => isset($existing_settings[$fldname]) |
|
| 3273 | - ? $existing_settings[$fldname] |
|
| 3274 | - : $fldprops['default'], |
|
| 3275 | - 'css_class' => 'no-drag', |
|
| 3276 | - 'format' => $fldprops['format'] |
|
| 3277 | - ); |
|
| 3278 | - } |
|
| 3257 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3258 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3259 | + $template_form_field[$field_id] = array( |
|
| 3260 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3261 | + 'label' => $fldprops['label'], |
|
| 3262 | + 'input' => $fldprops['field_type'], |
|
| 3263 | + 'type' => $fldprops['value_type'], |
|
| 3264 | + 'required' => $fldprops['required'], |
|
| 3265 | + 'validation' => $fldprops['validation'], |
|
| 3266 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3267 | + ? $existing_settings[$fldname] |
|
| 3268 | + : $fldprops['default'], |
|
| 3269 | + 'options' => isset($fldprops['options']) |
|
| 3270 | + ? $fldprops['options'] |
|
| 3271 | + : array(), |
|
| 3272 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3273 | + ? $existing_settings[$fldname] |
|
| 3274 | + : $fldprops['default'], |
|
| 3275 | + 'css_class' => 'no-drag', |
|
| 3276 | + 'format' => $fldprops['format'] |
|
| 3277 | + ); |
|
| 3278 | + } |
|
| 3279 | 3279 | |
| 3280 | 3280 | |
| 3281 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3282 | - ? $this->_generate_admin_form_fields( |
|
| 3283 | - $template_form_field, |
|
| 3284 | - 'string', |
|
| 3285 | - 'ee_mt_activate_form' |
|
| 3286 | - ) |
|
| 3287 | - : ''; |
|
| 3288 | - } |
|
| 3289 | - |
|
| 3290 | - $settings_template_args['description'] = $message_type->description; |
|
| 3291 | - //we also need some hidden fields |
|
| 3292 | - $settings_template_args['hidden_fields'] = array( |
|
| 3293 | - 'message_type_settings[messenger]' => array( |
|
| 3294 | - 'type' => 'hidden', |
|
| 3295 | - 'value' => $messenger->name |
|
| 3296 | - ), |
|
| 3297 | - 'message_type_settings[message_type]' => array( |
|
| 3298 | - 'type' => 'hidden', |
|
| 3299 | - 'value' => $message_type->name |
|
| 3300 | - ), |
|
| 3301 | - 'type' => array( |
|
| 3302 | - 'type' => 'hidden', |
|
| 3303 | - 'value' => 'message_type' |
|
| 3304 | - ) |
|
| 3305 | - ); |
|
| 3306 | - |
|
| 3307 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3308 | - $settings_template_args['hidden_fields'], |
|
| 3309 | - 'array' |
|
| 3310 | - ); |
|
| 3311 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3312 | - ? ' hidden' |
|
| 3313 | - : ''; |
|
| 3314 | - |
|
| 3315 | - |
|
| 3316 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3317 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3318 | - |
|
| 3319 | - return $content; |
|
| 3320 | - } |
|
| 3281 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3282 | + ? $this->_generate_admin_form_fields( |
|
| 3283 | + $template_form_field, |
|
| 3284 | + 'string', |
|
| 3285 | + 'ee_mt_activate_form' |
|
| 3286 | + ) |
|
| 3287 | + : ''; |
|
| 3288 | + } |
|
| 3289 | + |
|
| 3290 | + $settings_template_args['description'] = $message_type->description; |
|
| 3291 | + //we also need some hidden fields |
|
| 3292 | + $settings_template_args['hidden_fields'] = array( |
|
| 3293 | + 'message_type_settings[messenger]' => array( |
|
| 3294 | + 'type' => 'hidden', |
|
| 3295 | + 'value' => $messenger->name |
|
| 3296 | + ), |
|
| 3297 | + 'message_type_settings[message_type]' => array( |
|
| 3298 | + 'type' => 'hidden', |
|
| 3299 | + 'value' => $message_type->name |
|
| 3300 | + ), |
|
| 3301 | + 'type' => array( |
|
| 3302 | + 'type' => 'hidden', |
|
| 3303 | + 'value' => 'message_type' |
|
| 3304 | + ) |
|
| 3305 | + ); |
|
| 3306 | + |
|
| 3307 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3308 | + $settings_template_args['hidden_fields'], |
|
| 3309 | + 'array' |
|
| 3310 | + ); |
|
| 3311 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3312 | + ? ' hidden' |
|
| 3313 | + : ''; |
|
| 3314 | + |
|
| 3315 | + |
|
| 3316 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3317 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3318 | + |
|
| 3319 | + return $content; |
|
| 3320 | + } |
|
| 3321 | 3321 | |
| 3322 | 3322 | |
| 3323 | - /** |
|
| 3324 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3325 | - * |
|
| 3326 | - * @access protected |
|
| 3327 | - * @return void |
|
| 3328 | - * @throws DomainException |
|
| 3329 | - */ |
|
| 3330 | - protected function _messages_settings_metaboxes() |
|
| 3331 | - { |
|
| 3332 | - $this->_set_m_mt_settings(); |
|
| 3333 | - $m_boxes = $mt_boxes = array(); |
|
| 3334 | - $m_template_args = $mt_template_args = array(); |
|
| 3335 | - |
|
| 3336 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3337 | - ? $this->_req_data['selected_messenger'] |
|
| 3338 | - : 'email'; |
|
| 3339 | - |
|
| 3340 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3341 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3342 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3343 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3344 | - //messenger meta boxes |
|
| 3345 | - $active = $selected_messenger === $messenger; |
|
| 3346 | - $active_mt_tabs = isset( |
|
| 3347 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3348 | - ) |
|
| 3349 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3350 | - : ''; |
|
| 3351 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3352 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3353 | - $tab_array['label'] |
|
| 3354 | - ); |
|
| 3355 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3356 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3357 | - 'inactive_message_types' => isset( |
|
| 3358 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3359 | - ) |
|
| 3360 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3361 | - : '', |
|
| 3362 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3363 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3364 | - 'hide_on_message' => $hide_on_message, |
|
| 3365 | - 'messenger' => $messenger, |
|
| 3366 | - 'active' => $active |
|
| 3367 | - ); |
|
| 3368 | - // message type meta boxes |
|
| 3369 | - // (which is really just the inactive container for each messenger |
|
| 3370 | - // showing inactive message types for that messenger) |
|
| 3371 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3372 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3373 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3374 | - 'inactive_message_types' => isset( |
|
| 3375 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3376 | - ) |
|
| 3377 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3378 | - : '', |
|
| 3379 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3380 | - 'hide_on_message' => $hide_on_message, |
|
| 3381 | - 'hide_off_message' => $hide_off_message, |
|
| 3382 | - 'messenger' => $messenger, |
|
| 3383 | - 'active' => $active |
|
| 3384 | - ); |
|
| 3385 | - } |
|
| 3386 | - } |
|
| 3387 | - |
|
| 3388 | - |
|
| 3389 | - //register messenger metaboxes |
|
| 3390 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3391 | - foreach ($m_boxes as $box => $label) { |
|
| 3392 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3393 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3394 | - add_meta_box( |
|
| 3395 | - 'espresso_' . $msgr . '_settings', |
|
| 3396 | - $label, |
|
| 3397 | - function ($post, $metabox) { |
|
| 3398 | - echo EEH_Template::display_template( |
|
| 3399 | - $metabox["args"]["template_path"], |
|
| 3400 | - $metabox["args"]["template_args"], |
|
| 3401 | - true |
|
| 3402 | - ); |
|
| 3403 | - }, |
|
| 3404 | - $this->_current_screen->id, |
|
| 3405 | - 'normal', |
|
| 3406 | - 'high', |
|
| 3407 | - $callback_args |
|
| 3408 | - ); |
|
| 3409 | - } |
|
| 3410 | - |
|
| 3411 | - //register message type metaboxes |
|
| 3412 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3413 | - foreach ($mt_boxes as $box => $label) { |
|
| 3414 | - $callback_args = array( |
|
| 3415 | - 'template_path' => $mt_template_path, |
|
| 3416 | - 'template_args' => $mt_template_args[$box] |
|
| 3417 | - ); |
|
| 3418 | - $mt = str_replace('_i_box', '', $box); |
|
| 3419 | - add_meta_box( |
|
| 3420 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3421 | - $label, |
|
| 3422 | - function ($post, $metabox) { |
|
| 3423 | - echo EEH_Template::display_template( |
|
| 3424 | - $metabox["args"]["template_path"], |
|
| 3425 | - $metabox["args"]["template_args"], |
|
| 3426 | - true |
|
| 3427 | - ); |
|
| 3428 | - }, |
|
| 3429 | - $this->_current_screen->id, |
|
| 3430 | - 'side', |
|
| 3431 | - 'high', |
|
| 3432 | - $callback_args |
|
| 3433 | - ); |
|
| 3434 | - } |
|
| 3435 | - |
|
| 3436 | - //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3437 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3438 | - if (is_main_site()) { |
|
| 3439 | - add_meta_box( |
|
| 3440 | - 'espresso_global_message_settings', |
|
| 3441 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3442 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3443 | - $this->_current_screen->id, |
|
| 3444 | - 'normal', |
|
| 3445 | - 'low', |
|
| 3446 | - array() |
|
| 3447 | - ); |
|
| 3448 | - } |
|
| 3449 | - |
|
| 3450 | - } |
|
| 3323 | + /** |
|
| 3324 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3325 | + * |
|
| 3326 | + * @access protected |
|
| 3327 | + * @return void |
|
| 3328 | + * @throws DomainException |
|
| 3329 | + */ |
|
| 3330 | + protected function _messages_settings_metaboxes() |
|
| 3331 | + { |
|
| 3332 | + $this->_set_m_mt_settings(); |
|
| 3333 | + $m_boxes = $mt_boxes = array(); |
|
| 3334 | + $m_template_args = $mt_template_args = array(); |
|
| 3335 | + |
|
| 3336 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3337 | + ? $this->_req_data['selected_messenger'] |
|
| 3338 | + : 'email'; |
|
| 3339 | + |
|
| 3340 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3341 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3342 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3343 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3344 | + //messenger meta boxes |
|
| 3345 | + $active = $selected_messenger === $messenger; |
|
| 3346 | + $active_mt_tabs = isset( |
|
| 3347 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3348 | + ) |
|
| 3349 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3350 | + : ''; |
|
| 3351 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3352 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3353 | + $tab_array['label'] |
|
| 3354 | + ); |
|
| 3355 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 3356 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3357 | + 'inactive_message_types' => isset( |
|
| 3358 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3359 | + ) |
|
| 3360 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3361 | + : '', |
|
| 3362 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3363 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3364 | + 'hide_on_message' => $hide_on_message, |
|
| 3365 | + 'messenger' => $messenger, |
|
| 3366 | + 'active' => $active |
|
| 3367 | + ); |
|
| 3368 | + // message type meta boxes |
|
| 3369 | + // (which is really just the inactive container for each messenger |
|
| 3370 | + // showing inactive message types for that messenger) |
|
| 3371 | + $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3372 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3373 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3374 | + 'inactive_message_types' => isset( |
|
| 3375 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3376 | + ) |
|
| 3377 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3378 | + : '', |
|
| 3379 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3380 | + 'hide_on_message' => $hide_on_message, |
|
| 3381 | + 'hide_off_message' => $hide_off_message, |
|
| 3382 | + 'messenger' => $messenger, |
|
| 3383 | + 'active' => $active |
|
| 3384 | + ); |
|
| 3385 | + } |
|
| 3386 | + } |
|
| 3387 | + |
|
| 3388 | + |
|
| 3389 | + //register messenger metaboxes |
|
| 3390 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3391 | + foreach ($m_boxes as $box => $label) { |
|
| 3392 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3393 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3394 | + add_meta_box( |
|
| 3395 | + 'espresso_' . $msgr . '_settings', |
|
| 3396 | + $label, |
|
| 3397 | + function ($post, $metabox) { |
|
| 3398 | + echo EEH_Template::display_template( |
|
| 3399 | + $metabox["args"]["template_path"], |
|
| 3400 | + $metabox["args"]["template_args"], |
|
| 3401 | + true |
|
| 3402 | + ); |
|
| 3403 | + }, |
|
| 3404 | + $this->_current_screen->id, |
|
| 3405 | + 'normal', |
|
| 3406 | + 'high', |
|
| 3407 | + $callback_args |
|
| 3408 | + ); |
|
| 3409 | + } |
|
| 3410 | + |
|
| 3411 | + //register message type metaboxes |
|
| 3412 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3413 | + foreach ($mt_boxes as $box => $label) { |
|
| 3414 | + $callback_args = array( |
|
| 3415 | + 'template_path' => $mt_template_path, |
|
| 3416 | + 'template_args' => $mt_template_args[$box] |
|
| 3417 | + ); |
|
| 3418 | + $mt = str_replace('_i_box', '', $box); |
|
| 3419 | + add_meta_box( |
|
| 3420 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3421 | + $label, |
|
| 3422 | + function ($post, $metabox) { |
|
| 3423 | + echo EEH_Template::display_template( |
|
| 3424 | + $metabox["args"]["template_path"], |
|
| 3425 | + $metabox["args"]["template_args"], |
|
| 3426 | + true |
|
| 3427 | + ); |
|
| 3428 | + }, |
|
| 3429 | + $this->_current_screen->id, |
|
| 3430 | + 'side', |
|
| 3431 | + 'high', |
|
| 3432 | + $callback_args |
|
| 3433 | + ); |
|
| 3434 | + } |
|
| 3435 | + |
|
| 3436 | + //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3437 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3438 | + if (is_main_site()) { |
|
| 3439 | + add_meta_box( |
|
| 3440 | + 'espresso_global_message_settings', |
|
| 3441 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3442 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3443 | + $this->_current_screen->id, |
|
| 3444 | + 'normal', |
|
| 3445 | + 'low', |
|
| 3446 | + array() |
|
| 3447 | + ); |
|
| 3448 | + } |
|
| 3449 | + |
|
| 3450 | + } |
|
| 3451 | 3451 | |
| 3452 | 3452 | |
| 3453 | - /** |
|
| 3454 | - * This generates the content for the global messages settings metabox. |
|
| 3455 | - * |
|
| 3456 | - * @return string |
|
| 3457 | - * @throws EE_Error |
|
| 3458 | - * @throws InvalidArgumentException |
|
| 3459 | - * @throws ReflectionException |
|
| 3460 | - * @throws InvalidDataTypeException |
|
| 3461 | - * @throws InvalidInterfaceException |
|
| 3462 | - */ |
|
| 3463 | - public function global_messages_settings_metabox_content() |
|
| 3464 | - { |
|
| 3465 | - $form = $this->_generate_global_settings_form(); |
|
| 3466 | - echo $form->form_open( |
|
| 3467 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3468 | - 'POST' |
|
| 3469 | - ) |
|
| 3470 | - . $form->get_html() |
|
| 3471 | - . $form->form_close(); |
|
| 3472 | - } |
|
| 3453 | + /** |
|
| 3454 | + * This generates the content for the global messages settings metabox. |
|
| 3455 | + * |
|
| 3456 | + * @return string |
|
| 3457 | + * @throws EE_Error |
|
| 3458 | + * @throws InvalidArgumentException |
|
| 3459 | + * @throws ReflectionException |
|
| 3460 | + * @throws InvalidDataTypeException |
|
| 3461 | + * @throws InvalidInterfaceException |
|
| 3462 | + */ |
|
| 3463 | + public function global_messages_settings_metabox_content() |
|
| 3464 | + { |
|
| 3465 | + $form = $this->_generate_global_settings_form(); |
|
| 3466 | + echo $form->form_open( |
|
| 3467 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3468 | + 'POST' |
|
| 3469 | + ) |
|
| 3470 | + . $form->get_html() |
|
| 3471 | + . $form->form_close(); |
|
| 3472 | + } |
|
| 3473 | 3473 | |
| 3474 | 3474 | |
| 3475 | - /** |
|
| 3476 | - * This generates and returns the form object for the global messages settings. |
|
| 3477 | - * |
|
| 3478 | - * @return EE_Form_Section_Proper |
|
| 3479 | - * @throws EE_Error |
|
| 3480 | - * @throws InvalidArgumentException |
|
| 3481 | - * @throws ReflectionException |
|
| 3482 | - * @throws InvalidDataTypeException |
|
| 3483 | - * @throws InvalidInterfaceException |
|
| 3484 | - */ |
|
| 3485 | - protected function _generate_global_settings_form() |
|
| 3486 | - { |
|
| 3487 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3488 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3489 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3490 | - |
|
| 3491 | - return new EE_Form_Section_Proper( |
|
| 3492 | - array( |
|
| 3493 | - 'name' => 'global_messages_settings', |
|
| 3494 | - 'html_id' => 'global_messages_settings', |
|
| 3495 | - 'html_class' => 'form-table', |
|
| 3496 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3497 | - 'subsections' => apply_filters( |
|
| 3498 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3499 | - array( |
|
| 3500 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3501 | - array( |
|
| 3502 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3503 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3504 | - ), |
|
| 3505 | - array( |
|
| 3506 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3507 | - 'html_label_text' => esc_html__( |
|
| 3508 | - 'Generate and send all messages:', |
|
| 3509 | - 'event_espresso' |
|
| 3510 | - ), |
|
| 3511 | - 'html_help_text' => esc_html__( |
|
| 3512 | - '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.', |
|
| 3513 | - 'event_espresso' |
|
| 3514 | - ), |
|
| 3515 | - ) |
|
| 3516 | - ), |
|
| 3517 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3518 | - array( |
|
| 3519 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3520 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3521 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3522 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3523 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3524 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3525 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3526 | - ), |
|
| 3527 | - array( |
|
| 3528 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3529 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3530 | - 'html_help_text' => esc_html__( |
|
| 3531 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3532 | - 'event_espresso' |
|
| 3533 | - ), |
|
| 3534 | - ) |
|
| 3535 | - ), |
|
| 3536 | - 'update_settings' => new EE_Submit_Input( |
|
| 3537 | - array( |
|
| 3538 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3539 | - 'html_label_text' => ' ' |
|
| 3540 | - ) |
|
| 3541 | - ) |
|
| 3542 | - ) |
|
| 3543 | - ) |
|
| 3544 | - ) |
|
| 3545 | - ); |
|
| 3546 | - } |
|
| 3475 | + /** |
|
| 3476 | + * This generates and returns the form object for the global messages settings. |
|
| 3477 | + * |
|
| 3478 | + * @return EE_Form_Section_Proper |
|
| 3479 | + * @throws EE_Error |
|
| 3480 | + * @throws InvalidArgumentException |
|
| 3481 | + * @throws ReflectionException |
|
| 3482 | + * @throws InvalidDataTypeException |
|
| 3483 | + * @throws InvalidInterfaceException |
|
| 3484 | + */ |
|
| 3485 | + protected function _generate_global_settings_form() |
|
| 3486 | + { |
|
| 3487 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3488 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3489 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3490 | + |
|
| 3491 | + return new EE_Form_Section_Proper( |
|
| 3492 | + array( |
|
| 3493 | + 'name' => 'global_messages_settings', |
|
| 3494 | + 'html_id' => 'global_messages_settings', |
|
| 3495 | + 'html_class' => 'form-table', |
|
| 3496 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3497 | + 'subsections' => apply_filters( |
|
| 3498 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3499 | + array( |
|
| 3500 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3501 | + array( |
|
| 3502 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3503 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3504 | + ), |
|
| 3505 | + array( |
|
| 3506 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3507 | + 'html_label_text' => esc_html__( |
|
| 3508 | + 'Generate and send all messages:', |
|
| 3509 | + 'event_espresso' |
|
| 3510 | + ), |
|
| 3511 | + 'html_help_text' => esc_html__( |
|
| 3512 | + '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.', |
|
| 3513 | + 'event_espresso' |
|
| 3514 | + ), |
|
| 3515 | + ) |
|
| 3516 | + ), |
|
| 3517 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3518 | + array( |
|
| 3519 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3520 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3521 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3522 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3523 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3524 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3525 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3526 | + ), |
|
| 3527 | + array( |
|
| 3528 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3529 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3530 | + 'html_help_text' => esc_html__( |
|
| 3531 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3532 | + 'event_espresso' |
|
| 3533 | + ), |
|
| 3534 | + ) |
|
| 3535 | + ), |
|
| 3536 | + 'update_settings' => new EE_Submit_Input( |
|
| 3537 | + array( |
|
| 3538 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3539 | + 'html_label_text' => ' ' |
|
| 3540 | + ) |
|
| 3541 | + ) |
|
| 3542 | + ) |
|
| 3543 | + ) |
|
| 3544 | + ) |
|
| 3545 | + ); |
|
| 3546 | + } |
|
| 3547 | 3547 | |
| 3548 | 3548 | |
| 3549 | - /** |
|
| 3550 | - * This handles updating the global settings set on the admin page. |
|
| 3551 | - * |
|
| 3552 | - * @throws EE_Error |
|
| 3553 | - * @throws InvalidDataTypeException |
|
| 3554 | - * @throws InvalidInterfaceException |
|
| 3555 | - * @throws InvalidArgumentException |
|
| 3556 | - * @throws ReflectionException |
|
| 3557 | - */ |
|
| 3558 | - protected function _update_global_settings() |
|
| 3559 | - { |
|
| 3560 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3561 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3562 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3563 | - $form = $this->_generate_global_settings_form(); |
|
| 3564 | - if ($form->was_submitted()) { |
|
| 3565 | - $form->receive_form_submission(); |
|
| 3566 | - if ($form->is_valid()) { |
|
| 3567 | - $valid_data = $form->valid_data(); |
|
| 3568 | - foreach ($valid_data as $property => $value) { |
|
| 3569 | - $setter = 'set_' . $property; |
|
| 3570 | - if (method_exists($network_config, $setter)) { |
|
| 3571 | - $network_config->{$setter}($value); |
|
| 3572 | - } else if ( |
|
| 3573 | - property_exists($network_config, $property) |
|
| 3574 | - && $network_config->{$property} !== $value |
|
| 3575 | - ) { |
|
| 3576 | - $network_config->{$property} = $value; |
|
| 3577 | - } else if ( |
|
| 3578 | - property_exists($messages_config, $property) |
|
| 3579 | - && $messages_config->{$property} !== $value |
|
| 3580 | - ) { |
|
| 3581 | - $messages_config->{$property} = $value; |
|
| 3582 | - } |
|
| 3583 | - } |
|
| 3584 | - //only update if the form submission was valid! |
|
| 3585 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3586 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3587 | - EE_Error::overwrite_success(); |
|
| 3588 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3589 | - } |
|
| 3590 | - } |
|
| 3591 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3592 | - } |
|
| 3549 | + /** |
|
| 3550 | + * This handles updating the global settings set on the admin page. |
|
| 3551 | + * |
|
| 3552 | + * @throws EE_Error |
|
| 3553 | + * @throws InvalidDataTypeException |
|
| 3554 | + * @throws InvalidInterfaceException |
|
| 3555 | + * @throws InvalidArgumentException |
|
| 3556 | + * @throws ReflectionException |
|
| 3557 | + */ |
|
| 3558 | + protected function _update_global_settings() |
|
| 3559 | + { |
|
| 3560 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3561 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3562 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3563 | + $form = $this->_generate_global_settings_form(); |
|
| 3564 | + if ($form->was_submitted()) { |
|
| 3565 | + $form->receive_form_submission(); |
|
| 3566 | + if ($form->is_valid()) { |
|
| 3567 | + $valid_data = $form->valid_data(); |
|
| 3568 | + foreach ($valid_data as $property => $value) { |
|
| 3569 | + $setter = 'set_' . $property; |
|
| 3570 | + if (method_exists($network_config, $setter)) { |
|
| 3571 | + $network_config->{$setter}($value); |
|
| 3572 | + } else if ( |
|
| 3573 | + property_exists($network_config, $property) |
|
| 3574 | + && $network_config->{$property} !== $value |
|
| 3575 | + ) { |
|
| 3576 | + $network_config->{$property} = $value; |
|
| 3577 | + } else if ( |
|
| 3578 | + property_exists($messages_config, $property) |
|
| 3579 | + && $messages_config->{$property} !== $value |
|
| 3580 | + ) { |
|
| 3581 | + $messages_config->{$property} = $value; |
|
| 3582 | + } |
|
| 3583 | + } |
|
| 3584 | + //only update if the form submission was valid! |
|
| 3585 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3586 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3587 | + EE_Error::overwrite_success(); |
|
| 3588 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3589 | + } |
|
| 3590 | + } |
|
| 3591 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3592 | + } |
|
| 3593 | 3593 | |
| 3594 | 3594 | |
| 3595 | - /** |
|
| 3596 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3597 | - * |
|
| 3598 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3599 | - * @return string html formatted tabs |
|
| 3600 | - * @throws DomainException |
|
| 3601 | - */ |
|
| 3602 | - protected function _get_mt_tabs($tab_array) |
|
| 3603 | - { |
|
| 3604 | - $tab_array = (array)$tab_array; |
|
| 3605 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3606 | - $tabs = ''; |
|
| 3607 | - |
|
| 3608 | - foreach ($tab_array as $tab) { |
|
| 3609 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3610 | - } |
|
| 3611 | - |
|
| 3612 | - return $tabs; |
|
| 3613 | - } |
|
| 3595 | + /** |
|
| 3596 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3597 | + * |
|
| 3598 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3599 | + * @return string html formatted tabs |
|
| 3600 | + * @throws DomainException |
|
| 3601 | + */ |
|
| 3602 | + protected function _get_mt_tabs($tab_array) |
|
| 3603 | + { |
|
| 3604 | + $tab_array = (array)$tab_array; |
|
| 3605 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3606 | + $tabs = ''; |
|
| 3607 | + |
|
| 3608 | + foreach ($tab_array as $tab) { |
|
| 3609 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3610 | + } |
|
| 3611 | + |
|
| 3612 | + return $tabs; |
|
| 3613 | + } |
|
| 3614 | 3614 | |
| 3615 | 3615 | |
| 3616 | - /** |
|
| 3617 | - * This prepares the content of the messenger meta box admin settings |
|
| 3618 | - * |
|
| 3619 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3620 | - * @return string html formatted content |
|
| 3621 | - * @throws DomainException |
|
| 3622 | - */ |
|
| 3623 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3624 | - { |
|
| 3616 | + /** |
|
| 3617 | + * This prepares the content of the messenger meta box admin settings |
|
| 3618 | + * |
|
| 3619 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3620 | + * @return string html formatted content |
|
| 3621 | + * @throws DomainException |
|
| 3622 | + */ |
|
| 3623 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3624 | + { |
|
| 3625 | 3625 | |
| 3626 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3627 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3626 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3627 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3628 | 3628 | |
| 3629 | - //is $messenger active? |
|
| 3630 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3629 | + //is $messenger active? |
|
| 3630 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3631 | 3631 | |
| 3632 | 3632 | |
| 3633 | - if ( ! empty($fields)) { |
|
| 3633 | + if ( ! empty($fields)) { |
|
| 3634 | 3634 | |
| 3635 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3635 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3636 | 3636 | |
| 3637 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3638 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3639 | - $template_form_field[$field_id] = array( |
|
| 3640 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3641 | - 'label' => $fldprops['label'], |
|
| 3642 | - 'input' => $fldprops['field_type'], |
|
| 3643 | - 'type' => $fldprops['value_type'], |
|
| 3644 | - 'required' => $fldprops['required'], |
|
| 3645 | - 'validation' => $fldprops['validation'], |
|
| 3646 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3647 | - ? $existing_settings[$field_id] |
|
| 3648 | - : $fldprops['default'], |
|
| 3649 | - 'css_class' => '', |
|
| 3650 | - 'format' => $fldprops['format'] |
|
| 3651 | - ); |
|
| 3652 | - } |
|
| 3637 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3638 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3639 | + $template_form_field[$field_id] = array( |
|
| 3640 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3641 | + 'label' => $fldprops['label'], |
|
| 3642 | + 'input' => $fldprops['field_type'], |
|
| 3643 | + 'type' => $fldprops['value_type'], |
|
| 3644 | + 'required' => $fldprops['required'], |
|
| 3645 | + 'validation' => $fldprops['validation'], |
|
| 3646 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3647 | + ? $existing_settings[$field_id] |
|
| 3648 | + : $fldprops['default'], |
|
| 3649 | + 'css_class' => '', |
|
| 3650 | + 'format' => $fldprops['format'] |
|
| 3651 | + ); |
|
| 3652 | + } |
|
| 3653 | 3653 | |
| 3654 | 3654 | |
| 3655 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3656 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3657 | - : ''; |
|
| 3658 | - } |
|
| 3659 | - |
|
| 3660 | - //we also need some hidden fields |
|
| 3661 | - $settings_template_args['hidden_fields'] = array( |
|
| 3662 | - 'messenger_settings[messenger]' => array( |
|
| 3663 | - 'type' => 'hidden', |
|
| 3664 | - 'value' => $messenger->name |
|
| 3665 | - ), |
|
| 3666 | - 'type' => array( |
|
| 3667 | - 'type' => 'hidden', |
|
| 3668 | - 'value' => 'messenger' |
|
| 3669 | - ) |
|
| 3670 | - ); |
|
| 3671 | - |
|
| 3672 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3673 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3674 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3675 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3676 | - 'type' => 'hidden', |
|
| 3677 | - 'value' => $mt |
|
| 3678 | - ); |
|
| 3679 | - } |
|
| 3680 | - } |
|
| 3681 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3682 | - $settings_template_args['hidden_fields'], |
|
| 3683 | - 'array' |
|
| 3684 | - ); |
|
| 3685 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3686 | - |
|
| 3687 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3688 | - $settings_template_args['description'] = $messenger->description; |
|
| 3689 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3690 | - |
|
| 3691 | - |
|
| 3692 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3693 | - $messenger->name |
|
| 3694 | - ) |
|
| 3695 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3696 | - : ' hidden'; |
|
| 3697 | - |
|
| 3698 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3699 | - ? ' hidden' |
|
| 3700 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3701 | - |
|
| 3702 | - |
|
| 3703 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3704 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3705 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3706 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3707 | - $content = EEH_Template::display_template( |
|
| 3708 | - $template, |
|
| 3709 | - $settings_template_args, |
|
| 3710 | - true |
|
| 3711 | - ); |
|
| 3712 | - |
|
| 3713 | - return $content; |
|
| 3714 | - } |
|
| 3655 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3656 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3657 | + : ''; |
|
| 3658 | + } |
|
| 3659 | + |
|
| 3660 | + //we also need some hidden fields |
|
| 3661 | + $settings_template_args['hidden_fields'] = array( |
|
| 3662 | + 'messenger_settings[messenger]' => array( |
|
| 3663 | + 'type' => 'hidden', |
|
| 3664 | + 'value' => $messenger->name |
|
| 3665 | + ), |
|
| 3666 | + 'type' => array( |
|
| 3667 | + 'type' => 'hidden', |
|
| 3668 | + 'value' => 'messenger' |
|
| 3669 | + ) |
|
| 3670 | + ); |
|
| 3671 | + |
|
| 3672 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3673 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3674 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3675 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3676 | + 'type' => 'hidden', |
|
| 3677 | + 'value' => $mt |
|
| 3678 | + ); |
|
| 3679 | + } |
|
| 3680 | + } |
|
| 3681 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3682 | + $settings_template_args['hidden_fields'], |
|
| 3683 | + 'array' |
|
| 3684 | + ); |
|
| 3685 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3686 | + |
|
| 3687 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3688 | + $settings_template_args['description'] = $messenger->description; |
|
| 3689 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3690 | + |
|
| 3691 | + |
|
| 3692 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3693 | + $messenger->name |
|
| 3694 | + ) |
|
| 3695 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3696 | + : ' hidden'; |
|
| 3697 | + |
|
| 3698 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3699 | + ? ' hidden' |
|
| 3700 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3701 | + |
|
| 3702 | + |
|
| 3703 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3704 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3705 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3706 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3707 | + $content = EEH_Template::display_template( |
|
| 3708 | + $template, |
|
| 3709 | + $settings_template_args, |
|
| 3710 | + true |
|
| 3711 | + ); |
|
| 3712 | + |
|
| 3713 | + return $content; |
|
| 3714 | + } |
|
| 3715 | 3715 | |
| 3716 | 3716 | |
| 3717 | - /** |
|
| 3718 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3719 | - * |
|
| 3720 | - * @throws DomainException |
|
| 3721 | - * @throws EE_Error |
|
| 3722 | - * @throws InvalidDataTypeException |
|
| 3723 | - * @throws InvalidInterfaceException |
|
| 3724 | - * @throws InvalidArgumentException |
|
| 3725 | - * @throws ReflectionException |
|
| 3726 | - */ |
|
| 3727 | - public function activate_messenger_toggle() |
|
| 3728 | - { |
|
| 3729 | - $success = true; |
|
| 3730 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3731 | - //let's check that we have required data |
|
| 3732 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3733 | - EE_Error::add_error( |
|
| 3734 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3735 | - __FILE__, |
|
| 3736 | - __FUNCTION__, |
|
| 3737 | - __LINE__ |
|
| 3738 | - ); |
|
| 3739 | - $success = false; |
|
| 3740 | - } |
|
| 3741 | - |
|
| 3742 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3743 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3744 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3745 | - : ''; |
|
| 3746 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3747 | - |
|
| 3748 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3749 | - |
|
| 3750 | - |
|
| 3751 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3752 | - EE_Error::add_error( |
|
| 3753 | - esc_html__( |
|
| 3754 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3755 | - 'event_espresso' |
|
| 3756 | - ), |
|
| 3757 | - __FILE__, |
|
| 3758 | - __FUNCTION__, |
|
| 3759 | - __LINE__ |
|
| 3760 | - ); |
|
| 3761 | - $success = false; |
|
| 3762 | - } |
|
| 3763 | - |
|
| 3764 | - //do check to verify we have a valid status. |
|
| 3765 | - $status = $this->_req_data['status']; |
|
| 3766 | - |
|
| 3767 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3768 | - EE_Error::add_error( |
|
| 3769 | - sprintf( |
|
| 3770 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3771 | - $this->_req_data['status'] |
|
| 3772 | - ), |
|
| 3773 | - __FILE__, |
|
| 3774 | - __FUNCTION__, |
|
| 3775 | - __LINE__ |
|
| 3776 | - ); |
|
| 3777 | - $success = false; |
|
| 3778 | - } |
|
| 3779 | - |
|
| 3780 | - if ($success) { |
|
| 3781 | - //made it here? Stop dawdling then!! |
|
| 3782 | - $success = $status === 'off' |
|
| 3783 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3784 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3785 | - } |
|
| 3786 | - |
|
| 3787 | - $this->_template_args['success'] = $success; |
|
| 3788 | - |
|
| 3789 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3790 | - $this->_return_json(); |
|
| 3791 | - |
|
| 3792 | - } |
|
| 3717 | + /** |
|
| 3718 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3719 | + * |
|
| 3720 | + * @throws DomainException |
|
| 3721 | + * @throws EE_Error |
|
| 3722 | + * @throws InvalidDataTypeException |
|
| 3723 | + * @throws InvalidInterfaceException |
|
| 3724 | + * @throws InvalidArgumentException |
|
| 3725 | + * @throws ReflectionException |
|
| 3726 | + */ |
|
| 3727 | + public function activate_messenger_toggle() |
|
| 3728 | + { |
|
| 3729 | + $success = true; |
|
| 3730 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3731 | + //let's check that we have required data |
|
| 3732 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3733 | + EE_Error::add_error( |
|
| 3734 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3735 | + __FILE__, |
|
| 3736 | + __FUNCTION__, |
|
| 3737 | + __LINE__ |
|
| 3738 | + ); |
|
| 3739 | + $success = false; |
|
| 3740 | + } |
|
| 3741 | + |
|
| 3742 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3743 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3744 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3745 | + : ''; |
|
| 3746 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3747 | + |
|
| 3748 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3749 | + |
|
| 3750 | + |
|
| 3751 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3752 | + EE_Error::add_error( |
|
| 3753 | + esc_html__( |
|
| 3754 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3755 | + 'event_espresso' |
|
| 3756 | + ), |
|
| 3757 | + __FILE__, |
|
| 3758 | + __FUNCTION__, |
|
| 3759 | + __LINE__ |
|
| 3760 | + ); |
|
| 3761 | + $success = false; |
|
| 3762 | + } |
|
| 3763 | + |
|
| 3764 | + //do check to verify we have a valid status. |
|
| 3765 | + $status = $this->_req_data['status']; |
|
| 3766 | + |
|
| 3767 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3768 | + EE_Error::add_error( |
|
| 3769 | + sprintf( |
|
| 3770 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3771 | + $this->_req_data['status'] |
|
| 3772 | + ), |
|
| 3773 | + __FILE__, |
|
| 3774 | + __FUNCTION__, |
|
| 3775 | + __LINE__ |
|
| 3776 | + ); |
|
| 3777 | + $success = false; |
|
| 3778 | + } |
|
| 3779 | + |
|
| 3780 | + if ($success) { |
|
| 3781 | + //made it here? Stop dawdling then!! |
|
| 3782 | + $success = $status === 'off' |
|
| 3783 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3784 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3785 | + } |
|
| 3786 | + |
|
| 3787 | + $this->_template_args['success'] = $success; |
|
| 3788 | + |
|
| 3789 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3790 | + $this->_return_json(); |
|
| 3791 | + |
|
| 3792 | + } |
|
| 3793 | 3793 | |
| 3794 | 3794 | |
| 3795 | - /** |
|
| 3796 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3797 | - * |
|
| 3798 | - * @throws DomainException |
|
| 3799 | - * @throws EE_Error |
|
| 3800 | - * @throws ReflectionException |
|
| 3801 | - * @throws InvalidDataTypeException |
|
| 3802 | - * @throws InvalidInterfaceException |
|
| 3803 | - * @throws InvalidArgumentException |
|
| 3804 | - */ |
|
| 3805 | - public function activate_mt_toggle() |
|
| 3806 | - { |
|
| 3807 | - $success = true; |
|
| 3808 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3809 | - |
|
| 3810 | - //let's make sure we have the necessary data |
|
| 3811 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3812 | - EE_Error::add_error( |
|
| 3813 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3814 | - __FILE__, |
|
| 3815 | - __FUNCTION__, |
|
| 3816 | - __LINE__ |
|
| 3817 | - ); |
|
| 3818 | - $success = false; |
|
| 3819 | - } |
|
| 3820 | - |
|
| 3821 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3822 | - EE_Error::add_error( |
|
| 3823 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3824 | - __FILE__, |
|
| 3825 | - __FUNCTION__, |
|
| 3826 | - __LINE__ |
|
| 3827 | - ); |
|
| 3828 | - $success = false; |
|
| 3829 | - } |
|
| 3830 | - |
|
| 3831 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3832 | - EE_Error::add_error( |
|
| 3833 | - esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3834 | - 'event_espresso'), |
|
| 3835 | - __FILE__, |
|
| 3836 | - __FUNCTION__, |
|
| 3837 | - __LINE__ |
|
| 3838 | - ); |
|
| 3839 | - $success = false; |
|
| 3840 | - } |
|
| 3841 | - |
|
| 3842 | - |
|
| 3843 | - //do check to verify we have a valid status. |
|
| 3844 | - $status = $this->_req_data['status']; |
|
| 3845 | - |
|
| 3846 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3847 | - EE_Error::add_error( |
|
| 3848 | - sprintf( |
|
| 3849 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3850 | - $this->_req_data['status'] |
|
| 3851 | - ), |
|
| 3852 | - __FILE__, |
|
| 3853 | - __FUNCTION__, |
|
| 3854 | - __LINE__ |
|
| 3855 | - ); |
|
| 3856 | - $success = false; |
|
| 3857 | - } |
|
| 3858 | - |
|
| 3859 | - |
|
| 3860 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3861 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3862 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3863 | - |
|
| 3864 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3865 | - |
|
| 3866 | - if ($success) { |
|
| 3867 | - //made it here? um, what are you waiting for then? |
|
| 3868 | - $success = $status === 'deactivate' |
|
| 3869 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3870 | - $this->_req_data['messenger'], |
|
| 3871 | - $this->_req_data['message_type'] |
|
| 3872 | - ) |
|
| 3873 | - : $this->_activate_message_type_for_messenger( |
|
| 3874 | - $this->_req_data['messenger'], |
|
| 3875 | - $this->_req_data['message_type'] |
|
| 3876 | - ); |
|
| 3877 | - } |
|
| 3878 | - |
|
| 3879 | - $this->_template_args['success'] = $success; |
|
| 3880 | - $this->_return_json(); |
|
| 3881 | - } |
|
| 3795 | + /** |
|
| 3796 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3797 | + * |
|
| 3798 | + * @throws DomainException |
|
| 3799 | + * @throws EE_Error |
|
| 3800 | + * @throws ReflectionException |
|
| 3801 | + * @throws InvalidDataTypeException |
|
| 3802 | + * @throws InvalidInterfaceException |
|
| 3803 | + * @throws InvalidArgumentException |
|
| 3804 | + */ |
|
| 3805 | + public function activate_mt_toggle() |
|
| 3806 | + { |
|
| 3807 | + $success = true; |
|
| 3808 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3809 | + |
|
| 3810 | + //let's make sure we have the necessary data |
|
| 3811 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3812 | + EE_Error::add_error( |
|
| 3813 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3814 | + __FILE__, |
|
| 3815 | + __FUNCTION__, |
|
| 3816 | + __LINE__ |
|
| 3817 | + ); |
|
| 3818 | + $success = false; |
|
| 3819 | + } |
|
| 3820 | + |
|
| 3821 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3822 | + EE_Error::add_error( |
|
| 3823 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3824 | + __FILE__, |
|
| 3825 | + __FUNCTION__, |
|
| 3826 | + __LINE__ |
|
| 3827 | + ); |
|
| 3828 | + $success = false; |
|
| 3829 | + } |
|
| 3830 | + |
|
| 3831 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3832 | + EE_Error::add_error( |
|
| 3833 | + esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3834 | + 'event_espresso'), |
|
| 3835 | + __FILE__, |
|
| 3836 | + __FUNCTION__, |
|
| 3837 | + __LINE__ |
|
| 3838 | + ); |
|
| 3839 | + $success = false; |
|
| 3840 | + } |
|
| 3841 | + |
|
| 3842 | + |
|
| 3843 | + //do check to verify we have a valid status. |
|
| 3844 | + $status = $this->_req_data['status']; |
|
| 3845 | + |
|
| 3846 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3847 | + EE_Error::add_error( |
|
| 3848 | + sprintf( |
|
| 3849 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3850 | + $this->_req_data['status'] |
|
| 3851 | + ), |
|
| 3852 | + __FILE__, |
|
| 3853 | + __FUNCTION__, |
|
| 3854 | + __LINE__ |
|
| 3855 | + ); |
|
| 3856 | + $success = false; |
|
| 3857 | + } |
|
| 3858 | + |
|
| 3859 | + |
|
| 3860 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3861 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3862 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3863 | + |
|
| 3864 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3865 | + |
|
| 3866 | + if ($success) { |
|
| 3867 | + //made it here? um, what are you waiting for then? |
|
| 3868 | + $success = $status === 'deactivate' |
|
| 3869 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3870 | + $this->_req_data['messenger'], |
|
| 3871 | + $this->_req_data['message_type'] |
|
| 3872 | + ) |
|
| 3873 | + : $this->_activate_message_type_for_messenger( |
|
| 3874 | + $this->_req_data['messenger'], |
|
| 3875 | + $this->_req_data['message_type'] |
|
| 3876 | + ); |
|
| 3877 | + } |
|
| 3878 | + |
|
| 3879 | + $this->_template_args['success'] = $success; |
|
| 3880 | + $this->_return_json(); |
|
| 3881 | + } |
|
| 3882 | 3882 | |
| 3883 | 3883 | |
| 3884 | - /** |
|
| 3885 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3886 | - * |
|
| 3887 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3888 | - * @return bool |
|
| 3889 | - * @throws DomainException |
|
| 3890 | - * @throws EE_Error |
|
| 3891 | - * @throws InvalidArgumentException |
|
| 3892 | - * @throws ReflectionException |
|
| 3893 | - * @throws InvalidDataTypeException |
|
| 3894 | - * @throws InvalidInterfaceException |
|
| 3895 | - */ |
|
| 3896 | - protected function _activate_messenger($messenger_name) |
|
| 3897 | - { |
|
| 3898 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3899 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3900 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3901 | - ? $active_messenger->get_default_message_types() |
|
| 3902 | - : array(); |
|
| 3903 | - |
|
| 3904 | - //ensure is active |
|
| 3905 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3906 | - |
|
| 3907 | - //set response_data for reload |
|
| 3908 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3909 | - /** @var EE_message_type $message_type */ |
|
| 3910 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3911 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3912 | - $messenger_name, |
|
| 3913 | - $message_type_name |
|
| 3914 | - ) |
|
| 3915 | - && $message_type instanceof EE_message_type |
|
| 3916 | - ) { |
|
| 3917 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3918 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3919 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3920 | - } |
|
| 3921 | - } |
|
| 3922 | - } |
|
| 3923 | - |
|
| 3924 | - //add success message for activating messenger |
|
| 3925 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3926 | - |
|
| 3927 | - } |
|
| 3884 | + /** |
|
| 3885 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3886 | + * |
|
| 3887 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3888 | + * @return bool |
|
| 3889 | + * @throws DomainException |
|
| 3890 | + * @throws EE_Error |
|
| 3891 | + * @throws InvalidArgumentException |
|
| 3892 | + * @throws ReflectionException |
|
| 3893 | + * @throws InvalidDataTypeException |
|
| 3894 | + * @throws InvalidInterfaceException |
|
| 3895 | + */ |
|
| 3896 | + protected function _activate_messenger($messenger_name) |
|
| 3897 | + { |
|
| 3898 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3899 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3900 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3901 | + ? $active_messenger->get_default_message_types() |
|
| 3902 | + : array(); |
|
| 3903 | + |
|
| 3904 | + //ensure is active |
|
| 3905 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3906 | + |
|
| 3907 | + //set response_data for reload |
|
| 3908 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3909 | + /** @var EE_message_type $message_type */ |
|
| 3910 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3911 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3912 | + $messenger_name, |
|
| 3913 | + $message_type_name |
|
| 3914 | + ) |
|
| 3915 | + && $message_type instanceof EE_message_type |
|
| 3916 | + ) { |
|
| 3917 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3918 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3919 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3920 | + } |
|
| 3921 | + } |
|
| 3922 | + } |
|
| 3923 | + |
|
| 3924 | + //add success message for activating messenger |
|
| 3925 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3926 | + |
|
| 3927 | + } |
|
| 3928 | 3928 | |
| 3929 | 3929 | |
| 3930 | - /** |
|
| 3931 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3932 | - * |
|
| 3933 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3934 | - * @return bool |
|
| 3935 | - * @throws DomainException |
|
| 3936 | - * @throws EE_Error |
|
| 3937 | - * @throws InvalidArgumentException |
|
| 3938 | - * @throws ReflectionException |
|
| 3939 | - * @throws InvalidDataTypeException |
|
| 3940 | - * @throws InvalidInterfaceException |
|
| 3941 | - */ |
|
| 3942 | - protected function _deactivate_messenger($messenger_name) |
|
| 3943 | - { |
|
| 3944 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3945 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3946 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3947 | - |
|
| 3948 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3949 | - } |
|
| 3930 | + /** |
|
| 3931 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3932 | + * |
|
| 3933 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3934 | + * @return bool |
|
| 3935 | + * @throws DomainException |
|
| 3936 | + * @throws EE_Error |
|
| 3937 | + * @throws InvalidArgumentException |
|
| 3938 | + * @throws ReflectionException |
|
| 3939 | + * @throws InvalidDataTypeException |
|
| 3940 | + * @throws InvalidInterfaceException |
|
| 3941 | + */ |
|
| 3942 | + protected function _deactivate_messenger($messenger_name) |
|
| 3943 | + { |
|
| 3944 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3945 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3946 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3947 | + |
|
| 3948 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3949 | + } |
|
| 3950 | 3950 | |
| 3951 | 3951 | |
| 3952 | - /** |
|
| 3953 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3954 | - * |
|
| 3955 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3956 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3957 | - * @return bool |
|
| 3958 | - * @throws DomainException |
|
| 3959 | - * @throws EE_Error |
|
| 3960 | - * @throws InvalidArgumentException |
|
| 3961 | - * @throws ReflectionException |
|
| 3962 | - * @throws InvalidDataTypeException |
|
| 3963 | - * @throws InvalidInterfaceException |
|
| 3964 | - */ |
|
| 3965 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3966 | - { |
|
| 3967 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3968 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3969 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3970 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3971 | - |
|
| 3972 | - //ensure is active |
|
| 3973 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3974 | - |
|
| 3975 | - //set response for load |
|
| 3976 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3977 | - $message_type_name) |
|
| 3978 | - ) { |
|
| 3979 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3980 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3981 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3982 | - } |
|
| 3983 | - } |
|
| 3984 | - |
|
| 3985 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3986 | - $message_type_to_activate); |
|
| 3987 | - } |
|
| 3952 | + /** |
|
| 3953 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3954 | + * |
|
| 3955 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3956 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3957 | + * @return bool |
|
| 3958 | + * @throws DomainException |
|
| 3959 | + * @throws EE_Error |
|
| 3960 | + * @throws InvalidArgumentException |
|
| 3961 | + * @throws ReflectionException |
|
| 3962 | + * @throws InvalidDataTypeException |
|
| 3963 | + * @throws InvalidInterfaceException |
|
| 3964 | + */ |
|
| 3965 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3966 | + { |
|
| 3967 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3968 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3969 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3970 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3971 | + |
|
| 3972 | + //ensure is active |
|
| 3973 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3974 | + |
|
| 3975 | + //set response for load |
|
| 3976 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3977 | + $message_type_name) |
|
| 3978 | + ) { |
|
| 3979 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3980 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3981 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3982 | + } |
|
| 3983 | + } |
|
| 3984 | + |
|
| 3985 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3986 | + $message_type_to_activate); |
|
| 3987 | + } |
|
| 3988 | 3988 | |
| 3989 | 3989 | |
| 3990 | - /** |
|
| 3991 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3992 | - * |
|
| 3993 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3994 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3995 | - * @return bool |
|
| 3996 | - * @throws DomainException |
|
| 3997 | - * @throws EE_Error |
|
| 3998 | - * @throws InvalidArgumentException |
|
| 3999 | - * @throws ReflectionException |
|
| 4000 | - * @throws InvalidDataTypeException |
|
| 4001 | - * @throws InvalidInterfaceException |
|
| 4002 | - */ |
|
| 4003 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4004 | - { |
|
| 4005 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4006 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4007 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4008 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4009 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4010 | - |
|
| 4011 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 4012 | - $message_type_to_deactivate); |
|
| 4013 | - } |
|
| 3990 | + /** |
|
| 3991 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3992 | + * |
|
| 3993 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3994 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3995 | + * @return bool |
|
| 3996 | + * @throws DomainException |
|
| 3997 | + * @throws EE_Error |
|
| 3998 | + * @throws InvalidArgumentException |
|
| 3999 | + * @throws ReflectionException |
|
| 4000 | + * @throws InvalidDataTypeException |
|
| 4001 | + * @throws InvalidInterfaceException |
|
| 4002 | + */ |
|
| 4003 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4004 | + { |
|
| 4005 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4006 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4007 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4008 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4009 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4010 | + |
|
| 4011 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 4012 | + $message_type_to_deactivate); |
|
| 4013 | + } |
|
| 4014 | 4014 | |
| 4015 | 4015 | |
| 4016 | - /** |
|
| 4017 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 4018 | - */ |
|
| 4019 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4020 | - { |
|
| 4021 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4022 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4023 | - } |
|
| 4016 | + /** |
|
| 4017 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 4018 | + */ |
|
| 4019 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4020 | + { |
|
| 4021 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4022 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4023 | + } |
|
| 4024 | 4024 | |
| 4025 | 4025 | |
| 4026 | - /** |
|
| 4027 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4028 | - * |
|
| 4029 | - * @param EE_messenger $messenger |
|
| 4030 | - * @param EE_message_type|null $message_type |
|
| 4031 | - * @return bool |
|
| 4032 | - * @throws DomainException |
|
| 4033 | - * @throws EE_Error |
|
| 4034 | - * @throws InvalidArgumentException |
|
| 4035 | - * @throws ReflectionException |
|
| 4036 | - * @throws InvalidDataTypeException |
|
| 4037 | - * @throws InvalidInterfaceException |
|
| 4038 | - */ |
|
| 4039 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4040 | - $messenger, |
|
| 4041 | - EE_Message_Type $message_type = null |
|
| 4042 | - ) { |
|
| 4043 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4044 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4045 | - EE_Error::add_error( |
|
| 4046 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4047 | - __FILE__, |
|
| 4048 | - __FUNCTION__, |
|
| 4049 | - __LINE__ |
|
| 4050 | - ); |
|
| 4026 | + /** |
|
| 4027 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4028 | + * |
|
| 4029 | + * @param EE_messenger $messenger |
|
| 4030 | + * @param EE_message_type|null $message_type |
|
| 4031 | + * @return bool |
|
| 4032 | + * @throws DomainException |
|
| 4033 | + * @throws EE_Error |
|
| 4034 | + * @throws InvalidArgumentException |
|
| 4035 | + * @throws ReflectionException |
|
| 4036 | + * @throws InvalidDataTypeException |
|
| 4037 | + * @throws InvalidInterfaceException |
|
| 4038 | + */ |
|
| 4039 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4040 | + $messenger, |
|
| 4041 | + EE_Message_Type $message_type = null |
|
| 4042 | + ) { |
|
| 4043 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4044 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4045 | + EE_Error::add_error( |
|
| 4046 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4047 | + __FILE__, |
|
| 4048 | + __FUNCTION__, |
|
| 4049 | + __LINE__ |
|
| 4050 | + ); |
|
| 4051 | 4051 | |
| 4052 | - return false; |
|
| 4053 | - } |
|
| 4054 | - //activated |
|
| 4055 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4056 | - EE_Error::overwrite_success(); |
|
| 4057 | - //activated a message type with the messenger |
|
| 4058 | - if ($message_type instanceof EE_message_type) { |
|
| 4059 | - EE_Error::add_success( |
|
| 4060 | - sprintf( |
|
| 4061 | - esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4062 | - ucwords($message_type->label['singular']), |
|
| 4063 | - ucwords($messenger->label['singular']) |
|
| 4064 | - ) |
|
| 4065 | - ); |
|
| 4052 | + return false; |
|
| 4053 | + } |
|
| 4054 | + //activated |
|
| 4055 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4056 | + EE_Error::overwrite_success(); |
|
| 4057 | + //activated a message type with the messenger |
|
| 4058 | + if ($message_type instanceof EE_message_type) { |
|
| 4059 | + EE_Error::add_success( |
|
| 4060 | + sprintf( |
|
| 4061 | + esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4062 | + ucwords($message_type->label['singular']), |
|
| 4063 | + ucwords($messenger->label['singular']) |
|
| 4064 | + ) |
|
| 4065 | + ); |
|
| 4066 | 4066 | |
| 4067 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4068 | - if ($message_type->name === 'invoice') { |
|
| 4069 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4070 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4071 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4072 | - EE_Error::add_attention( |
|
| 4073 | - esc_html__( |
|
| 4074 | - '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.', |
|
| 4075 | - 'event_espresso' |
|
| 4076 | - ) |
|
| 4077 | - ); |
|
| 4078 | - } |
|
| 4079 | - } |
|
| 4080 | - //just toggles the entire messenger |
|
| 4081 | - } else { |
|
| 4082 | - EE_Error::add_success( |
|
| 4083 | - sprintf( |
|
| 4084 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4085 | - ucwords($messenger->label['singular']) |
|
| 4086 | - ) |
|
| 4087 | - ); |
|
| 4088 | - } |
|
| 4067 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4068 | + if ($message_type->name === 'invoice') { |
|
| 4069 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4070 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4071 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4072 | + EE_Error::add_attention( |
|
| 4073 | + esc_html__( |
|
| 4074 | + '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.', |
|
| 4075 | + 'event_espresso' |
|
| 4076 | + ) |
|
| 4077 | + ); |
|
| 4078 | + } |
|
| 4079 | + } |
|
| 4080 | + //just toggles the entire messenger |
|
| 4081 | + } else { |
|
| 4082 | + EE_Error::add_success( |
|
| 4083 | + sprintf( |
|
| 4084 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4085 | + ucwords($messenger->label['singular']) |
|
| 4086 | + ) |
|
| 4087 | + ); |
|
| 4088 | + } |
|
| 4089 | 4089 | |
| 4090 | - return true; |
|
| 4090 | + return true; |
|
| 4091 | 4091 | |
| 4092 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4093 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4094 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 4095 | - } else { |
|
| 4096 | - if ( ! $messenger->get_default_message_types()) { |
|
| 4097 | - //messenger doesn't have any default message types so still a success. |
|
| 4098 | - EE_Error::add_success( |
|
| 4099 | - sprintf( |
|
| 4100 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4101 | - ucwords($messenger->label['singular']) |
|
| 4102 | - ) |
|
| 4103 | - ); |
|
| 4092 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4093 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4094 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 4095 | + } else { |
|
| 4096 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4097 | + //messenger doesn't have any default message types so still a success. |
|
| 4098 | + EE_Error::add_success( |
|
| 4099 | + sprintf( |
|
| 4100 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4101 | + ucwords($messenger->label['singular']) |
|
| 4102 | + ) |
|
| 4103 | + ); |
|
| 4104 | 4104 | |
| 4105 | - return true; |
|
| 4106 | - } else { |
|
| 4107 | - EE_Error::add_error( |
|
| 4108 | - $message_type instanceof EE_message_type |
|
| 4109 | - ? sprintf( |
|
| 4110 | - esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4111 | - ucwords($message_type->label['singular']), |
|
| 4112 | - ucwords($messenger->label['singular']) |
|
| 4113 | - ) |
|
| 4114 | - : sprintf( |
|
| 4115 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4116 | - ucwords($messenger->label['singular']) |
|
| 4117 | - ), |
|
| 4118 | - __FILE__, |
|
| 4119 | - __FUNCTION__, |
|
| 4120 | - __LINE__ |
|
| 4121 | - ); |
|
| 4105 | + return true; |
|
| 4106 | + } else { |
|
| 4107 | + EE_Error::add_error( |
|
| 4108 | + $message_type instanceof EE_message_type |
|
| 4109 | + ? sprintf( |
|
| 4110 | + esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4111 | + ucwords($message_type->label['singular']), |
|
| 4112 | + ucwords($messenger->label['singular']) |
|
| 4113 | + ) |
|
| 4114 | + : sprintf( |
|
| 4115 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4116 | + ucwords($messenger->label['singular']) |
|
| 4117 | + ), |
|
| 4118 | + __FILE__, |
|
| 4119 | + __FUNCTION__, |
|
| 4120 | + __LINE__ |
|
| 4121 | + ); |
|
| 4122 | 4122 | |
| 4123 | - return false; |
|
| 4124 | - } |
|
| 4125 | - } |
|
| 4126 | - } |
|
| 4123 | + return false; |
|
| 4124 | + } |
|
| 4125 | + } |
|
| 4126 | + } |
|
| 4127 | 4127 | |
| 4128 | 4128 | |
| 4129 | - /** |
|
| 4130 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4131 | - * |
|
| 4132 | - * @param EE_messenger $messenger |
|
| 4133 | - * @param EE_message_type|null $message_type |
|
| 4134 | - * @return bool |
|
| 4135 | - * @throws DomainException |
|
| 4136 | - * @throws EE_Error |
|
| 4137 | - * @throws InvalidArgumentException |
|
| 4138 | - * @throws ReflectionException |
|
| 4139 | - * @throws InvalidDataTypeException |
|
| 4140 | - * @throws InvalidInterfaceException |
|
| 4141 | - */ |
|
| 4142 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4143 | - $messenger, |
|
| 4144 | - EE_message_type $message_type = null |
|
| 4145 | - ) { |
|
| 4146 | - EE_Error::overwrite_success(); |
|
| 4147 | - |
|
| 4148 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4149 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4150 | - EE_Error::add_error( |
|
| 4151 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4152 | - __FILE__, |
|
| 4153 | - __FUNCTION__, |
|
| 4154 | - __LINE__ |
|
| 4155 | - ); |
|
| 4129 | + /** |
|
| 4130 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4131 | + * |
|
| 4132 | + * @param EE_messenger $messenger |
|
| 4133 | + * @param EE_message_type|null $message_type |
|
| 4134 | + * @return bool |
|
| 4135 | + * @throws DomainException |
|
| 4136 | + * @throws EE_Error |
|
| 4137 | + * @throws InvalidArgumentException |
|
| 4138 | + * @throws ReflectionException |
|
| 4139 | + * @throws InvalidDataTypeException |
|
| 4140 | + * @throws InvalidInterfaceException |
|
| 4141 | + */ |
|
| 4142 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4143 | + $messenger, |
|
| 4144 | + EE_message_type $message_type = null |
|
| 4145 | + ) { |
|
| 4146 | + EE_Error::overwrite_success(); |
|
| 4147 | + |
|
| 4148 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4149 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4150 | + EE_Error::add_error( |
|
| 4151 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4152 | + __FILE__, |
|
| 4153 | + __FUNCTION__, |
|
| 4154 | + __LINE__ |
|
| 4155 | + ); |
|
| 4156 | 4156 | |
| 4157 | - return false; |
|
| 4158 | - } |
|
| 4159 | - |
|
| 4160 | - if ($message_type instanceof EE_message_type) { |
|
| 4161 | - $message_type_name = $message_type->name; |
|
| 4162 | - EE_Error::add_success( |
|
| 4163 | - sprintf( |
|
| 4164 | - esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4165 | - ucwords($message_type->label['singular']), |
|
| 4166 | - ucwords($messenger->label['singular']) |
|
| 4167 | - ) |
|
| 4168 | - ); |
|
| 4169 | - } else { |
|
| 4170 | - $message_type_name = ''; |
|
| 4171 | - EE_Error::add_success( |
|
| 4172 | - sprintf( |
|
| 4173 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4174 | - ucwords($messenger->label['singular']) |
|
| 4175 | - ) |
|
| 4176 | - ); |
|
| 4177 | - } |
|
| 4178 | - |
|
| 4179 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4180 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4181 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4182 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4183 | - if ($count_updated > 0) { |
|
| 4184 | - $msg = $message_type_name === 'invoice' |
|
| 4185 | - ? esc_html__( |
|
| 4186 | - '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.', |
|
| 4187 | - 'event_espresso' |
|
| 4188 | - ) |
|
| 4189 | - : esc_html__( |
|
| 4190 | - '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.', |
|
| 4191 | - 'event_espresso' |
|
| 4192 | - ); |
|
| 4193 | - EE_Error::add_attention($msg); |
|
| 4194 | - } |
|
| 4195 | - } |
|
| 4196 | - |
|
| 4197 | - return true; |
|
| 4198 | - } |
|
| 4157 | + return false; |
|
| 4158 | + } |
|
| 4159 | + |
|
| 4160 | + if ($message_type instanceof EE_message_type) { |
|
| 4161 | + $message_type_name = $message_type->name; |
|
| 4162 | + EE_Error::add_success( |
|
| 4163 | + sprintf( |
|
| 4164 | + esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4165 | + ucwords($message_type->label['singular']), |
|
| 4166 | + ucwords($messenger->label['singular']) |
|
| 4167 | + ) |
|
| 4168 | + ); |
|
| 4169 | + } else { |
|
| 4170 | + $message_type_name = ''; |
|
| 4171 | + EE_Error::add_success( |
|
| 4172 | + sprintf( |
|
| 4173 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4174 | + ucwords($messenger->label['singular']) |
|
| 4175 | + ) |
|
| 4176 | + ); |
|
| 4177 | + } |
|
| 4178 | + |
|
| 4179 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4180 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4181 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4182 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4183 | + if ($count_updated > 0) { |
|
| 4184 | + $msg = $message_type_name === 'invoice' |
|
| 4185 | + ? esc_html__( |
|
| 4186 | + '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.', |
|
| 4187 | + 'event_espresso' |
|
| 4188 | + ) |
|
| 4189 | + : esc_html__( |
|
| 4190 | + '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.', |
|
| 4191 | + 'event_espresso' |
|
| 4192 | + ); |
|
| 4193 | + EE_Error::add_attention($msg); |
|
| 4194 | + } |
|
| 4195 | + } |
|
| 4196 | + |
|
| 4197 | + return true; |
|
| 4198 | + } |
|
| 4199 | 4199 | |
| 4200 | 4200 | |
| 4201 | - /** |
|
| 4202 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4203 | - * |
|
| 4204 | - * @throws DomainException |
|
| 4205 | - */ |
|
| 4206 | - public function update_mt_form() |
|
| 4207 | - { |
|
| 4208 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4209 | - EE_Error::add_error( |
|
| 4210 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4211 | - __FILE__, |
|
| 4212 | - __FUNCTION__, |
|
| 4213 | - __LINE__ |
|
| 4214 | - ); |
|
| 4215 | - $this->_return_json(); |
|
| 4216 | - } |
|
| 4217 | - |
|
| 4218 | - $message_types = $this->get_installed_message_types(); |
|
| 4219 | - |
|
| 4220 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4221 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4222 | - |
|
| 4223 | - $content = $this->_message_type_settings_content( |
|
| 4224 | - $message_type, |
|
| 4225 | - $messenger, |
|
| 4226 | - true |
|
| 4227 | - ); |
|
| 4228 | - $this->_template_args['success'] = true; |
|
| 4229 | - $this->_template_args['content'] = $content; |
|
| 4230 | - $this->_return_json(); |
|
| 4231 | - } |
|
| 4201 | + /** |
|
| 4202 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4203 | + * |
|
| 4204 | + * @throws DomainException |
|
| 4205 | + */ |
|
| 4206 | + public function update_mt_form() |
|
| 4207 | + { |
|
| 4208 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4209 | + EE_Error::add_error( |
|
| 4210 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4211 | + __FILE__, |
|
| 4212 | + __FUNCTION__, |
|
| 4213 | + __LINE__ |
|
| 4214 | + ); |
|
| 4215 | + $this->_return_json(); |
|
| 4216 | + } |
|
| 4217 | + |
|
| 4218 | + $message_types = $this->get_installed_message_types(); |
|
| 4219 | + |
|
| 4220 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4221 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4222 | + |
|
| 4223 | + $content = $this->_message_type_settings_content( |
|
| 4224 | + $message_type, |
|
| 4225 | + $messenger, |
|
| 4226 | + true |
|
| 4227 | + ); |
|
| 4228 | + $this->_template_args['success'] = true; |
|
| 4229 | + $this->_template_args['content'] = $content; |
|
| 4230 | + $this->_return_json(); |
|
| 4231 | + } |
|
| 4232 | 4232 | |
| 4233 | 4233 | |
| 4234 | - /** |
|
| 4235 | - * this handles saving the settings for a messenger or message type |
|
| 4236 | - * |
|
| 4237 | - */ |
|
| 4238 | - public function save_settings() |
|
| 4239 | - { |
|
| 4240 | - if ( ! isset($this->_req_data['type'])) { |
|
| 4241 | - EE_Error::add_error( |
|
| 4242 | - esc_html__( |
|
| 4243 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4244 | - 'event_espresso' |
|
| 4245 | - ), |
|
| 4246 | - __FILE__, |
|
| 4247 | - __FUNCTION__, |
|
| 4248 | - __LINE__ |
|
| 4249 | - ); |
|
| 4250 | - $this->_template_args['error'] = true; |
|
| 4251 | - $this->_return_json(); |
|
| 4252 | - } |
|
| 4253 | - |
|
| 4254 | - |
|
| 4255 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4256 | - //this should be an array. |
|
| 4257 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4258 | - $messenger = $settings['messenger']; |
|
| 4259 | - //let's setup the settings data |
|
| 4260 | - foreach ($settings as $key => $value) { |
|
| 4261 | - switch ($key) { |
|
| 4262 | - case 'messenger' : |
|
| 4263 | - unset($settings['messenger']); |
|
| 4264 | - break; |
|
| 4265 | - case 'message_types' : |
|
| 4266 | - unset($settings['message_types']); |
|
| 4267 | - break; |
|
| 4268 | - default : |
|
| 4269 | - $settings[$key] = $value; |
|
| 4270 | - break; |
|
| 4271 | - } |
|
| 4272 | - } |
|
| 4273 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4274 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4275 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4276 | - $messenger = $settings['messenger']; |
|
| 4277 | - $message_type = $settings['message_type']; |
|
| 4234 | + /** |
|
| 4235 | + * this handles saving the settings for a messenger or message type |
|
| 4236 | + * |
|
| 4237 | + */ |
|
| 4238 | + public function save_settings() |
|
| 4239 | + { |
|
| 4240 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4241 | + EE_Error::add_error( |
|
| 4242 | + esc_html__( |
|
| 4243 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4244 | + 'event_espresso' |
|
| 4245 | + ), |
|
| 4246 | + __FILE__, |
|
| 4247 | + __FUNCTION__, |
|
| 4248 | + __LINE__ |
|
| 4249 | + ); |
|
| 4250 | + $this->_template_args['error'] = true; |
|
| 4251 | + $this->_return_json(); |
|
| 4252 | + } |
|
| 4253 | + |
|
| 4254 | + |
|
| 4255 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4256 | + //this should be an array. |
|
| 4257 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4258 | + $messenger = $settings['messenger']; |
|
| 4259 | + //let's setup the settings data |
|
| 4260 | + foreach ($settings as $key => $value) { |
|
| 4261 | + switch ($key) { |
|
| 4262 | + case 'messenger' : |
|
| 4263 | + unset($settings['messenger']); |
|
| 4264 | + break; |
|
| 4265 | + case 'message_types' : |
|
| 4266 | + unset($settings['message_types']); |
|
| 4267 | + break; |
|
| 4268 | + default : |
|
| 4269 | + $settings[$key] = $value; |
|
| 4270 | + break; |
|
| 4271 | + } |
|
| 4272 | + } |
|
| 4273 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4274 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4275 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4276 | + $messenger = $settings['messenger']; |
|
| 4277 | + $message_type = $settings['message_type']; |
|
| 4278 | 4278 | |
| 4279 | - foreach ($settings as $key => $value) { |
|
| 4280 | - switch ($key) { |
|
| 4281 | - case 'messenger' : |
|
| 4282 | - unset($settings['messenger']); |
|
| 4283 | - break; |
|
| 4284 | - case 'message_type' : |
|
| 4285 | - unset($settings['message_type']); |
|
| 4286 | - break; |
|
| 4287 | - default : |
|
| 4288 | - $settings[$key] = $value; |
|
| 4289 | - break; |
|
| 4290 | - } |
|
| 4291 | - } |
|
| 4279 | + foreach ($settings as $key => $value) { |
|
| 4280 | + switch ($key) { |
|
| 4281 | + case 'messenger' : |
|
| 4282 | + unset($settings['messenger']); |
|
| 4283 | + break; |
|
| 4284 | + case 'message_type' : |
|
| 4285 | + unset($settings['message_type']); |
|
| 4286 | + break; |
|
| 4287 | + default : |
|
| 4288 | + $settings[$key] = $value; |
|
| 4289 | + break; |
|
| 4290 | + } |
|
| 4291 | + } |
|
| 4292 | 4292 | |
| 4293 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4294 | - } |
|
| 4295 | - |
|
| 4296 | - //okay we should have the data all setup. Now we just update! |
|
| 4297 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4298 | - |
|
| 4299 | - if ($success) { |
|
| 4300 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4301 | - } else { |
|
| 4302 | - EE_Error::add_error( |
|
| 4303 | - esc_html__( |
|
| 4304 | - 'Settings did not get updated', |
|
| 4305 | - 'event_espresso' |
|
| 4306 | - ), |
|
| 4307 | - __FILE__, |
|
| 4308 | - __FUNCTION__, |
|
| 4309 | - __LINE__ |
|
| 4310 | - ); |
|
| 4311 | - } |
|
| 4312 | - |
|
| 4313 | - $this->_template_args['success'] = $success; |
|
| 4314 | - $this->_return_json(); |
|
| 4315 | - } |
|
| 4293 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4294 | + } |
|
| 4295 | + |
|
| 4296 | + //okay we should have the data all setup. Now we just update! |
|
| 4297 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4298 | + |
|
| 4299 | + if ($success) { |
|
| 4300 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4301 | + } else { |
|
| 4302 | + EE_Error::add_error( |
|
| 4303 | + esc_html__( |
|
| 4304 | + 'Settings did not get updated', |
|
| 4305 | + 'event_espresso' |
|
| 4306 | + ), |
|
| 4307 | + __FILE__, |
|
| 4308 | + __FUNCTION__, |
|
| 4309 | + __LINE__ |
|
| 4310 | + ); |
|
| 4311 | + } |
|
| 4312 | + |
|
| 4313 | + $this->_template_args['success'] = $success; |
|
| 4314 | + $this->_return_json(); |
|
| 4315 | + } |
|
| 4316 | 4316 | |
| 4317 | 4317 | |
| 4318 | 4318 | |
| 4319 | 4319 | |
| 4320 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4320 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4321 | 4321 | |
| 4322 | 4322 | |
| 4323 | - /** |
|
| 4324 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4325 | - * However, this does not send immediately, it just queues for sending. |
|
| 4326 | - * |
|
| 4327 | - * @since 4.9.0 |
|
| 4328 | - * @throws EE_Error |
|
| 4329 | - * @throws InvalidDataTypeException |
|
| 4330 | - * @throws InvalidInterfaceException |
|
| 4331 | - * @throws InvalidArgumentException |
|
| 4332 | - * @throws ReflectionException |
|
| 4333 | - */ |
|
| 4334 | - protected function _generate_now() |
|
| 4335 | - { |
|
| 4336 | - EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4337 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4338 | - } |
|
| 4323 | + /** |
|
| 4324 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4325 | + * However, this does not send immediately, it just queues for sending. |
|
| 4326 | + * |
|
| 4327 | + * @since 4.9.0 |
|
| 4328 | + * @throws EE_Error |
|
| 4329 | + * @throws InvalidDataTypeException |
|
| 4330 | + * @throws InvalidInterfaceException |
|
| 4331 | + * @throws InvalidArgumentException |
|
| 4332 | + * @throws ReflectionException |
|
| 4333 | + */ |
|
| 4334 | + protected function _generate_now() |
|
| 4335 | + { |
|
| 4336 | + EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4337 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4338 | + } |
|
| 4339 | 4339 | |
| 4340 | 4340 | |
| 4341 | - /** |
|
| 4342 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4343 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4344 | - * |
|
| 4345 | - * @since 4.9.0 |
|
| 4346 | - * @throws EE_Error |
|
| 4347 | - * @throws InvalidDataTypeException |
|
| 4348 | - * @throws InvalidInterfaceException |
|
| 4349 | - * @throws InvalidArgumentException |
|
| 4350 | - * @throws ReflectionException |
|
| 4351 | - */ |
|
| 4352 | - protected function _generate_and_send_now() |
|
| 4353 | - { |
|
| 4354 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4355 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | - } |
|
| 4341 | + /** |
|
| 4342 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4343 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4344 | + * |
|
| 4345 | + * @since 4.9.0 |
|
| 4346 | + * @throws EE_Error |
|
| 4347 | + * @throws InvalidDataTypeException |
|
| 4348 | + * @throws InvalidInterfaceException |
|
| 4349 | + * @throws InvalidArgumentException |
|
| 4350 | + * @throws ReflectionException |
|
| 4351 | + */ |
|
| 4352 | + protected function _generate_and_send_now() |
|
| 4353 | + { |
|
| 4354 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4355 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | + } |
|
| 4357 | 4357 | |
| 4358 | 4358 | |
| 4359 | - /** |
|
| 4360 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4361 | - * |
|
| 4362 | - * @since 4.9.0 |
|
| 4363 | - * @throws EE_Error |
|
| 4364 | - * @throws InvalidDataTypeException |
|
| 4365 | - * @throws InvalidInterfaceException |
|
| 4366 | - * @throws InvalidArgumentException |
|
| 4367 | - * @throws ReflectionException |
|
| 4368 | - */ |
|
| 4369 | - protected function _queue_for_resending() |
|
| 4370 | - { |
|
| 4371 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4372 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | - } |
|
| 4359 | + /** |
|
| 4360 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4361 | + * |
|
| 4362 | + * @since 4.9.0 |
|
| 4363 | + * @throws EE_Error |
|
| 4364 | + * @throws InvalidDataTypeException |
|
| 4365 | + * @throws InvalidInterfaceException |
|
| 4366 | + * @throws InvalidArgumentException |
|
| 4367 | + * @throws ReflectionException |
|
| 4368 | + */ |
|
| 4369 | + protected function _queue_for_resending() |
|
| 4370 | + { |
|
| 4371 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4372 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4373 | + } |
|
| 4374 | 4374 | |
| 4375 | 4375 | |
| 4376 | - /** |
|
| 4377 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4378 | - * |
|
| 4379 | - * @since 4.9.0 |
|
| 4380 | - * @throws EE_Error |
|
| 4381 | - * @throws InvalidDataTypeException |
|
| 4382 | - * @throws InvalidInterfaceException |
|
| 4383 | - * @throws InvalidArgumentException |
|
| 4384 | - * @throws ReflectionException |
|
| 4385 | - */ |
|
| 4386 | - protected function _send_now() |
|
| 4387 | - { |
|
| 4388 | - EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4389 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4390 | - } |
|
| 4376 | + /** |
|
| 4377 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4378 | + * |
|
| 4379 | + * @since 4.9.0 |
|
| 4380 | + * @throws EE_Error |
|
| 4381 | + * @throws InvalidDataTypeException |
|
| 4382 | + * @throws InvalidInterfaceException |
|
| 4383 | + * @throws InvalidArgumentException |
|
| 4384 | + * @throws ReflectionException |
|
| 4385 | + */ |
|
| 4386 | + protected function _send_now() |
|
| 4387 | + { |
|
| 4388 | + EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4389 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4390 | + } |
|
| 4391 | 4391 | |
| 4392 | 4392 | |
| 4393 | - /** |
|
| 4394 | - * Deletes EE_messages for IDs in the request. |
|
| 4395 | - * |
|
| 4396 | - * @since 4.9.0 |
|
| 4397 | - * @throws EE_Error |
|
| 4398 | - * @throws InvalidDataTypeException |
|
| 4399 | - * @throws InvalidInterfaceException |
|
| 4400 | - * @throws InvalidArgumentException |
|
| 4401 | - */ |
|
| 4402 | - protected function _delete_ee_messages() |
|
| 4403 | - { |
|
| 4404 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4405 | - $deleted_count = 0; |
|
| 4406 | - foreach ($msg_ids as $msg_id) { |
|
| 4407 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4408 | - $deleted_count++; |
|
| 4409 | - } |
|
| 4410 | - } |
|
| 4411 | - if ($deleted_count) { |
|
| 4412 | - EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso'))); |
|
| 4413 | - $this->_redirect_after_action( |
|
| 4414 | - false, |
|
| 4415 | - '', |
|
| 4416 | - '', |
|
| 4417 | - array(), |
|
| 4418 | - true |
|
| 4419 | - ); |
|
| 4420 | - } else { |
|
| 4421 | - EE_Error::add_error( |
|
| 4422 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4423 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 4424 | - ); |
|
| 4425 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4426 | - } |
|
| 4427 | - } |
|
| 4393 | + /** |
|
| 4394 | + * Deletes EE_messages for IDs in the request. |
|
| 4395 | + * |
|
| 4396 | + * @since 4.9.0 |
|
| 4397 | + * @throws EE_Error |
|
| 4398 | + * @throws InvalidDataTypeException |
|
| 4399 | + * @throws InvalidInterfaceException |
|
| 4400 | + * @throws InvalidArgumentException |
|
| 4401 | + */ |
|
| 4402 | + protected function _delete_ee_messages() |
|
| 4403 | + { |
|
| 4404 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4405 | + $deleted_count = 0; |
|
| 4406 | + foreach ($msg_ids as $msg_id) { |
|
| 4407 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4408 | + $deleted_count++; |
|
| 4409 | + } |
|
| 4410 | + } |
|
| 4411 | + if ($deleted_count) { |
|
| 4412 | + EE_Error::add_success(esc_html(_n('Message successfully deleted', 'Messages successfully deleted', $deleted_count, 'event_espresso'))); |
|
| 4413 | + $this->_redirect_after_action( |
|
| 4414 | + false, |
|
| 4415 | + '', |
|
| 4416 | + '', |
|
| 4417 | + array(), |
|
| 4418 | + true |
|
| 4419 | + ); |
|
| 4420 | + } else { |
|
| 4421 | + EE_Error::add_error( |
|
| 4422 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4423 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 4424 | + ); |
|
| 4425 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4426 | + } |
|
| 4427 | + } |
|
| 4428 | 4428 | |
| 4429 | 4429 | |
| 4430 | - /** |
|
| 4431 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4432 | - * @since 4.9.0 |
|
| 4433 | - * @return array |
|
| 4434 | - */ |
|
| 4435 | - protected function _get_msg_ids_from_request() |
|
| 4436 | - { |
|
| 4437 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4438 | - return array(); |
|
| 4439 | - } |
|
| 4440 | - |
|
| 4441 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4442 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4443 | - : array($this->_req_data['MSG_ID']); |
|
| 4444 | - } |
|
| 4430 | + /** |
|
| 4431 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4432 | + * @since 4.9.0 |
|
| 4433 | + * @return array |
|
| 4434 | + */ |
|
| 4435 | + protected function _get_msg_ids_from_request() |
|
| 4436 | + { |
|
| 4437 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4438 | + return array(); |
|
| 4439 | + } |
|
| 4440 | + |
|
| 4441 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4442 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4443 | + : array($this->_req_data['MSG_ID']); |
|
| 4444 | + } |
|
| 4445 | 4445 | } |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
| 16 | 16 | $I->ensurePluginActive( |
| 17 | - 'event-espresso-mer-multi-event-registration', |
|
| 18 | - 'activated' |
|
| 17 | + 'event-espresso-mer-multi-event-registration', |
|
| 18 | + 'activated' |
|
| 19 | 19 | ); |
| 20 | 20 | |
| 21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -73,38 +73,38 @@ discard block |
||
| 73 | 73 | $I->loginAsAdmin(); |
| 74 | 74 | $I->amOnMessagesActivityListTablePage(); |
| 75 | 75 | $I->see( |
| 76 | - '[email protected]', |
|
| 77 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 78 | - 'to', |
|
| 79 | - 'Registration Multi-status Summary', |
|
| 80 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 81 | - '', |
|
| 82 | - 'Primary Registrant' |
|
| 83 | - ) |
|
| 76 | + '[email protected]', |
|
| 77 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 78 | + 'to', |
|
| 79 | + 'Registration Multi-status Summary', |
|
| 80 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 81 | + '', |
|
| 82 | + 'Primary Registrant' |
|
| 83 | + ) |
|
| 84 | 84 | ); |
| 85 | 85 | $I->see( |
| 86 | - '[email protected]', |
|
| 87 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 88 | - 'to', |
|
| 89 | - 'Registration Multi-status Summary', |
|
| 90 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 91 | - ) |
|
| 86 | + '[email protected]', |
|
| 87 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 88 | + 'to', |
|
| 89 | + 'Registration Multi-status Summary', |
|
| 90 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 91 | + ) |
|
| 92 | 92 | ); |
| 93 | 93 | //verify count |
| 94 | 94 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 95 | - 1, |
|
| 96 | - '[email protected]', |
|
| 97 | - 'to', |
|
| 98 | - 'Registration Multi-status Summary', |
|
| 99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 100 | - 'Email', |
|
| 101 | - 'Primary Registrant' |
|
| 95 | + 1, |
|
| 96 | + '[email protected]', |
|
| 97 | + 'to', |
|
| 98 | + 'Registration Multi-status Summary', |
|
| 99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 100 | + 'Email', |
|
| 101 | + 'Primary Registrant' |
|
| 102 | 102 | ); |
| 103 | 103 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 104 | - 1, |
|
| 105 | - '[email protected]', |
|
| 106 | - 'to', |
|
| 107 | - 'Registration Multi-status Summary' |
|
| 104 | + 1, |
|
| 105 | + '[email protected]', |
|
| 106 | + 'to', |
|
| 107 | + 'Registration Multi-status Summary' |
|
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | 110 | //okay now let's do some registrations for just the first event and verify that registration multi-status summary is NOT |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | $I->loginAsAdmin(); |
| 135 | 135 | $I->amOnMessagesActivityListTablePage(); |
| 136 | 136 | $I->dontSee( |
| 137 | - '[email protected]', |
|
| 138 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 139 | - 'to', |
|
| 140 | - 'Registration Multi-status Summary', |
|
| 141 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 142 | - '', |
|
| 143 | - 'Primary Registrant' |
|
| 144 | - ) |
|
| 137 | + '[email protected]', |
|
| 138 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 139 | + 'to', |
|
| 140 | + 'Registration Multi-status Summary', |
|
| 141 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 142 | + '', |
|
| 143 | + 'Primary Registrant' |
|
| 144 | + ) |
|
| 145 | 145 | ); |
| 146 | 146 | //there should still only be one admin multi-status summary thing. |
| 147 | 147 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 148 | - 1, |
|
| 149 | - '[email protected]', |
|
| 150 | - 'to', |
|
| 151 | - 'Registration Multi-status Summary' |
|
| 148 | + 1, |
|
| 149 | + '[email protected]', |
|
| 150 | + 'to', |
|
| 151 | + 'Registration Multi-status Summary' |
|
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | 154 | //deactivate MER plugin so its not active for future tests |
| 155 | 155 | $I->ensurePluginDeactivated( |
| 156 | - 'event-espresso-mer-multi-event-registration', |
|
| 157 | - 'plugins deactivated' |
|
| 156 | + 'event-espresso-mer-multi-event-registration', |
|
| 157 | + 'plugins deactivated' |
|
| 158 | 158 | ); |
| 159 | 159 | \ No newline at end of file |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | $event_one_link = $event_two_link = $event_three_link = ''; |
| 19 | 19 | |
| 20 | 20 | $I->wantTo( |
| 21 | - 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
| 22 | - . 'template, that that custom template will be used.' |
|
| 21 | + 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
| 22 | + . 'template, that that custom template will be used.' |
|
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | 25 | //need the MER plugin active for this test (we'll deactivate it after). |
| 26 | 26 | $I->ensurePluginActive( |
| 27 | - 'event-espresso-mer-multi-event-registration', |
|
| 28 | - 'activated' |
|
| 27 | + 'event-espresso-mer-multi-event-registration', |
|
| 28 | + 'activated' |
|
| 29 | 29 | ); |
| 30 | 30 | |
| 31 | 31 | $I->loginAsAdmin(); |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | $test_registration_details = array( |
| 83 | - 'fname' => 'CTGuy', |
|
| 84 | - 'lname' => 'Dude', |
|
| 85 | - 'email' => '[email protected]' |
|
| 83 | + 'fname' => 'CTGuy', |
|
| 84 | + 'lname' => 'Dude', |
|
| 85 | + 'email' => '[email protected]' |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.'); |
@@ -108,23 +108,23 @@ discard block |
||
| 108 | 108 | $I->loginAsAdmin(); |
| 109 | 109 | $I->amOnMessagesActivityListTablePage(); |
| 110 | 110 | $I->viewMessageInMessagesListTableFor( |
| 111 | - 'Registration Approved', |
|
| 112 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 113 | - 'Email', |
|
| 114 | - 'Registrant' |
|
| 111 | + 'Registration Approved', |
|
| 112 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 113 | + 'Email', |
|
| 114 | + 'Registrant' |
|
| 115 | 115 | ); |
| 116 | 116 | $I->seeTextInViewMessageModal($custom_template_a_label); |
| 117 | 117 | $I->dismissMessageModal(); |
| 118 | 118 | $I->deleteMessageInMessagesListTableFor( |
| 119 | - 'Registration Approved', |
|
| 120 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 121 | - 'Email', |
|
| 122 | - 'Registrant' |
|
| 119 | + 'Registration Approved', |
|
| 120 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 121 | + 'Email', |
|
| 122 | + 'Registrant' |
|
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | 125 | //verify admin context |
| 126 | 126 | $I->viewMessageInMessagesListTableFor( |
| 127 | - 'Registration Approved' |
|
| 127 | + 'Registration Approved' |
|
| 128 | 128 | ); |
| 129 | 129 | $I->seeTextInViewMessageModal($custom_template_a_label); |
| 130 | 130 | $I->dismissMessageModal(); |
@@ -153,25 +153,25 @@ discard block |
||
| 153 | 153 | $I->loginAsAdmin(); |
| 154 | 154 | $I->amOnMessagesActivityListTablePage(); |
| 155 | 155 | $I->viewMessageInMessagesListTableFor( |
| 156 | - 'Registration Approved', |
|
| 157 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 158 | - 'Email', |
|
| 159 | - 'Registrant' |
|
| 156 | + 'Registration Approved', |
|
| 157 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 158 | + 'Email', |
|
| 159 | + 'Registrant' |
|
| 160 | 160 | ); |
| 161 | 161 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
| 162 | 162 | $I->dontSeeTextInViewMessageModal($custom_template_a_label); |
| 163 | 163 | $I->dontSeeTextInViewMessageModal($custom_template_b_label); |
| 164 | 164 | $I->dismissMessageModal(); |
| 165 | 165 | $I->deleteMessageInMessagesListTableFor( |
| 166 | - 'Registration Approved', |
|
| 167 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 168 | - 'Email', |
|
| 169 | - 'Registrant' |
|
| 166 | + 'Registration Approved', |
|
| 167 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 168 | + 'Email', |
|
| 169 | + 'Registrant' |
|
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | 172 | //verify admin context |
| 173 | 173 | $I->viewMessageInMessagesListTableFor( |
| 174 | - 'Registration Approved' |
|
| 174 | + 'Registration Approved' |
|
| 175 | 175 | ); |
| 176 | 176 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
| 177 | 177 | $I->dontSee($custom_template_a_label); |
@@ -183,6 +183,6 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | //deactivate MER plugin so its not active for future tests |
| 185 | 185 | $I->ensurePluginDeactivated( |
| 186 | - 'event-espresso-mer-multi-event-registration', |
|
| 187 | - 'plugins deactivated' |
|
| 186 | + 'event-espresso-mer-multi-event-registration', |
|
| 187 | + 'plugins deactivated' |
|
| 188 | 188 | ); |
| 189 | 189 | \ No newline at end of file |
@@ -14,133 +14,133 @@ |
||
| 14 | 14 | trait EventsAdmin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $additional_params |
|
| 19 | - */ |
|
| 20 | - public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | - { |
|
| 22 | - $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Triggers the publishing of the Event. |
|
| 28 | - */ |
|
| 29 | - public function publishEvent() |
|
| 30 | - { |
|
| 31 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 32 | - $this->actor()->wait(2); |
|
| 33 | - $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 34 | - $this->actor()->waitForText('Event published.', 30); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Triggers saving the Event. |
|
| 40 | - */ |
|
| 41 | - public function saveEvent() |
|
| 42 | - { |
|
| 43 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 44 | - $this->actor()->wait(2); |
|
| 45 | - $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 51 | - * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 52 | - * |
|
| 53 | - * Assumes actor is already logged in. |
|
| 54 | - * @param $event_title |
|
| 55 | - */ |
|
| 56 | - public function amEditingTheEventWithTitle($event_title) |
|
| 57 | - { |
|
| 58 | - $this->amOnDefaultEventsListTablePage(); |
|
| 59 | - $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 60 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 61 | - $this->actor()->waitForText($event_title, 15); |
|
| 62 | - $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 68 | - * link for the event in the event list table. |
|
| 69 | - * Assumes the actor is already logged in and on the Event list table page. |
|
| 70 | - * |
|
| 71 | - * @param string $event_title |
|
| 72 | - */ |
|
| 73 | - public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 74 | - { |
|
| 75 | - $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 76 | - $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Used to retrieve the event id for the event via the list table and for the given event. |
|
| 82 | - * @param string $event_title |
|
| 83 | - */ |
|
| 84 | - public function observeEventIdInListTableForEvent($event_title) |
|
| 85 | - { |
|
| 86 | - return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 92 | - * Assumes the actor is already logged in and editing an event. |
|
| 93 | - * |
|
| 94 | - * @param int $row_number What ticket row to toggle open/close. |
|
| 95 | - */ |
|
| 96 | - public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 97 | - { |
|
| 98 | - $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 104 | - * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 105 | - * ticket is "open". |
|
| 106 | - * |
|
| 107 | - * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 108 | - */ |
|
| 109 | - public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 110 | - { |
|
| 111 | - $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Use to change the default registration status for the event. |
|
| 117 | - * Assumes the view is already on the event editor. |
|
| 118 | - * @param $registration_status |
|
| 119 | - */ |
|
| 120 | - public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 121 | - { |
|
| 122 | - $this->actor()->selectOption( |
|
| 123 | - EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 124 | - $registration_status |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 131 | - * messenger. |
|
| 132 | - * |
|
| 133 | - * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 134 | - * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 135 | - * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 136 | - * selected. |
|
| 137 | - */ |
|
| 138 | - public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 139 | - { |
|
| 140 | - $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 141 | - $this->actor()->selectOption( |
|
| 142 | - EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 143 | - $custom_template_label |
|
| 144 | - ); |
|
| 145 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $additional_params |
|
| 19 | + */ |
|
| 20 | + public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | + { |
|
| 22 | + $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Triggers the publishing of the Event. |
|
| 28 | + */ |
|
| 29 | + public function publishEvent() |
|
| 30 | + { |
|
| 31 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 32 | + $this->actor()->wait(2); |
|
| 33 | + $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 34 | + $this->actor()->waitForText('Event published.', 30); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Triggers saving the Event. |
|
| 40 | + */ |
|
| 41 | + public function saveEvent() |
|
| 42 | + { |
|
| 43 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 44 | + $this->actor()->wait(2); |
|
| 45 | + $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 51 | + * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 52 | + * |
|
| 53 | + * Assumes actor is already logged in. |
|
| 54 | + * @param $event_title |
|
| 55 | + */ |
|
| 56 | + public function amEditingTheEventWithTitle($event_title) |
|
| 57 | + { |
|
| 58 | + $this->amOnDefaultEventsListTablePage(); |
|
| 59 | + $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 60 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 61 | + $this->actor()->waitForText($event_title, 15); |
|
| 62 | + $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 68 | + * link for the event in the event list table. |
|
| 69 | + * Assumes the actor is already logged in and on the Event list table page. |
|
| 70 | + * |
|
| 71 | + * @param string $event_title |
|
| 72 | + */ |
|
| 73 | + public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 74 | + { |
|
| 75 | + $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 76 | + $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Used to retrieve the event id for the event via the list table and for the given event. |
|
| 82 | + * @param string $event_title |
|
| 83 | + */ |
|
| 84 | + public function observeEventIdInListTableForEvent($event_title) |
|
| 85 | + { |
|
| 86 | + return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 92 | + * Assumes the actor is already logged in and editing an event. |
|
| 93 | + * |
|
| 94 | + * @param int $row_number What ticket row to toggle open/close. |
|
| 95 | + */ |
|
| 96 | + public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 97 | + { |
|
| 98 | + $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 104 | + * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 105 | + * ticket is "open". |
|
| 106 | + * |
|
| 107 | + * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 108 | + */ |
|
| 109 | + public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 110 | + { |
|
| 111 | + $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Use to change the default registration status for the event. |
|
| 117 | + * Assumes the view is already on the event editor. |
|
| 118 | + * @param $registration_status |
|
| 119 | + */ |
|
| 120 | + public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 121 | + { |
|
| 122 | + $this->actor()->selectOption( |
|
| 123 | + EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 124 | + $registration_status |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 131 | + * messenger. |
|
| 132 | + * |
|
| 133 | + * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 134 | + * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 135 | + * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 136 | + * selected. |
|
| 137 | + */ |
|
| 138 | + public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 139 | + { |
|
| 140 | + $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 141 | + $this->actor()->selectOption( |
|
| 142 | + EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 143 | + $custom_template_label |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | 146 | } |
| 147 | 147 | \ No newline at end of file |
@@ -10,296 +10,296 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | trait MessagesAdmin |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | - * a string. |
|
| 16 | - */ |
|
| 17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | - { |
|
| 19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | - * a string. |
|
| 25 | - */ |
|
| 26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | - { |
|
| 28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | - * a string. |
|
| 35 | - */ |
|
| 36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | - { |
|
| 38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Directs to message settings page |
|
| 44 | - */ |
|
| 45 | - public function amOnMessageSettingsPage() |
|
| 46 | - { |
|
| 47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | - { |
|
| 53 | - $this->actor()->dragAndDrop( |
|
| 54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | - * @param string $message_type_slug |
|
| 63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | - */ |
|
| 65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | - { |
|
| 67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | - * |
|
| 75 | - * @param int $expected_occurence_count |
|
| 76 | - * @param string $text_to_check_for |
|
| 77 | - * @param string $field |
|
| 78 | - * @param string $message_type_label |
|
| 79 | - * @param string $message_status |
|
| 80 | - * @param string $messenger |
|
| 81 | - * @param string $context |
|
| 82 | - */ |
|
| 83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | - $expected_occurence_count, |
|
| 85 | - $text_to_check_for, |
|
| 86 | - $field, |
|
| 87 | - $message_type_label, |
|
| 88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | - $messenger = 'Email', |
|
| 90 | - $context = 'Event Admin' |
|
| 91 | - ) { |
|
| 92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | - $field, |
|
| 94 | - $message_type_label, |
|
| 95 | - $message_status, |
|
| 96 | - $messenger, |
|
| 97 | - $context, |
|
| 98 | - $text_to_check_for, |
|
| 99 | - 0 |
|
| 100 | - )); |
|
| 101 | - $actual_count = count($elements); |
|
| 102 | - $this->actor()->assertEquals( |
|
| 103 | - $expected_occurence_count, |
|
| 104 | - $actual_count, |
|
| 105 | - sprintf( |
|
| 106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | - $expected_occurence_count, |
|
| 108 | - $text_to_check_for, |
|
| 109 | - $field, |
|
| 110 | - $actual_count |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | - * default (global) message template list table. |
|
| 119 | - * Also takes care of verifying the template was created. |
|
| 120 | - * @param string $message_type_label |
|
| 121 | - * @param string $messenger_label |
|
| 122 | - */ |
|
| 123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | - { |
|
| 125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | - $this->actor()->click( |
|
| 127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | - $message_type_label, |
|
| 129 | - $messenger_label |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * This switches the context of the current messages template to the given reference. |
|
| 138 | - * @param string $context_reference This should be the visible label for the option. |
|
| 139 | - */ |
|
| 140 | - public function switchContextTo($context_reference) |
|
| 141 | - { |
|
| 142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | - * toggling. |
|
| 151 | - * |
|
| 152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | - * (false) |
|
| 155 | - */ |
|
| 156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | - { |
|
| 158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | - if ($expected_state_is_active) { |
|
| 160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | - } else { |
|
| 162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Triggers saving the message template. |
|
| 169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | - */ |
|
| 171 | - public function saveMessageTemplate($and_close = false) |
|
| 172 | - { |
|
| 173 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
| 174 | - if ($and_close) { |
|
| 175 | - $this->actor()->click('Save and Close'); |
|
| 176 | - } else { |
|
| 177 | - $this->actor()->click('Save'); |
|
| 178 | - } |
|
| 179 | - $this->actor()->waitForText('successfully updated'); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * This takes care of clicking the View Message icon for the given parameters. |
|
| 185 | - * Assumes you are already viewing the messages activity list table. |
|
| 186 | - * @param $message_type_label |
|
| 187 | - * @param $message_status |
|
| 188 | - * @param string $messenger |
|
| 189 | - * @param string $context |
|
| 190 | - * @param int $number_in_set |
|
| 191 | - */ |
|
| 192 | - public function viewMessageInMessagesListTableFor( |
|
| 193 | - $message_type_label, |
|
| 194 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 195 | - $messenger = 'Email', |
|
| 196 | - $context = 'Event Admin', |
|
| 197 | - $number_in_set = 1 |
|
| 198 | - ) { |
|
| 199 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 200 | - $message_type_label, |
|
| 201 | - $message_status, |
|
| 202 | - $messenger, |
|
| 203 | - $context, |
|
| 204 | - $number_in_set |
|
| 205 | - )); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 211 | - * Assumes you are already viewing the messages activity list table. |
|
| 212 | - * @param $message_type_label |
|
| 213 | - * @param $message_status |
|
| 214 | - * @param string $messenger |
|
| 215 | - * @param string $context |
|
| 216 | - * @param int $number_in_set |
|
| 217 | - */ |
|
| 218 | - public function deleteMessageInMessagesListTableFor( |
|
| 219 | - $message_type_label, |
|
| 220 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 221 | - $messenger = 'Email', |
|
| 222 | - $context = 'Event Admin', |
|
| 223 | - $number_in_set = 1 |
|
| 224 | - ) { |
|
| 225 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 226 | - $message_type_label, |
|
| 227 | - $message_status, |
|
| 228 | - $messenger, |
|
| 229 | - $context, |
|
| 230 | - $number_in_set |
|
| 231 | - ); |
|
| 232 | - $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | - 'to', |
|
| 234 | - $message_type_label, |
|
| 235 | - $message_status, |
|
| 236 | - $messenger, |
|
| 237 | - $context, |
|
| 238 | - '', |
|
| 239 | - $number_in_set |
|
| 240 | - ); |
|
| 241 | - $this->actor()->scrollTo($cell_selector, 0, -30); |
|
| 242 | - $this->actor()->moveMouseOver( |
|
| 243 | - $cell_selector, |
|
| 244 | - 5, |
|
| 245 | - 5 |
|
| 246 | - ); |
|
| 247 | - $this->actor()->waitForElementVisible( |
|
| 248 | - $delete_action_selector |
|
| 249 | - ); |
|
| 250 | - $this->actor()->click( |
|
| 251 | - $delete_action_selector |
|
| 252 | - ); |
|
| 253 | - $this->actor()->waitForText('successfully deleted', 20); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 259 | - * list table, this will take care of validating the given text is in that window. |
|
| 260 | - * @param string $text_to_view |
|
| 261 | - */ |
|
| 262 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 263 | - { |
|
| 264 | - $this->actor()->wait(2); |
|
| 265 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 266 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 267 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 268 | - $this->actor()->switchToIframe(); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * This returns the value for the link at the given selector in the message modal. |
|
| 274 | - * @param string $selector (any selector string accepted by WebDriver) |
|
| 275 | - */ |
|
| 276 | - public function observeLinkAtSelectorInMessageModal($selector) |
|
| 277 | - { |
|
| 278 | - $this->actor()->wait(2); |
|
| 279 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 280 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 281 | - $link = $this->actor()->observeLinkUrlAt($selector); |
|
| 282 | - $this->actor()->switchToIframe(); |
|
| 283 | - return $link; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 289 | - * list table, this will take care of validating the given text is NOT that window. |
|
| 290 | - * @param string $text_to_view |
|
| 291 | - */ |
|
| 292 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 293 | - { |
|
| 294 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - public function dismissMessageModal() |
|
| 299 | - { |
|
| 300 | - $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
| 301 | - //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
| 302 | - $this->actor()->scrollTo('form#EE_Message_List_Table-table-frm'); |
|
| 303 | - $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
| 304 | - } |
|
| 13 | + /** |
|
| 14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | + * a string. |
|
| 16 | + */ |
|
| 17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | + { |
|
| 19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | + * a string. |
|
| 25 | + */ |
|
| 26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | + { |
|
| 28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | + * a string. |
|
| 35 | + */ |
|
| 36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | + { |
|
| 38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Directs to message settings page |
|
| 44 | + */ |
|
| 45 | + public function amOnMessageSettingsPage() |
|
| 46 | + { |
|
| 47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | + { |
|
| 53 | + $this->actor()->dragAndDrop( |
|
| 54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | + * @param string $message_type_slug |
|
| 63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | + */ |
|
| 65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | + { |
|
| 67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | + * |
|
| 75 | + * @param int $expected_occurence_count |
|
| 76 | + * @param string $text_to_check_for |
|
| 77 | + * @param string $field |
|
| 78 | + * @param string $message_type_label |
|
| 79 | + * @param string $message_status |
|
| 80 | + * @param string $messenger |
|
| 81 | + * @param string $context |
|
| 82 | + */ |
|
| 83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | + $expected_occurence_count, |
|
| 85 | + $text_to_check_for, |
|
| 86 | + $field, |
|
| 87 | + $message_type_label, |
|
| 88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | + $messenger = 'Email', |
|
| 90 | + $context = 'Event Admin' |
|
| 91 | + ) { |
|
| 92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | + $field, |
|
| 94 | + $message_type_label, |
|
| 95 | + $message_status, |
|
| 96 | + $messenger, |
|
| 97 | + $context, |
|
| 98 | + $text_to_check_for, |
|
| 99 | + 0 |
|
| 100 | + )); |
|
| 101 | + $actual_count = count($elements); |
|
| 102 | + $this->actor()->assertEquals( |
|
| 103 | + $expected_occurence_count, |
|
| 104 | + $actual_count, |
|
| 105 | + sprintf( |
|
| 106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | + $expected_occurence_count, |
|
| 108 | + $text_to_check_for, |
|
| 109 | + $field, |
|
| 110 | + $actual_count |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | + * default (global) message template list table. |
|
| 119 | + * Also takes care of verifying the template was created. |
|
| 120 | + * @param string $message_type_label |
|
| 121 | + * @param string $messenger_label |
|
| 122 | + */ |
|
| 123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | + { |
|
| 125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | + $this->actor()->click( |
|
| 127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | + $message_type_label, |
|
| 129 | + $messenger_label |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * This switches the context of the current messages template to the given reference. |
|
| 138 | + * @param string $context_reference This should be the visible label for the option. |
|
| 139 | + */ |
|
| 140 | + public function switchContextTo($context_reference) |
|
| 141 | + { |
|
| 142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | + * toggling. |
|
| 151 | + * |
|
| 152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | + * (false) |
|
| 155 | + */ |
|
| 156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | + { |
|
| 158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | + if ($expected_state_is_active) { |
|
| 160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | + } else { |
|
| 162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Triggers saving the message template. |
|
| 169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | + */ |
|
| 171 | + public function saveMessageTemplate($and_close = false) |
|
| 172 | + { |
|
| 173 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
| 174 | + if ($and_close) { |
|
| 175 | + $this->actor()->click('Save and Close'); |
|
| 176 | + } else { |
|
| 177 | + $this->actor()->click('Save'); |
|
| 178 | + } |
|
| 179 | + $this->actor()->waitForText('successfully updated'); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * This takes care of clicking the View Message icon for the given parameters. |
|
| 185 | + * Assumes you are already viewing the messages activity list table. |
|
| 186 | + * @param $message_type_label |
|
| 187 | + * @param $message_status |
|
| 188 | + * @param string $messenger |
|
| 189 | + * @param string $context |
|
| 190 | + * @param int $number_in_set |
|
| 191 | + */ |
|
| 192 | + public function viewMessageInMessagesListTableFor( |
|
| 193 | + $message_type_label, |
|
| 194 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 195 | + $messenger = 'Email', |
|
| 196 | + $context = 'Event Admin', |
|
| 197 | + $number_in_set = 1 |
|
| 198 | + ) { |
|
| 199 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 200 | + $message_type_label, |
|
| 201 | + $message_status, |
|
| 202 | + $messenger, |
|
| 203 | + $context, |
|
| 204 | + $number_in_set |
|
| 205 | + )); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 211 | + * Assumes you are already viewing the messages activity list table. |
|
| 212 | + * @param $message_type_label |
|
| 213 | + * @param $message_status |
|
| 214 | + * @param string $messenger |
|
| 215 | + * @param string $context |
|
| 216 | + * @param int $number_in_set |
|
| 217 | + */ |
|
| 218 | + public function deleteMessageInMessagesListTableFor( |
|
| 219 | + $message_type_label, |
|
| 220 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 221 | + $messenger = 'Email', |
|
| 222 | + $context = 'Event Admin', |
|
| 223 | + $number_in_set = 1 |
|
| 224 | + ) { |
|
| 225 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 226 | + $message_type_label, |
|
| 227 | + $message_status, |
|
| 228 | + $messenger, |
|
| 229 | + $context, |
|
| 230 | + $number_in_set |
|
| 231 | + ); |
|
| 232 | + $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | + 'to', |
|
| 234 | + $message_type_label, |
|
| 235 | + $message_status, |
|
| 236 | + $messenger, |
|
| 237 | + $context, |
|
| 238 | + '', |
|
| 239 | + $number_in_set |
|
| 240 | + ); |
|
| 241 | + $this->actor()->scrollTo($cell_selector, 0, -30); |
|
| 242 | + $this->actor()->moveMouseOver( |
|
| 243 | + $cell_selector, |
|
| 244 | + 5, |
|
| 245 | + 5 |
|
| 246 | + ); |
|
| 247 | + $this->actor()->waitForElementVisible( |
|
| 248 | + $delete_action_selector |
|
| 249 | + ); |
|
| 250 | + $this->actor()->click( |
|
| 251 | + $delete_action_selector |
|
| 252 | + ); |
|
| 253 | + $this->actor()->waitForText('successfully deleted', 20); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 259 | + * list table, this will take care of validating the given text is in that window. |
|
| 260 | + * @param string $text_to_view |
|
| 261 | + */ |
|
| 262 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 263 | + { |
|
| 264 | + $this->actor()->wait(2); |
|
| 265 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 266 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 267 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 268 | + $this->actor()->switchToIframe(); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * This returns the value for the link at the given selector in the message modal. |
|
| 274 | + * @param string $selector (any selector string accepted by WebDriver) |
|
| 275 | + */ |
|
| 276 | + public function observeLinkAtSelectorInMessageModal($selector) |
|
| 277 | + { |
|
| 278 | + $this->actor()->wait(2); |
|
| 279 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 280 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 281 | + $link = $this->actor()->observeLinkUrlAt($selector); |
|
| 282 | + $this->actor()->switchToIframe(); |
|
| 283 | + return $link; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 289 | + * list table, this will take care of validating the given text is NOT that window. |
|
| 290 | + * @param string $text_to_view |
|
| 291 | + */ |
|
| 292 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 293 | + { |
|
| 294 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + public function dismissMessageModal() |
|
| 299 | + { |
|
| 300 | + $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
| 301 | + //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
| 302 | + $this->actor()->scrollTo('form#EE_Message_List_Table-table-frm'); |
|
| 303 | + $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
| 304 | + } |
|
| 305 | 305 | } |