@@ -55,7 +55,7 @@ discard block  | 
                                                    ||
| 55 | 55 | 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',  | 
                                                        
| 56 | 56 | 'event_espresso'  | 
                                                        
| 57 | 57 | );  | 
                                                        
| 58 | - $this->label = array(  | 
                                                        |
| 58 | + $this->label = array(  | 
                                                        |
| 59 | 59 |              'singular' => esc_html__('email', 'event_espresso'), | 
                                                        
| 60 | 60 |              'plural'   => esc_html__('emails', 'event_espresso'), | 
                                                        
| 61 | 61 | );  | 
                                                        
@@ -419,7 +419,7 @@ discard block  | 
                                                    ||
| 419 | 419 | $this->_body(),  | 
                                                        
| 420 | 420 | $this->_headers()  | 
                                                        
| 421 | 421 | );  | 
                                                        
| 422 | -        if (! $success) { | 
                                                        |
| 422 | +        if ( ! $success) { | 
                                                        |
| 423 | 423 | EE_Error::add_error(  | 
                                                        
| 424 | 424 | sprintf(  | 
                                                        
| 425 | 425 | esc_html__(  | 
                                                        
@@ -464,13 +464,13 @@ discard block  | 
                                                    ||
| 464 | 464 | $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));  | 
                                                        
| 465 | 465 | $headers = array(  | 
                                                        
| 466 | 466 | 'MIME-Version: 1.0',  | 
                                                        
| 467 | - 'From:' . $from,  | 
                                                        |
| 468 | - 'Reply-To:' . $from,  | 
                                                        |
| 467 | + 'From:'.$from,  | 
                                                        |
| 468 | + 'Reply-To:'.$from,  | 
                                                        |
| 469 | 469 | 'Content-Type:text/html; charset=utf-8',  | 
                                                        
| 470 | 470 | );  | 
                                                        
| 471 | 471 | |
| 472 | -        if (! empty($this->_cc)) { | 
                                                        |
| 473 | - $headers[] = 'cc: ' . $this->_cc;  | 
                                                        |
| 472 | +        if ( ! empty($this->_cc)) { | 
                                                        |
| 473 | + $headers[] = 'cc: '.$this->_cc;  | 
                                                        |
| 474 | 474 | }  | 
                                                        
| 475 | 475 | |
| 476 | 476 | //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the  | 
                                                        
@@ -580,7 +580,7 @@ discard block  | 
                                                    ||
| 580 | 580 | )  | 
                                                        
| 581 | 581 | ),  | 
                                                        
| 582 | 582 | );  | 
                                                        
| 583 | - $body = $this->_get_main_template($preview);  | 
                                                        |
| 583 | + $body = $this->_get_main_template($preview);  | 
                                                        |
| 584 | 584 | |
| 585 | 585 | /**  | 
                                                        
| 586 | 586 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.  | 
                                                        
@@ -590,10 +590,10 @@ discard block  | 
                                                    ||
| 590 | 590 | */  | 
                                                        
| 591 | 591 |          if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { | 
                                                        
| 592 | 592 | //require CssToInlineStyles library and its dependencies via composer autoloader  | 
                                                        
| 593 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';  | 
                                                        |
| 593 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php';  | 
                                                        |
| 594 | 594 | |
| 595 | 595 | //now if this isn't a preview, let's setup the body so it has inline styles  | 
                                                        
| 596 | -            if (! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 596 | +            if ( ! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 597 | 597 | $style = file_get_contents(  | 
                                                        
| 598 | 598 | $this->get_variation(  | 
                                                        
| 599 | 599 | $this->_tmp_pack,  | 
                                                        
@@ -8,643 +8,643 @@  | 
                                                    ||
| 8 | 8 | class EE_Email_messenger extends EE_messenger  | 
                                                        
| 9 | 9 |  { | 
                                                        
| 10 | 10 | |
| 11 | - /**  | 
                                                        |
| 12 | - * To field for email  | 
                                                        |
| 13 | - * @var string  | 
                                                        |
| 14 | - */  | 
                                                        |
| 15 | - protected $_to = '';  | 
                                                        |
| 16 | -  | 
                                                        |
| 17 | -  | 
                                                        |
| 18 | - /**  | 
                                                        |
| 19 | - * CC field for email.  | 
                                                        |
| 20 | - * @var string  | 
                                                        |
| 21 | - */  | 
                                                        |
| 22 | - protected $_cc = '';  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - /**  | 
                                                        |
| 25 | - * From field for email  | 
                                                        |
| 26 | - * @var string  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - protected $_from = '';  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | -  | 
                                                        |
| 31 | - /**  | 
                                                        |
| 32 | - * Subject field for email  | 
                                                        |
| 33 | - * @var string  | 
                                                        |
| 34 | - */  | 
                                                        |
| 35 | - protected $_subject = '';  | 
                                                        |
| 36 | -  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - /**  | 
                                                        |
| 39 | - * Content field for email  | 
                                                        |
| 40 | - * @var string  | 
                                                        |
| 41 | - */  | 
                                                        |
| 42 | - protected $_content = '';  | 
                                                        |
| 43 | -  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /**  | 
                                                        |
| 46 | - * constructor  | 
                                                        |
| 47 | - *  | 
                                                        |
| 48 | - * @access public  | 
                                                        |
| 49 | - */  | 
                                                        |
| 50 | - public function __construct()  | 
                                                        |
| 51 | -    { | 
                                                        |
| 52 | - //set name and description properties  | 
                                                        |
| 53 | - $this->name = 'email';  | 
                                                        |
| 54 | - $this->description = esc_html__(  | 
                                                        |
| 55 | - 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',  | 
                                                        |
| 56 | - 'event_espresso'  | 
                                                        |
| 57 | - );  | 
                                                        |
| 58 | - $this->label = array(  | 
                                                        |
| 59 | -            'singular' => esc_html__('email', 'event_espresso'), | 
                                                        |
| 60 | -            'plural'   => esc_html__('emails', 'event_espresso'), | 
                                                        |
| 61 | - );  | 
                                                        |
| 62 | - $this->activate_on_install = true;  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other  | 
                                                        |
| 65 | - // properties  | 
                                                        |
| 66 | - parent::__construct();  | 
                                                        |
| 67 | - }  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - /**  | 
                                                        |
| 71 | - * see abstract declaration in parent class for details.  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - protected function _set_admin_pages()  | 
                                                        |
| 74 | -    { | 
                                                        |
| 75 | - $this->admin_registered_pages = array(  | 
                                                        |
| 76 | - 'events_edit' => true,  | 
                                                        |
| 77 | - );  | 
                                                        |
| 78 | - }  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | - /**  | 
                                                        |
| 82 | - * see abstract declaration in parent class for details  | 
                                                        |
| 83 | - */  | 
                                                        |
| 84 | - protected function _set_valid_shortcodes()  | 
                                                        |
| 85 | -    { | 
                                                        |
| 86 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the  | 
                                                        |
| 87 | - // message type.  | 
                                                        |
| 88 | - $this->_valid_shortcodes = array(  | 
                                                        |
| 89 | -            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 90 | -            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 91 | -            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 92 | - );  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * see abstract declaration in parent class for details  | 
                                                        |
| 98 | - *  | 
                                                        |
| 99 | - * @access protected  | 
                                                        |
| 100 | - * @return void  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - protected function _set_validator_config()  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | - $valid_shortcodes = $this->get_valid_shortcodes();  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | - $this->_validator_config = array(  | 
                                                        |
| 107 | - 'to' => array(  | 
                                                        |
| 108 | - 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 109 | - 'type' => 'email',  | 
                                                        |
| 110 | - ),  | 
                                                        |
| 111 | - 'cc' => array(  | 
                                                        |
| 112 | - 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 113 | - 'type' => 'email',  | 
                                                        |
| 114 | - ),  | 
                                                        |
| 115 | - 'from' => array(  | 
                                                        |
| 116 | - 'shortcodes' => $valid_shortcodes['from'],  | 
                                                        |
| 117 | - 'type' => 'email',  | 
                                                        |
| 118 | - ),  | 
                                                        |
| 119 | - 'subject' => array(  | 
                                                        |
| 120 | - 'shortcodes' => array(  | 
                                                        |
| 121 | - 'organization',  | 
                                                        |
| 122 | - 'primary_registration_details',  | 
                                                        |
| 123 | - 'event_author',  | 
                                                        |
| 124 | - 'primary_registration_details',  | 
                                                        |
| 125 | - 'recipient_details',  | 
                                                        |
| 126 | - ),  | 
                                                        |
| 127 | - ),  | 
                                                        |
| 128 | - 'content' => array(  | 
                                                        |
| 129 | - 'shortcodes' => array(  | 
                                                        |
| 130 | - 'event_list',  | 
                                                        |
| 131 | - 'attendee_list',  | 
                                                        |
| 132 | - 'ticket_list',  | 
                                                        |
| 133 | - 'organization',  | 
                                                        |
| 134 | - 'primary_registration_details',  | 
                                                        |
| 135 | - 'primary_registration_list',  | 
                                                        |
| 136 | - 'event_author',  | 
                                                        |
| 137 | - 'recipient_details',  | 
                                                        |
| 138 | - 'recipient_list',  | 
                                                        |
| 139 | - 'transaction',  | 
                                                        |
| 140 | - 'messenger',  | 
                                                        |
| 141 | - ),  | 
                                                        |
| 142 | - ),  | 
                                                        |
| 143 | - 'attendee_list' => array(  | 
                                                        |
| 144 | -                'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 145 | -                'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 146 | - ),  | 
                                                        |
| 147 | - 'event_list' => array(  | 
                                                        |
| 148 | - 'shortcodes' => array(  | 
                                                        |
| 149 | - 'event',  | 
                                                        |
| 150 | - 'attendee_list',  | 
                                                        |
| 151 | - 'ticket_list',  | 
                                                        |
| 152 | - 'venue',  | 
                                                        |
| 153 | - 'datetime_list',  | 
                                                        |
| 154 | - 'attendee',  | 
                                                        |
| 155 | - 'primary_registration_details',  | 
                                                        |
| 156 | - 'primary_registration_list',  | 
                                                        |
| 157 | - 'event_author',  | 
                                                        |
| 158 | - 'recipient_details',  | 
                                                        |
| 159 | - 'recipient_list',  | 
                                                        |
| 160 | - ),  | 
                                                        |
| 161 | -                'required'   => array('[EVENT_LIST]'), | 
                                                        |
| 162 | - ),  | 
                                                        |
| 163 | - 'ticket_list' => array(  | 
                                                        |
| 164 | - 'shortcodes' => array(  | 
                                                        |
| 165 | - 'event_list',  | 
                                                        |
| 166 | - 'attendee_list',  | 
                                                        |
| 167 | - 'ticket',  | 
                                                        |
| 168 | - 'datetime_list',  | 
                                                        |
| 169 | - 'primary_registration_details',  | 
                                                        |
| 170 | - 'recipient_details',  | 
                                                        |
| 171 | - ),  | 
                                                        |
| 172 | -                'required'   => array('[TICKET_LIST]'), | 
                                                        |
| 173 | - ),  | 
                                                        |
| 174 | - 'datetime_list' => array(  | 
                                                        |
| 175 | -                'shortcodes' => array('datetime'), | 
                                                        |
| 176 | -                'required'   => array('[DATETIME_LIST]'), | 
                                                        |
| 177 | - ),  | 
                                                        |
| 178 | - );  | 
                                                        |
| 179 | - }  | 
                                                        |
| 180 | -  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - /**  | 
                                                        |
| 183 | - * @see parent EE_messenger class for docs  | 
                                                        |
| 184 | - * @since 4.5.0  | 
                                                        |
| 185 | - */  | 
                                                        |
| 186 | - public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 187 | -    { | 
                                                        |
| 188 | -        if ($sending_messenger_name = 'html') { | 
                                                        |
| 189 | -            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | -  | 
                                                        |
| 193 | -  | 
                                                        |
| 194 | - public function add_email_css(  | 
                                                        |
| 195 | - $variation_path,  | 
                                                        |
| 196 | - $messenger,  | 
                                                        |
| 197 | - $message_type,  | 
                                                        |
| 198 | - $type,  | 
                                                        |
| 199 | - $variation,  | 
                                                        |
| 200 | - $file_extension,  | 
                                                        |
| 201 | - $url,  | 
                                                        |
| 202 | - EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 203 | -    ) { | 
                                                        |
| 204 | - //prevent recursion on this callback.  | 
                                                        |
| 205 | -        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); | 
                                                        |
| 206 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | -        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 209 | - return $variation;  | 
                                                        |
| 210 | - }  | 
                                                        |
| 211 | -  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - /**  | 
                                                        |
| 214 | - * See parent for details  | 
                                                        |
| 215 | - *  | 
                                                        |
| 216 | - * @access protected  | 
                                                        |
| 217 | - * @return void  | 
                                                        |
| 218 | - */  | 
                                                        |
| 219 | - protected function _set_test_settings_fields()  | 
                                                        |
| 220 | -    { | 
                                                        |
| 221 | - $this->_test_settings_fields = array(  | 
                                                        |
| 222 | - 'to' => array(  | 
                                                        |
| 223 | - 'input' => 'text',  | 
                                                        |
| 224 | -                'label'      => esc_html__('Send a test email to', 'event_espresso'), | 
                                                        |
| 225 | - 'type' => 'email',  | 
                                                        |
| 226 | - 'required' => true,  | 
                                                        |
| 227 | - 'validation' => true,  | 
                                                        |
| 228 | - 'css_class' => 'large-text',  | 
                                                        |
| 229 | - 'format' => '%s',  | 
                                                        |
| 230 | -                'default'    => get_bloginfo('admin_email'), | 
                                                        |
| 231 | - ),  | 
                                                        |
| 232 | - 'subject' => array(  | 
                                                        |
| 233 | - 'input' => 'hidden',  | 
                                                        |
| 234 | - 'label' => '',  | 
                                                        |
| 235 | - 'type' => 'string',  | 
                                                        |
| 236 | - 'required' => false,  | 
                                                        |
| 237 | - 'validation' => false,  | 
                                                        |
| 238 | - 'format' => '%s',  | 
                                                        |
| 239 | -                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), | 
                                                        |
| 240 | - 'default' => '',  | 
                                                        |
| 241 | - 'css_class' => '',  | 
                                                        |
| 242 | - ),  | 
                                                        |
| 243 | - );  | 
                                                        |
| 244 | - }  | 
                                                        |
| 245 | -  | 
                                                        |
| 246 | -  | 
                                                        |
| 247 | - /**  | 
                                                        |
| 248 | - * _set_template_fields  | 
                                                        |
| 249 | - * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 250 | - *  | 
                                                        |
| 251 | - * @access protected  | 
                                                        |
| 252 | - * @return void  | 
                                                        |
| 253 | - */  | 
                                                        |
| 254 | - protected function _set_template_fields()  | 
                                                        |
| 255 | -    { | 
                                                        |
| 256 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for  | 
                                                        |
| 257 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field  | 
                                                        |
| 258 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 259 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what  | 
                                                        |
| 260 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array  | 
                                                        |
| 261 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be  | 
                                                        |
| 262 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and  | 
                                                        |
| 263 | - // will not be displayed/parsed.  | 
                                                        |
| 264 | - $this->_template_fields = array(  | 
                                                        |
| 265 | - 'to' => array(  | 
                                                        |
| 266 | - 'input' => 'text',  | 
                                                        |
| 267 | - 'label' => esc_html_x(  | 
                                                        |
| 268 | - 'To',  | 
                                                        |
| 269 | - 'Label for the "To" field for email addresses',  | 
                                                        |
| 270 | - 'event_espresso'  | 
                                                        |
| 271 | - ),  | 
                                                        |
| 272 | - 'type' => 'string',  | 
                                                        |
| 273 | - 'required' => true,  | 
                                                        |
| 274 | - 'validation' => true,  | 
                                                        |
| 275 | - 'css_class' => 'large-text',  | 
                                                        |
| 276 | - 'format' => '%s',  | 
                                                        |
| 277 | - ),  | 
                                                        |
| 278 | - 'cc' => array(  | 
                                                        |
| 279 | - 'input' => 'text',  | 
                                                        |
| 280 | - 'label' => esc_html_x(  | 
                                                        |
| 281 | - 'CC',  | 
                                                        |
| 282 | - 'Label for the "Carbon Copy" field used for additional email addresses',  | 
                                                        |
| 283 | - 'event_espresso'  | 
                                                        |
| 284 | - ),  | 
                                                        |
| 285 | - 'type' => 'string',  | 
                                                        |
| 286 | - 'required' => false,  | 
                                                        |
| 287 | - 'validation' => true,  | 
                                                        |
| 288 | - 'css_class' => 'large-text',  | 
                                                        |
| 289 | - 'format' => '%s',  | 
                                                        |
| 290 | - ),  | 
                                                        |
| 291 | - 'from' => array(  | 
                                                        |
| 292 | - 'input' => 'text',  | 
                                                        |
| 293 | - 'label' => esc_html_x(  | 
                                                        |
| 294 | - 'From',  | 
                                                        |
| 295 | - 'Label for the "From" field for email addresses.',  | 
                                                        |
| 296 | - 'event_espresso'  | 
                                                        |
| 297 | - ),  | 
                                                        |
| 298 | - 'type' => 'string',  | 
                                                        |
| 299 | - 'required' => true,  | 
                                                        |
| 300 | - 'validation' => true,  | 
                                                        |
| 301 | - 'css_class' => 'large-text',  | 
                                                        |
| 302 | - 'format' => '%s',  | 
                                                        |
| 303 | - ),  | 
                                                        |
| 304 | - 'subject' => array(  | 
                                                        |
| 305 | - 'input' => 'text',  | 
                                                        |
| 306 | - 'label' => esc_html_x(  | 
                                                        |
| 307 | - 'Subject',  | 
                                                        |
| 308 | - 'Label for the "Subject" field (short description of contents) for emails.',  | 
                                                        |
| 309 | - 'event_espresso'  | 
                                                        |
| 310 | - ),  | 
                                                        |
| 311 | - 'type' => 'string',  | 
                                                        |
| 312 | - 'required' => true,  | 
                                                        |
| 313 | - 'validation' => true,  | 
                                                        |
| 314 | - 'css_class' => 'large-text',  | 
                                                        |
| 315 | - 'format' => '%s',  | 
                                                        |
| 316 | - ),  | 
                                                        |
| 317 | - 'content' => '',  | 
                                                        |
| 318 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 319 | - 'extra' => array(  | 
                                                        |
| 320 | - 'content' => array(  | 
                                                        |
| 321 | - 'main' => array(  | 
                                                        |
| 322 | - 'input' => 'wp_editor',  | 
                                                        |
| 323 | -                        'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 324 | - 'type' => 'string',  | 
                                                        |
| 325 | - 'required' => true,  | 
                                                        |
| 326 | - 'validation' => true,  | 
                                                        |
| 327 | - 'format' => '%s',  | 
                                                        |
| 328 | - 'rows' => '15',  | 
                                                        |
| 329 | - ),  | 
                                                        |
| 330 | - 'event_list' => array(  | 
                                                        |
| 331 | - 'input' => 'wp_editor',  | 
                                                        |
| 332 | - 'label' => '[EVENT_LIST]',  | 
                                                        |
| 333 | - 'type' => 'string',  | 
                                                        |
| 334 | - 'required' => true,  | 
                                                        |
| 335 | - 'validation' => true,  | 
                                                        |
| 336 | - 'format' => '%s',  | 
                                                        |
| 337 | - 'rows' => '15',  | 
                                                        |
| 338 | -                        'shortcodes_required' => array('[EVENT_LIST]'), | 
                                                        |
| 339 | - ),  | 
                                                        |
| 340 | - 'attendee_list' => array(  | 
                                                        |
| 341 | - 'input' => 'textarea',  | 
                                                        |
| 342 | - 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 343 | - 'type' => 'string',  | 
                                                        |
| 344 | - 'required' => true,  | 
                                                        |
| 345 | - 'validation' => true,  | 
                                                        |
| 346 | - 'format' => '%s',  | 
                                                        |
| 347 | - 'css_class' => 'large-text',  | 
                                                        |
| 348 | - 'rows' => '5',  | 
                                                        |
| 349 | -                        'shortcodes_required' => array('[ATTENDEE_LIST]'), | 
                                                        |
| 350 | - ),  | 
                                                        |
| 351 | - 'ticket_list' => array(  | 
                                                        |
| 352 | - 'input' => 'textarea',  | 
                                                        |
| 353 | - 'label' => '[TICKET_LIST]',  | 
                                                        |
| 354 | - 'type' => 'string',  | 
                                                        |
| 355 | - 'required' => true,  | 
                                                        |
| 356 | - 'validation' => true,  | 
                                                        |
| 357 | - 'format' => '%s',  | 
                                                        |
| 358 | - 'css_class' => 'large-text',  | 
                                                        |
| 359 | - 'rows' => '10',  | 
                                                        |
| 360 | -                        'shortcodes_required' => array('[TICKET_LIST]'), | 
                                                        |
| 361 | - ),  | 
                                                        |
| 362 | - 'datetime_list' => array(  | 
                                                        |
| 363 | - 'input' => 'textarea',  | 
                                                        |
| 364 | - 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 365 | - 'type' => 'string',  | 
                                                        |
| 366 | - 'required' => true,  | 
                                                        |
| 367 | - 'validation' => true,  | 
                                                        |
| 368 | - 'format' => '%s',  | 
                                                        |
| 369 | - 'css_class' => 'large-text',  | 
                                                        |
| 370 | - 'rows' => '10',  | 
                                                        |
| 371 | -                        'shortcodes_required' => array('[DATETIME_LIST]'), | 
                                                        |
| 372 | - ),  | 
                                                        |
| 373 | - ),  | 
                                                        |
| 374 | - ),  | 
                                                        |
| 375 | - );  | 
                                                        |
| 376 | - }  | 
                                                        |
| 377 | -  | 
                                                        |
| 378 | -  | 
                                                        |
| 379 | - /**  | 
                                                        |
| 380 | - * See definition of this class in parent  | 
                                                        |
| 381 | - */  | 
                                                        |
| 382 | - protected function _set_default_message_types()  | 
                                                        |
| 383 | -    { | 
                                                        |
| 384 | - $this->_default_message_types = array(  | 
                                                        |
| 385 | - 'payment',  | 
                                                        |
| 386 | - 'payment_refund',  | 
                                                        |
| 387 | - 'registration',  | 
                                                        |
| 388 | - 'not_approved_registration',  | 
                                                        |
| 389 | - 'pending_approval',  | 
                                                        |
| 390 | - );  | 
                                                        |
| 391 | - }  | 
                                                        |
| 392 | -  | 
                                                        |
| 393 | -  | 
                                                        |
| 394 | - /**  | 
                                                        |
| 395 | - * @see definition of this class in parent  | 
                                                        |
| 396 | - * @since 4.5.0  | 
                                                        |
| 397 | - */  | 
                                                        |
| 398 | - protected function _set_valid_message_types()  | 
                                                        |
| 399 | -    { | 
                                                        |
| 400 | - $this->_valid_message_types = array(  | 
                                                        |
| 401 | - 'payment',  | 
                                                        |
| 402 | - 'registration',  | 
                                                        |
| 403 | - 'not_approved_registration',  | 
                                                        |
| 404 | - 'declined_registration',  | 
                                                        |
| 405 | - 'cancelled_registration',  | 
                                                        |
| 406 | - 'pending_approval',  | 
                                                        |
| 407 | - 'registration_summary',  | 
                                                        |
| 408 | - 'payment_reminder',  | 
                                                        |
| 409 | - 'payment_declined',  | 
                                                        |
| 410 | - 'payment_refund',  | 
                                                        |
| 411 | - );  | 
                                                        |
| 412 | - }  | 
                                                        |
| 413 | -  | 
                                                        |
| 414 | -  | 
                                                        |
| 415 | - /**  | 
                                                        |
| 416 | - * setting up admin_settings_fields for messenger.  | 
                                                        |
| 417 | - */  | 
                                                        |
| 418 | - protected function _set_admin_settings_fields()  | 
                                                        |
| 419 | -    { | 
                                                        |
| 420 | - }  | 
                                                        |
| 421 | -  | 
                                                        |
| 422 | - /**  | 
                                                        |
| 423 | - * We just deliver the messages don't kill us!!  | 
                                                        |
| 424 | - *  | 
                                                        |
| 425 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if  | 
                                                        |
| 426 | - * present.  | 
                                                        |
| 427 | - * @throws EE_Error  | 
                                                        |
| 428 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 429 | - */  | 
                                                        |
| 430 | - protected function _send_message()  | 
                                                        |
| 431 | -    { | 
                                                        |
| 432 | - $success = wp_mail(  | 
                                                        |
| 433 | - html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),  | 
                                                        |
| 434 | - stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),  | 
                                                        |
| 435 | - $this->_body(),  | 
                                                        |
| 436 | - $this->_headers()  | 
                                                        |
| 437 | - );  | 
                                                        |
| 438 | -        if (! $success) { | 
                                                        |
| 439 | - EE_Error::add_error(  | 
                                                        |
| 440 | - sprintf(  | 
                                                        |
| 441 | - esc_html__(  | 
                                                        |
| 442 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',  | 
                                                        |
| 443 | - 'event_espresso'  | 
                                                        |
| 444 | - ),  | 
                                                        |
| 445 | - $this->_to,  | 
                                                        |
| 446 | - $this->_from,  | 
                                                        |
| 447 | - '<br />'  | 
                                                        |
| 448 | - ),  | 
                                                        |
| 449 | - __FILE__,  | 
                                                        |
| 450 | - __FUNCTION__,  | 
                                                        |
| 451 | - __LINE__  | 
                                                        |
| 452 | - );  | 
                                                        |
| 453 | - }  | 
                                                        |
| 454 | - return $success;  | 
                                                        |
| 455 | - }  | 
                                                        |
| 456 | -  | 
                                                        |
| 457 | -  | 
                                                        |
| 458 | - /**  | 
                                                        |
| 459 | - * see parent for definition  | 
                                                        |
| 460 | - *  | 
                                                        |
| 461 | - * @return string html body of the message content and the related css.  | 
                                                        |
| 462 | - * @throws EE_Error  | 
                                                        |
| 463 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 464 | - */  | 
                                                        |
| 465 | - protected function _preview()  | 
                                                        |
| 466 | -    { | 
                                                        |
| 467 | - return $this->_body(true);  | 
                                                        |
| 468 | - }  | 
                                                        |
| 469 | -  | 
                                                        |
| 470 | -  | 
                                                        |
| 471 | - /**  | 
                                                        |
| 472 | - * Setup headers for email  | 
                                                        |
| 473 | - *  | 
                                                        |
| 474 | - * @access protected  | 
                                                        |
| 475 | - * @return string formatted header for email  | 
                                                        |
| 476 | - */  | 
                                                        |
| 477 | - protected function _headers()  | 
                                                        |
| 478 | -    { | 
                                                        |
| 479 | - $this->_ensure_has_from_email_address();  | 
                                                        |
| 480 | - $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));  | 
                                                        |
| 481 | - $headers = array(  | 
                                                        |
| 482 | - 'MIME-Version: 1.0',  | 
                                                        |
| 483 | - 'From:' . $from,  | 
                                                        |
| 484 | - 'Reply-To:' . $from,  | 
                                                        |
| 485 | - 'Content-Type:text/html; charset=utf-8',  | 
                                                        |
| 486 | - );  | 
                                                        |
| 487 | -  | 
                                                        |
| 488 | -        if (! empty($this->_cc)) { | 
                                                        |
| 489 | - $headers[] = 'cc: ' . $this->_cc;  | 
                                                        |
| 490 | - }  | 
                                                        |
| 491 | -  | 
                                                        |
| 492 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the  | 
                                                        |
| 493 | - // header.  | 
                                                        |
| 494 | -        add_filter('wp_mail_from', array($this, 'set_from_address'), 100); | 
                                                        |
| 495 | -        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); | 
                                                        |
| 496 | -        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); | 
                                                        |
| 497 | - }  | 
                                                        |
| 498 | -  | 
                                                        |
| 499 | -  | 
                                                        |
| 500 | - /**  | 
                                                        |
| 501 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email  | 
                                                        |
| 502 | - * address for the from address to avoid problems with sending emails.  | 
                                                        |
| 503 | - */  | 
                                                        |
| 504 | - protected function _ensure_has_from_email_address()  | 
                                                        |
| 505 | -    { | 
                                                        |
| 506 | -        if (empty($this->_from)) { | 
                                                        |
| 507 | -            $this->_from = get_bloginfo('admin_email'); | 
                                                        |
| 508 | - }  | 
                                                        |
| 509 | - }  | 
                                                        |
| 510 | -  | 
                                                        |
| 511 | -  | 
                                                        |
| 512 | - /**  | 
                                                        |
| 513 | -     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> | 
                                                        |
| 514 | -     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* | 
                                                        |
| 515 | - * be empty  | 
                                                        |
| 516 | - *  | 
                                                        |
| 517 | - * @since 4.3.1  | 
                                                        |
| 518 | - * @return array  | 
                                                        |
| 519 | - */  | 
                                                        |
| 520 | - private function _parse_from()  | 
                                                        |
| 521 | -    { | 
                                                        |
| 522 | -        if (strpos($this->_from, '<') !== false) { | 
                                                        |
| 523 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);  | 
                                                        |
| 524 | -            $from_name = str_replace('"', '', $from_name); | 
                                                        |
| 525 | - $from_name = trim($from_name);  | 
                                                        |
| 526 | -  | 
                                                        |
| 527 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1);  | 
                                                        |
| 528 | -            $from_email = str_replace('>', '', $from_email); | 
                                                        |
| 529 | - $from_email = trim($from_email);  | 
                                                        |
| 530 | -        } elseif (trim($this->_from) !== '') { | 
                                                        |
| 531 | - $from_name = '';  | 
                                                        |
| 532 | - $from_email = trim($this->_from);  | 
                                                        |
| 533 | -        } else { | 
                                                        |
| 534 | - $from_name = $from_email = '';  | 
                                                        |
| 535 | - }  | 
                                                        |
| 536 | - return array($from_name, $from_email);  | 
                                                        |
| 537 | - }  | 
                                                        |
| 538 | -  | 
                                                        |
| 539 | -  | 
                                                        |
| 540 | - /**  | 
                                                        |
| 541 | - * Callback for the wp_mail_from filter.  | 
                                                        |
| 542 | - *  | 
                                                        |
| 543 | - * @since 4.3.1  | 
                                                        |
| 544 | - * @param string $from_email What the original from_email is.  | 
                                                        |
| 545 | - * @return string  | 
                                                        |
| 546 | - */  | 
                                                        |
| 547 | - public function set_from_address($from_email)  | 
                                                        |
| 548 | -    { | 
                                                        |
| 549 | - $parsed_from = $this->_parse_from();  | 
                                                        |
| 550 | - //includes fallback if the parsing failed.  | 
                                                        |
| 551 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1])  | 
                                                        |
| 552 | - ? $parsed_from[1]  | 
                                                        |
| 553 | -            : get_bloginfo('admin_email'); | 
                                                        |
| 554 | - return $from_email;  | 
                                                        |
| 555 | - }  | 
                                                        |
| 556 | -  | 
                                                        |
| 557 | -  | 
                                                        |
| 558 | - /**  | 
                                                        |
| 559 | - * Callback fro the wp_mail_from_name filter.  | 
                                                        |
| 560 | - *  | 
                                                        |
| 561 | - * @since 4.3.1  | 
                                                        |
| 562 | - * @param string $from_name The original from_name.  | 
                                                        |
| 563 | - * @return string  | 
                                                        |
| 564 | - */  | 
                                                        |
| 565 | - public function set_from_name($from_name)  | 
                                                        |
| 566 | -    { | 
                                                        |
| 567 | - $parsed_from = $this->_parse_from();  | 
                                                        |
| 568 | -        if (is_array($parsed_from) && ! empty($parsed_from[0])) { | 
                                                        |
| 569 | - $from_name = $parsed_from[0];  | 
                                                        |
| 570 | - }  | 
                                                        |
| 571 | -  | 
                                                        |
| 572 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!)  | 
                                                        |
| 573 | - $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;  | 
                                                        |
| 574 | -  | 
                                                        |
| 575 | - return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));  | 
                                                        |
| 576 | - }  | 
                                                        |
| 577 | -  | 
                                                        |
| 578 | -  | 
                                                        |
| 579 | - /**  | 
                                                        |
| 580 | - * setup body for email  | 
                                                        |
| 581 | - *  | 
                                                        |
| 582 | - * @param bool $preview will determine whether this is preview template or not.  | 
                                                        |
| 583 | - * @return string formatted body for email.  | 
                                                        |
| 584 | - * @throws EE_Error  | 
                                                        |
| 585 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 586 | - */  | 
                                                        |
| 587 | - protected function _body($preview = false)  | 
                                                        |
| 588 | -    { | 
                                                        |
| 589 | - //setup template args!  | 
                                                        |
| 590 | - $this->_template_args = array(  | 
                                                        |
| 591 | - 'subject' => $this->_subject,  | 
                                                        |
| 592 | - 'from' => $this->_from,  | 
                                                        |
| 593 | - 'main_body' => wpautop(  | 
                                                        |
| 594 | - stripslashes_deep(  | 
                                                        |
| 595 | - html_entity_decode($this->_content, ENT_QUOTES, "UTF-8")  | 
                                                        |
| 596 | - )  | 
                                                        |
| 597 | - ),  | 
                                                        |
| 598 | - );  | 
                                                        |
| 599 | - $body = $this->_get_main_template($preview);  | 
                                                        |
| 600 | -  | 
                                                        |
| 601 | - /**  | 
                                                        |
| 602 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.  | 
                                                        |
| 603 | - *  | 
                                                        |
| 604 | - * @type bool $preview Indicates whether a preview is being generated or not.  | 
                                                        |
| 605 | - * @return bool true indicates to use the inliner, false bypasses it.  | 
                                                        |
| 606 | - */  | 
                                                        |
| 607 | -        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { | 
                                                        |
| 608 | - //require CssToInlineStyles library and its dependencies via composer autoloader  | 
                                                        |
| 609 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';  | 
                                                        |
| 610 | -  | 
                                                        |
| 611 | - //now if this isn't a preview, let's setup the body so it has inline styles  | 
                                                        |
| 612 | -            if (! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 613 | - $style = file_get_contents(  | 
                                                        |
| 614 | - $this->get_variation(  | 
                                                        |
| 615 | - $this->_tmp_pack,  | 
                                                        |
| 616 | - $this->_incoming_message_type->name,  | 
                                                        |
| 617 | - false,  | 
                                                        |
| 618 | - 'main',  | 
                                                        |
| 619 | - $this->_variation  | 
                                                        |
| 620 | - ),  | 
                                                        |
| 621 | - true  | 
                                                        |
| 622 | - );  | 
                                                        |
| 623 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);  | 
                                                        |
| 624 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that.  | 
                                                        |
| 625 | - $body = ltrim($CSS->convert(true), ">\n");  | 
                                                        |
| 626 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609  | 
                                                        |
| 627 | - $body = ltrim($body, "<?");  | 
                                                        |
| 628 | - }  | 
                                                        |
| 629 | -  | 
                                                        |
| 630 | - }  | 
                                                        |
| 631 | - return $body;  | 
                                                        |
| 632 | - }  | 
                                                        |
| 633 | -  | 
                                                        |
| 634 | -  | 
                                                        |
| 635 | - /**  | 
                                                        |
| 636 | - * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 637 | - *  | 
                                                        |
| 638 | - * @access public  | 
                                                        |
| 639 | - * @return array  | 
                                                        |
| 640 | - */  | 
                                                        |
| 641 | - public function get_existing_test_settings()  | 
                                                        |
| 642 | -    { | 
                                                        |
| 643 | - $settings = parent::get_existing_test_settings();  | 
                                                        |
| 644 | - //override subject if present because we always want it to be fresh.  | 
                                                        |
| 645 | -        if (is_array($settings) && ! empty($settings['subject'])) { | 
                                                        |
| 646 | -            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); | 
                                                        |
| 647 | - }  | 
                                                        |
| 648 | - return $settings;  | 
                                                        |
| 649 | - }  | 
                                                        |
| 11 | + /**  | 
                                                        |
| 12 | + * To field for email  | 
                                                        |
| 13 | + * @var string  | 
                                                        |
| 14 | + */  | 
                                                        |
| 15 | + protected $_to = '';  | 
                                                        |
| 16 | +  | 
                                                        |
| 17 | +  | 
                                                        |
| 18 | + /**  | 
                                                        |
| 19 | + * CC field for email.  | 
                                                        |
| 20 | + * @var string  | 
                                                        |
| 21 | + */  | 
                                                        |
| 22 | + protected $_cc = '';  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * From field for email  | 
                                                        |
| 26 | + * @var string  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + protected $_from = '';  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | +  | 
                                                        |
| 31 | + /**  | 
                                                        |
| 32 | + * Subject field for email  | 
                                                        |
| 33 | + * @var string  | 
                                                        |
| 34 | + */  | 
                                                        |
| 35 | + protected $_subject = '';  | 
                                                        |
| 36 | +  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + /**  | 
                                                        |
| 39 | + * Content field for email  | 
                                                        |
| 40 | + * @var string  | 
                                                        |
| 41 | + */  | 
                                                        |
| 42 | + protected $_content = '';  | 
                                                        |
| 43 | +  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /**  | 
                                                        |
| 46 | + * constructor  | 
                                                        |
| 47 | + *  | 
                                                        |
| 48 | + * @access public  | 
                                                        |
| 49 | + */  | 
                                                        |
| 50 | + public function __construct()  | 
                                                        |
| 51 | +	{ | 
                                                        |
| 52 | + //set name and description properties  | 
                                                        |
| 53 | + $this->name = 'email';  | 
                                                        |
| 54 | + $this->description = esc_html__(  | 
                                                        |
| 55 | + 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress',  | 
                                                        |
| 56 | + 'event_espresso'  | 
                                                        |
| 57 | + );  | 
                                                        |
| 58 | + $this->label = array(  | 
                                                        |
| 59 | +			'singular' => esc_html__('email', 'event_espresso'), | 
                                                        |
| 60 | +			'plural'   => esc_html__('emails', 'event_espresso'), | 
                                                        |
| 61 | + );  | 
                                                        |
| 62 | + $this->activate_on_install = true;  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other  | 
                                                        |
| 65 | + // properties  | 
                                                        |
| 66 | + parent::__construct();  | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + /**  | 
                                                        |
| 71 | + * see abstract declaration in parent class for details.  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + protected function _set_admin_pages()  | 
                                                        |
| 74 | +	{ | 
                                                        |
| 75 | + $this->admin_registered_pages = array(  | 
                                                        |
| 76 | + 'events_edit' => true,  | 
                                                        |
| 77 | + );  | 
                                                        |
| 78 | + }  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | + /**  | 
                                                        |
| 82 | + * see abstract declaration in parent class for details  | 
                                                        |
| 83 | + */  | 
                                                        |
| 84 | + protected function _set_valid_shortcodes()  | 
                                                        |
| 85 | +	{ | 
                                                        |
| 86 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the  | 
                                                        |
| 87 | + // message type.  | 
                                                        |
| 88 | + $this->_valid_shortcodes = array(  | 
                                                        |
| 89 | +			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 90 | +			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 91 | +			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 92 | + );  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * see abstract declaration in parent class for details  | 
                                                        |
| 98 | + *  | 
                                                        |
| 99 | + * @access protected  | 
                                                        |
| 100 | + * @return void  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + protected function _set_validator_config()  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | + $valid_shortcodes = $this->get_valid_shortcodes();  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | + $this->_validator_config = array(  | 
                                                        |
| 107 | + 'to' => array(  | 
                                                        |
| 108 | + 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 109 | + 'type' => 'email',  | 
                                                        |
| 110 | + ),  | 
                                                        |
| 111 | + 'cc' => array(  | 
                                                        |
| 112 | + 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 113 | + 'type' => 'email',  | 
                                                        |
| 114 | + ),  | 
                                                        |
| 115 | + 'from' => array(  | 
                                                        |
| 116 | + 'shortcodes' => $valid_shortcodes['from'],  | 
                                                        |
| 117 | + 'type' => 'email',  | 
                                                        |
| 118 | + ),  | 
                                                        |
| 119 | + 'subject' => array(  | 
                                                        |
| 120 | + 'shortcodes' => array(  | 
                                                        |
| 121 | + 'organization',  | 
                                                        |
| 122 | + 'primary_registration_details',  | 
                                                        |
| 123 | + 'event_author',  | 
                                                        |
| 124 | + 'primary_registration_details',  | 
                                                        |
| 125 | + 'recipient_details',  | 
                                                        |
| 126 | + ),  | 
                                                        |
| 127 | + ),  | 
                                                        |
| 128 | + 'content' => array(  | 
                                                        |
| 129 | + 'shortcodes' => array(  | 
                                                        |
| 130 | + 'event_list',  | 
                                                        |
| 131 | + 'attendee_list',  | 
                                                        |
| 132 | + 'ticket_list',  | 
                                                        |
| 133 | + 'organization',  | 
                                                        |
| 134 | + 'primary_registration_details',  | 
                                                        |
| 135 | + 'primary_registration_list',  | 
                                                        |
| 136 | + 'event_author',  | 
                                                        |
| 137 | + 'recipient_details',  | 
                                                        |
| 138 | + 'recipient_list',  | 
                                                        |
| 139 | + 'transaction',  | 
                                                        |
| 140 | + 'messenger',  | 
                                                        |
| 141 | + ),  | 
                                                        |
| 142 | + ),  | 
                                                        |
| 143 | + 'attendee_list' => array(  | 
                                                        |
| 144 | +				'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 145 | +				'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 146 | + ),  | 
                                                        |
| 147 | + 'event_list' => array(  | 
                                                        |
| 148 | + 'shortcodes' => array(  | 
                                                        |
| 149 | + 'event',  | 
                                                        |
| 150 | + 'attendee_list',  | 
                                                        |
| 151 | + 'ticket_list',  | 
                                                        |
| 152 | + 'venue',  | 
                                                        |
| 153 | + 'datetime_list',  | 
                                                        |
| 154 | + 'attendee',  | 
                                                        |
| 155 | + 'primary_registration_details',  | 
                                                        |
| 156 | + 'primary_registration_list',  | 
                                                        |
| 157 | + 'event_author',  | 
                                                        |
| 158 | + 'recipient_details',  | 
                                                        |
| 159 | + 'recipient_list',  | 
                                                        |
| 160 | + ),  | 
                                                        |
| 161 | +				'required'   => array('[EVENT_LIST]'), | 
                                                        |
| 162 | + ),  | 
                                                        |
| 163 | + 'ticket_list' => array(  | 
                                                        |
| 164 | + 'shortcodes' => array(  | 
                                                        |
| 165 | + 'event_list',  | 
                                                        |
| 166 | + 'attendee_list',  | 
                                                        |
| 167 | + 'ticket',  | 
                                                        |
| 168 | + 'datetime_list',  | 
                                                        |
| 169 | + 'primary_registration_details',  | 
                                                        |
| 170 | + 'recipient_details',  | 
                                                        |
| 171 | + ),  | 
                                                        |
| 172 | +				'required'   => array('[TICKET_LIST]'), | 
                                                        |
| 173 | + ),  | 
                                                        |
| 174 | + 'datetime_list' => array(  | 
                                                        |
| 175 | +				'shortcodes' => array('datetime'), | 
                                                        |
| 176 | +				'required'   => array('[DATETIME_LIST]'), | 
                                                        |
| 177 | + ),  | 
                                                        |
| 178 | + );  | 
                                                        |
| 179 | + }  | 
                                                        |
| 180 | +  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + /**  | 
                                                        |
| 183 | + * @see parent EE_messenger class for docs  | 
                                                        |
| 184 | + * @since 4.5.0  | 
                                                        |
| 185 | + */  | 
                                                        |
| 186 | + public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 187 | +	{ | 
                                                        |
| 188 | +		if ($sending_messenger_name = 'html') { | 
                                                        |
| 189 | +			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | +  | 
                                                        |
| 193 | +  | 
                                                        |
| 194 | + public function add_email_css(  | 
                                                        |
| 195 | + $variation_path,  | 
                                                        |
| 196 | + $messenger,  | 
                                                        |
| 197 | + $message_type,  | 
                                                        |
| 198 | + $type,  | 
                                                        |
| 199 | + $variation,  | 
                                                        |
| 200 | + $file_extension,  | 
                                                        |
| 201 | + $url,  | 
                                                        |
| 202 | + EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 203 | +	) { | 
                                                        |
| 204 | + //prevent recursion on this callback.  | 
                                                        |
| 205 | +		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); | 
                                                        |
| 206 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | +		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 209 | + return $variation;  | 
                                                        |
| 210 | + }  | 
                                                        |
| 211 | +  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + /**  | 
                                                        |
| 214 | + * See parent for details  | 
                                                        |
| 215 | + *  | 
                                                        |
| 216 | + * @access protected  | 
                                                        |
| 217 | + * @return void  | 
                                                        |
| 218 | + */  | 
                                                        |
| 219 | + protected function _set_test_settings_fields()  | 
                                                        |
| 220 | +	{ | 
                                                        |
| 221 | + $this->_test_settings_fields = array(  | 
                                                        |
| 222 | + 'to' => array(  | 
                                                        |
| 223 | + 'input' => 'text',  | 
                                                        |
| 224 | +				'label'      => esc_html__('Send a test email to', 'event_espresso'), | 
                                                        |
| 225 | + 'type' => 'email',  | 
                                                        |
| 226 | + 'required' => true,  | 
                                                        |
| 227 | + 'validation' => true,  | 
                                                        |
| 228 | + 'css_class' => 'large-text',  | 
                                                        |
| 229 | + 'format' => '%s',  | 
                                                        |
| 230 | +				'default'    => get_bloginfo('admin_email'), | 
                                                        |
| 231 | + ),  | 
                                                        |
| 232 | + 'subject' => array(  | 
                                                        |
| 233 | + 'input' => 'hidden',  | 
                                                        |
| 234 | + 'label' => '',  | 
                                                        |
| 235 | + 'type' => 'string',  | 
                                                        |
| 236 | + 'required' => false,  | 
                                                        |
| 237 | + 'validation' => false,  | 
                                                        |
| 238 | + 'format' => '%s',  | 
                                                        |
| 239 | +				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), | 
                                                        |
| 240 | + 'default' => '',  | 
                                                        |
| 241 | + 'css_class' => '',  | 
                                                        |
| 242 | + ),  | 
                                                        |
| 243 | + );  | 
                                                        |
| 244 | + }  | 
                                                        |
| 245 | +  | 
                                                        |
| 246 | +  | 
                                                        |
| 247 | + /**  | 
                                                        |
| 248 | + * _set_template_fields  | 
                                                        |
| 249 | + * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 250 | + *  | 
                                                        |
| 251 | + * @access protected  | 
                                                        |
| 252 | + * @return void  | 
                                                        |
| 253 | + */  | 
                                                        |
| 254 | + protected function _set_template_fields()  | 
                                                        |
| 255 | +	{ | 
                                                        |
| 256 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for  | 
                                                        |
| 257 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field  | 
                                                        |
| 258 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 259 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what  | 
                                                        |
| 260 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array  | 
                                                        |
| 261 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be  | 
                                                        |
| 262 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and  | 
                                                        |
| 263 | + // will not be displayed/parsed.  | 
                                                        |
| 264 | + $this->_template_fields = array(  | 
                                                        |
| 265 | + 'to' => array(  | 
                                                        |
| 266 | + 'input' => 'text',  | 
                                                        |
| 267 | + 'label' => esc_html_x(  | 
                                                        |
| 268 | + 'To',  | 
                                                        |
| 269 | + 'Label for the "To" field for email addresses',  | 
                                                        |
| 270 | + 'event_espresso'  | 
                                                        |
| 271 | + ),  | 
                                                        |
| 272 | + 'type' => 'string',  | 
                                                        |
| 273 | + 'required' => true,  | 
                                                        |
| 274 | + 'validation' => true,  | 
                                                        |
| 275 | + 'css_class' => 'large-text',  | 
                                                        |
| 276 | + 'format' => '%s',  | 
                                                        |
| 277 | + ),  | 
                                                        |
| 278 | + 'cc' => array(  | 
                                                        |
| 279 | + 'input' => 'text',  | 
                                                        |
| 280 | + 'label' => esc_html_x(  | 
                                                        |
| 281 | + 'CC',  | 
                                                        |
| 282 | + 'Label for the "Carbon Copy" field used for additional email addresses',  | 
                                                        |
| 283 | + 'event_espresso'  | 
                                                        |
| 284 | + ),  | 
                                                        |
| 285 | + 'type' => 'string',  | 
                                                        |
| 286 | + 'required' => false,  | 
                                                        |
| 287 | + 'validation' => true,  | 
                                                        |
| 288 | + 'css_class' => 'large-text',  | 
                                                        |
| 289 | + 'format' => '%s',  | 
                                                        |
| 290 | + ),  | 
                                                        |
| 291 | + 'from' => array(  | 
                                                        |
| 292 | + 'input' => 'text',  | 
                                                        |
| 293 | + 'label' => esc_html_x(  | 
                                                        |
| 294 | + 'From',  | 
                                                        |
| 295 | + 'Label for the "From" field for email addresses.',  | 
                                                        |
| 296 | + 'event_espresso'  | 
                                                        |
| 297 | + ),  | 
                                                        |
| 298 | + 'type' => 'string',  | 
                                                        |
| 299 | + 'required' => true,  | 
                                                        |
| 300 | + 'validation' => true,  | 
                                                        |
| 301 | + 'css_class' => 'large-text',  | 
                                                        |
| 302 | + 'format' => '%s',  | 
                                                        |
| 303 | + ),  | 
                                                        |
| 304 | + 'subject' => array(  | 
                                                        |
| 305 | + 'input' => 'text',  | 
                                                        |
| 306 | + 'label' => esc_html_x(  | 
                                                        |
| 307 | + 'Subject',  | 
                                                        |
| 308 | + 'Label for the "Subject" field (short description of contents) for emails.',  | 
                                                        |
| 309 | + 'event_espresso'  | 
                                                        |
| 310 | + ),  | 
                                                        |
| 311 | + 'type' => 'string',  | 
                                                        |
| 312 | + 'required' => true,  | 
                                                        |
| 313 | + 'validation' => true,  | 
                                                        |
| 314 | + 'css_class' => 'large-text',  | 
                                                        |
| 315 | + 'format' => '%s',  | 
                                                        |
| 316 | + ),  | 
                                                        |
| 317 | + 'content' => '',  | 
                                                        |
| 318 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 319 | + 'extra' => array(  | 
                                                        |
| 320 | + 'content' => array(  | 
                                                        |
| 321 | + 'main' => array(  | 
                                                        |
| 322 | + 'input' => 'wp_editor',  | 
                                                        |
| 323 | +						'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 324 | + 'type' => 'string',  | 
                                                        |
| 325 | + 'required' => true,  | 
                                                        |
| 326 | + 'validation' => true,  | 
                                                        |
| 327 | + 'format' => '%s',  | 
                                                        |
| 328 | + 'rows' => '15',  | 
                                                        |
| 329 | + ),  | 
                                                        |
| 330 | + 'event_list' => array(  | 
                                                        |
| 331 | + 'input' => 'wp_editor',  | 
                                                        |
| 332 | + 'label' => '[EVENT_LIST]',  | 
                                                        |
| 333 | + 'type' => 'string',  | 
                                                        |
| 334 | + 'required' => true,  | 
                                                        |
| 335 | + 'validation' => true,  | 
                                                        |
| 336 | + 'format' => '%s',  | 
                                                        |
| 337 | + 'rows' => '15',  | 
                                                        |
| 338 | +						'shortcodes_required' => array('[EVENT_LIST]'), | 
                                                        |
| 339 | + ),  | 
                                                        |
| 340 | + 'attendee_list' => array(  | 
                                                        |
| 341 | + 'input' => 'textarea',  | 
                                                        |
| 342 | + 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 343 | + 'type' => 'string',  | 
                                                        |
| 344 | + 'required' => true,  | 
                                                        |
| 345 | + 'validation' => true,  | 
                                                        |
| 346 | + 'format' => '%s',  | 
                                                        |
| 347 | + 'css_class' => 'large-text',  | 
                                                        |
| 348 | + 'rows' => '5',  | 
                                                        |
| 349 | +						'shortcodes_required' => array('[ATTENDEE_LIST]'), | 
                                                        |
| 350 | + ),  | 
                                                        |
| 351 | + 'ticket_list' => array(  | 
                                                        |
| 352 | + 'input' => 'textarea',  | 
                                                        |
| 353 | + 'label' => '[TICKET_LIST]',  | 
                                                        |
| 354 | + 'type' => 'string',  | 
                                                        |
| 355 | + 'required' => true,  | 
                                                        |
| 356 | + 'validation' => true,  | 
                                                        |
| 357 | + 'format' => '%s',  | 
                                                        |
| 358 | + 'css_class' => 'large-text',  | 
                                                        |
| 359 | + 'rows' => '10',  | 
                                                        |
| 360 | +						'shortcodes_required' => array('[TICKET_LIST]'), | 
                                                        |
| 361 | + ),  | 
                                                        |
| 362 | + 'datetime_list' => array(  | 
                                                        |
| 363 | + 'input' => 'textarea',  | 
                                                        |
| 364 | + 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 365 | + 'type' => 'string',  | 
                                                        |
| 366 | + 'required' => true,  | 
                                                        |
| 367 | + 'validation' => true,  | 
                                                        |
| 368 | + 'format' => '%s',  | 
                                                        |
| 369 | + 'css_class' => 'large-text',  | 
                                                        |
| 370 | + 'rows' => '10',  | 
                                                        |
| 371 | +						'shortcodes_required' => array('[DATETIME_LIST]'), | 
                                                        |
| 372 | + ),  | 
                                                        |
| 373 | + ),  | 
                                                        |
| 374 | + ),  | 
                                                        |
| 375 | + );  | 
                                                        |
| 376 | + }  | 
                                                        |
| 377 | +  | 
                                                        |
| 378 | +  | 
                                                        |
| 379 | + /**  | 
                                                        |
| 380 | + * See definition of this class in parent  | 
                                                        |
| 381 | + */  | 
                                                        |
| 382 | + protected function _set_default_message_types()  | 
                                                        |
| 383 | +	{ | 
                                                        |
| 384 | + $this->_default_message_types = array(  | 
                                                        |
| 385 | + 'payment',  | 
                                                        |
| 386 | + 'payment_refund',  | 
                                                        |
| 387 | + 'registration',  | 
                                                        |
| 388 | + 'not_approved_registration',  | 
                                                        |
| 389 | + 'pending_approval',  | 
                                                        |
| 390 | + );  | 
                                                        |
| 391 | + }  | 
                                                        |
| 392 | +  | 
                                                        |
| 393 | +  | 
                                                        |
| 394 | + /**  | 
                                                        |
| 395 | + * @see definition of this class in parent  | 
                                                        |
| 396 | + * @since 4.5.0  | 
                                                        |
| 397 | + */  | 
                                                        |
| 398 | + protected function _set_valid_message_types()  | 
                                                        |
| 399 | +	{ | 
                                                        |
| 400 | + $this->_valid_message_types = array(  | 
                                                        |
| 401 | + 'payment',  | 
                                                        |
| 402 | + 'registration',  | 
                                                        |
| 403 | + 'not_approved_registration',  | 
                                                        |
| 404 | + 'declined_registration',  | 
                                                        |
| 405 | + 'cancelled_registration',  | 
                                                        |
| 406 | + 'pending_approval',  | 
                                                        |
| 407 | + 'registration_summary',  | 
                                                        |
| 408 | + 'payment_reminder',  | 
                                                        |
| 409 | + 'payment_declined',  | 
                                                        |
| 410 | + 'payment_refund',  | 
                                                        |
| 411 | + );  | 
                                                        |
| 412 | + }  | 
                                                        |
| 413 | +  | 
                                                        |
| 414 | +  | 
                                                        |
| 415 | + /**  | 
                                                        |
| 416 | + * setting up admin_settings_fields for messenger.  | 
                                                        |
| 417 | + */  | 
                                                        |
| 418 | + protected function _set_admin_settings_fields()  | 
                                                        |
| 419 | +	{ | 
                                                        |
| 420 | + }  | 
                                                        |
| 421 | +  | 
                                                        |
| 422 | + /**  | 
                                                        |
| 423 | + * We just deliver the messages don't kill us!!  | 
                                                        |
| 424 | + *  | 
                                                        |
| 425 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if  | 
                                                        |
| 426 | + * present.  | 
                                                        |
| 427 | + * @throws EE_Error  | 
                                                        |
| 428 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 429 | + */  | 
                                                        |
| 430 | + protected function _send_message()  | 
                                                        |
| 431 | +	{ | 
                                                        |
| 432 | + $success = wp_mail(  | 
                                                        |
| 433 | + html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),  | 
                                                        |
| 434 | + stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),  | 
                                                        |
| 435 | + $this->_body(),  | 
                                                        |
| 436 | + $this->_headers()  | 
                                                        |
| 437 | + );  | 
                                                        |
| 438 | +		if (! $success) { | 
                                                        |
| 439 | + EE_Error::add_error(  | 
                                                        |
| 440 | + sprintf(  | 
                                                        |
| 441 | + esc_html__(  | 
                                                        |
| 442 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',  | 
                                                        |
| 443 | + 'event_espresso'  | 
                                                        |
| 444 | + ),  | 
                                                        |
| 445 | + $this->_to,  | 
                                                        |
| 446 | + $this->_from,  | 
                                                        |
| 447 | + '<br />'  | 
                                                        |
| 448 | + ),  | 
                                                        |
| 449 | + __FILE__,  | 
                                                        |
| 450 | + __FUNCTION__,  | 
                                                        |
| 451 | + __LINE__  | 
                                                        |
| 452 | + );  | 
                                                        |
| 453 | + }  | 
                                                        |
| 454 | + return $success;  | 
                                                        |
| 455 | + }  | 
                                                        |
| 456 | +  | 
                                                        |
| 457 | +  | 
                                                        |
| 458 | + /**  | 
                                                        |
| 459 | + * see parent for definition  | 
                                                        |
| 460 | + *  | 
                                                        |
| 461 | + * @return string html body of the message content and the related css.  | 
                                                        |
| 462 | + * @throws EE_Error  | 
                                                        |
| 463 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 464 | + */  | 
                                                        |
| 465 | + protected function _preview()  | 
                                                        |
| 466 | +	{ | 
                                                        |
| 467 | + return $this->_body(true);  | 
                                                        |
| 468 | + }  | 
                                                        |
| 469 | +  | 
                                                        |
| 470 | +  | 
                                                        |
| 471 | + /**  | 
                                                        |
| 472 | + * Setup headers for email  | 
                                                        |
| 473 | + *  | 
                                                        |
| 474 | + * @access protected  | 
                                                        |
| 475 | + * @return string formatted header for email  | 
                                                        |
| 476 | + */  | 
                                                        |
| 477 | + protected function _headers()  | 
                                                        |
| 478 | +	{ | 
                                                        |
| 479 | + $this->_ensure_has_from_email_address();  | 
                                                        |
| 480 | + $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));  | 
                                                        |
| 481 | + $headers = array(  | 
                                                        |
| 482 | + 'MIME-Version: 1.0',  | 
                                                        |
| 483 | + 'From:' . $from,  | 
                                                        |
| 484 | + 'Reply-To:' . $from,  | 
                                                        |
| 485 | + 'Content-Type:text/html; charset=utf-8',  | 
                                                        |
| 486 | + );  | 
                                                        |
| 487 | +  | 
                                                        |
| 488 | +		if (! empty($this->_cc)) { | 
                                                        |
| 489 | + $headers[] = 'cc: ' . $this->_cc;  | 
                                                        |
| 490 | + }  | 
                                                        |
| 491 | +  | 
                                                        |
| 492 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the  | 
                                                        |
| 493 | + // header.  | 
                                                        |
| 494 | +		add_filter('wp_mail_from', array($this, 'set_from_address'), 100); | 
                                                        |
| 495 | +		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); | 
                                                        |
| 496 | +		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); | 
                                                        |
| 497 | + }  | 
                                                        |
| 498 | +  | 
                                                        |
| 499 | +  | 
                                                        |
| 500 | + /**  | 
                                                        |
| 501 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email  | 
                                                        |
| 502 | + * address for the from address to avoid problems with sending emails.  | 
                                                        |
| 503 | + */  | 
                                                        |
| 504 | + protected function _ensure_has_from_email_address()  | 
                                                        |
| 505 | +	{ | 
                                                        |
| 506 | +		if (empty($this->_from)) { | 
                                                        |
| 507 | +			$this->_from = get_bloginfo('admin_email'); | 
                                                        |
| 508 | + }  | 
                                                        |
| 509 | + }  | 
                                                        |
| 510 | +  | 
                                                        |
| 511 | +  | 
                                                        |
| 512 | + /**  | 
                                                        |
| 513 | +	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> | 
                                                        |
| 514 | +	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* | 
                                                        |
| 515 | + * be empty  | 
                                                        |
| 516 | + *  | 
                                                        |
| 517 | + * @since 4.3.1  | 
                                                        |
| 518 | + * @return array  | 
                                                        |
| 519 | + */  | 
                                                        |
| 520 | + private function _parse_from()  | 
                                                        |
| 521 | +	{ | 
                                                        |
| 522 | +		if (strpos($this->_from, '<') !== false) { | 
                                                        |
| 523 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);  | 
                                                        |
| 524 | +			$from_name = str_replace('"', '', $from_name); | 
                                                        |
| 525 | + $from_name = trim($from_name);  | 
                                                        |
| 526 | +  | 
                                                        |
| 527 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1);  | 
                                                        |
| 528 | +			$from_email = str_replace('>', '', $from_email); | 
                                                        |
| 529 | + $from_email = trim($from_email);  | 
                                                        |
| 530 | +		} elseif (trim($this->_from) !== '') { | 
                                                        |
| 531 | + $from_name = '';  | 
                                                        |
| 532 | + $from_email = trim($this->_from);  | 
                                                        |
| 533 | +		} else { | 
                                                        |
| 534 | + $from_name = $from_email = '';  | 
                                                        |
| 535 | + }  | 
                                                        |
| 536 | + return array($from_name, $from_email);  | 
                                                        |
| 537 | + }  | 
                                                        |
| 538 | +  | 
                                                        |
| 539 | +  | 
                                                        |
| 540 | + /**  | 
                                                        |
| 541 | + * Callback for the wp_mail_from filter.  | 
                                                        |
| 542 | + *  | 
                                                        |
| 543 | + * @since 4.3.1  | 
                                                        |
| 544 | + * @param string $from_email What the original from_email is.  | 
                                                        |
| 545 | + * @return string  | 
                                                        |
| 546 | + */  | 
                                                        |
| 547 | + public function set_from_address($from_email)  | 
                                                        |
| 548 | +	{ | 
                                                        |
| 549 | + $parsed_from = $this->_parse_from();  | 
                                                        |
| 550 | + //includes fallback if the parsing failed.  | 
                                                        |
| 551 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1])  | 
                                                        |
| 552 | + ? $parsed_from[1]  | 
                                                        |
| 553 | +			: get_bloginfo('admin_email'); | 
                                                        |
| 554 | + return $from_email;  | 
                                                        |
| 555 | + }  | 
                                                        |
| 556 | +  | 
                                                        |
| 557 | +  | 
                                                        |
| 558 | + /**  | 
                                                        |
| 559 | + * Callback fro the wp_mail_from_name filter.  | 
                                                        |
| 560 | + *  | 
                                                        |
| 561 | + * @since 4.3.1  | 
                                                        |
| 562 | + * @param string $from_name The original from_name.  | 
                                                        |
| 563 | + * @return string  | 
                                                        |
| 564 | + */  | 
                                                        |
| 565 | + public function set_from_name($from_name)  | 
                                                        |
| 566 | +	{ | 
                                                        |
| 567 | + $parsed_from = $this->_parse_from();  | 
                                                        |
| 568 | +		if (is_array($parsed_from) && ! empty($parsed_from[0])) { | 
                                                        |
| 569 | + $from_name = $parsed_from[0];  | 
                                                        |
| 570 | + }  | 
                                                        |
| 571 | +  | 
                                                        |
| 572 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!)  | 
                                                        |
| 573 | + $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name;  | 
                                                        |
| 574 | +  | 
                                                        |
| 575 | + return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));  | 
                                                        |
| 576 | + }  | 
                                                        |
| 577 | +  | 
                                                        |
| 578 | +  | 
                                                        |
| 579 | + /**  | 
                                                        |
| 580 | + * setup body for email  | 
                                                        |
| 581 | + *  | 
                                                        |
| 582 | + * @param bool $preview will determine whether this is preview template or not.  | 
                                                        |
| 583 | + * @return string formatted body for email.  | 
                                                        |
| 584 | + * @throws EE_Error  | 
                                                        |
| 585 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 586 | + */  | 
                                                        |
| 587 | + protected function _body($preview = false)  | 
                                                        |
| 588 | +	{ | 
                                                        |
| 589 | + //setup template args!  | 
                                                        |
| 590 | + $this->_template_args = array(  | 
                                                        |
| 591 | + 'subject' => $this->_subject,  | 
                                                        |
| 592 | + 'from' => $this->_from,  | 
                                                        |
| 593 | + 'main_body' => wpautop(  | 
                                                        |
| 594 | + stripslashes_deep(  | 
                                                        |
| 595 | + html_entity_decode($this->_content, ENT_QUOTES, "UTF-8")  | 
                                                        |
| 596 | + )  | 
                                                        |
| 597 | + ),  | 
                                                        |
| 598 | + );  | 
                                                        |
| 599 | + $body = $this->_get_main_template($preview);  | 
                                                        |
| 600 | +  | 
                                                        |
| 601 | + /**  | 
                                                        |
| 602 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.  | 
                                                        |
| 603 | + *  | 
                                                        |
| 604 | + * @type bool $preview Indicates whether a preview is being generated or not.  | 
                                                        |
| 605 | + * @return bool true indicates to use the inliner, false bypasses it.  | 
                                                        |
| 606 | + */  | 
                                                        |
| 607 | +		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { | 
                                                        |
| 608 | + //require CssToInlineStyles library and its dependencies via composer autoloader  | 
                                                        |
| 609 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';  | 
                                                        |
| 610 | +  | 
                                                        |
| 611 | + //now if this isn't a preview, let's setup the body so it has inline styles  | 
                                                        |
| 612 | +			if (! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 613 | + $style = file_get_contents(  | 
                                                        |
| 614 | + $this->get_variation(  | 
                                                        |
| 615 | + $this->_tmp_pack,  | 
                                                        |
| 616 | + $this->_incoming_message_type->name,  | 
                                                        |
| 617 | + false,  | 
                                                        |
| 618 | + 'main',  | 
                                                        |
| 619 | + $this->_variation  | 
                                                        |
| 620 | + ),  | 
                                                        |
| 621 | + true  | 
                                                        |
| 622 | + );  | 
                                                        |
| 623 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);  | 
                                                        |
| 624 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that.  | 
                                                        |
| 625 | + $body = ltrim($CSS->convert(true), ">\n");  | 
                                                        |
| 626 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609  | 
                                                        |
| 627 | + $body = ltrim($body, "<?");  | 
                                                        |
| 628 | + }  | 
                                                        |
| 629 | +  | 
                                                        |
| 630 | + }  | 
                                                        |
| 631 | + return $body;  | 
                                                        |
| 632 | + }  | 
                                                        |
| 633 | +  | 
                                                        |
| 634 | +  | 
                                                        |
| 635 | + /**  | 
                                                        |
| 636 | + * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 637 | + *  | 
                                                        |
| 638 | + * @access public  | 
                                                        |
| 639 | + * @return array  | 
                                                        |
| 640 | + */  | 
                                                        |
| 641 | + public function get_existing_test_settings()  | 
                                                        |
| 642 | +	{ | 
                                                        |
| 643 | + $settings = parent::get_existing_test_settings();  | 
                                                        |
| 644 | + //override subject if present because we always want it to be fresh.  | 
                                                        |
| 645 | +		if (is_array($settings) && ! empty($settings['subject'])) { | 
                                                        |
| 646 | +			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); | 
                                                        |
| 647 | + }  | 
                                                        |
| 648 | + return $settings;  | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | 650 | }  | 
                                                        
@@ -13,1095 +13,1095 @@  | 
                                                    ||
| 13 | 13 | class EED_Messages extends EED_Module  | 
                                                        
| 14 | 14 |  { | 
                                                        
| 15 | 15 | |
| 16 | - /**  | 
                                                        |
| 17 | - * This holds the EE_messages controller  | 
                                                        |
| 18 | - *  | 
                                                        |
| 19 | - * @deprecated 4.9.0  | 
                                                        |
| 20 | - * @var EE_messages $_EEMSG  | 
                                                        |
| 21 | - */  | 
                                                        |
| 22 | - protected static $_EEMSG;  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - /**  | 
                                                        |
| 25 | - * @type EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 26 | - */  | 
                                                        |
| 27 | - protected static $_message_resource_manager;  | 
                                                        |
| 28 | -  | 
                                                        |
| 29 | - /**  | 
                                                        |
| 30 | - * This holds the EE_Messages_Processor business class.  | 
                                                        |
| 31 | - *  | 
                                                        |
| 32 | - * @type EE_Messages_Processor  | 
                                                        |
| 33 | - */  | 
                                                        |
| 34 | - protected static $_MSG_PROCESSOR;  | 
                                                        |
| 35 | -  | 
                                                        |
| 36 | - /**  | 
                                                        |
| 37 | - * holds all the paths for various messages components.  | 
                                                        |
| 38 | - * Utilized by autoloader registry  | 
                                                        |
| 39 | - *  | 
                                                        |
| 40 | - * @var array  | 
                                                        |
| 41 | - */  | 
                                                        |
| 42 | - protected static $_MSG_PATHS;  | 
                                                        |
| 43 | -  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /**  | 
                                                        |
| 46 | - * This will hold an array of messages template packs that are registered in the messages system.  | 
                                                        |
| 47 | - * Format is:  | 
                                                        |
| 48 | - * array(  | 
                                                        |
| 49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance)  | 
                                                        |
| 50 | - * )  | 
                                                        |
| 51 | - *  | 
                                                        |
| 52 | - * @var EE_Messages_Template_Pack[]  | 
                                                        |
| 53 | - */  | 
                                                        |
| 54 | - protected static $_TMP_PACKS = array();  | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - /**  | 
                                                        |
| 58 | - * @return EED_Messages  | 
                                                        |
| 59 | - */  | 
                                                        |
| 60 | - public static function instance()  | 
                                                        |
| 61 | -    { | 
                                                        |
| 62 | - return parent::get_instance(__CLASS__);  | 
                                                        |
| 63 | - }  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - /**  | 
                                                        |
| 67 | - * set_hooks - for hooking into EE Core, other modules, etc  | 
                                                        |
| 68 | - *  | 
                                                        |
| 69 | - * @since 4.5.0  | 
                                                        |
| 70 | - * @return void  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | - public static function set_hooks()  | 
                                                        |
| 73 | -    { | 
                                                        |
| 74 | - //actions  | 
                                                        |
| 75 | -        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); | 
                                                        |
| 76 | -        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', | 
                                                        |
| 77 | -            array('EED_Messages', 'maybe_registration'), 10, 2); | 
                                                        |
| 78 | - //filters  | 
                                                        |
| 79 | -        add_filter('FHEE__EE_Registration__receipt_url__receipt_url', | 
                                                        |
| 80 | -            array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 81 | -        add_filter('FHEE__EE_Registration__invoice_url__invoice_url', | 
                                                        |
| 82 | -            array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 83 | - //register routes  | 
                                                        |
| 84 | - self::_register_routes();  | 
                                                        |
| 85 | - }  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - /**  | 
                                                        |
| 88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc  | 
                                                        |
| 89 | - *  | 
                                                        |
| 90 | - * @access public  | 
                                                        |
| 91 | - * @return void  | 
                                                        |
| 92 | - */  | 
                                                        |
| 93 | - public static function set_hooks_admin()  | 
                                                        |
| 94 | -    { | 
                                                        |
| 95 | - //actions  | 
                                                        |
| 96 | -        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); | 
                                                        |
| 97 | -        add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', | 
                                                        |
| 98 | -            array('EED_Messages', 'payment_reminder'), 10); | 
                                                        |
| 99 | -        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', | 
                                                        |
| 100 | -            array('EED_Messages', 'maybe_registration'), 10, 3); | 
                                                        |
| 101 | -        add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', | 
                                                        |
| 102 | -            array('EED_Messages', 'send_newsletter_message'), 10, 2); | 
                                                        |
| 103 | -        add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', | 
                                                        |
| 104 | -            array('EED_Messages', 'cancelled_registration'), 10); | 
                                                        |
| 105 | -        add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', | 
                                                        |
| 106 | -            array('EED_Messages', 'process_admin_payment'), 10, 1); | 
                                                        |
| 107 | - //filters  | 
                                                        |
| 108 | -        add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', | 
                                                        |
| 109 | -            array('EED_Messages', 'process_resend'), 10, 2); | 
                                                        |
| 110 | -        add_filter('FHEE__EE_Registration__receipt_url__receipt_url', | 
                                                        |
| 111 | -            array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 112 | -        add_filter('FHEE__EE_Registration__invoice_url__invoice_url', | 
                                                        |
| 113 | -            array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 114 | - }  | 
                                                        |
| 115 | -  | 
                                                        |
| 116 | -  | 
                                                        |
| 117 | - /**  | 
                                                        |
| 118 | - * All the message triggers done by route go in here.  | 
                                                        |
| 119 | - *  | 
                                                        |
| 120 | - * @since 4.5.0  | 
                                                        |
| 121 | - * @return void  | 
                                                        |
| 122 | - */  | 
                                                        |
| 123 | - protected static function _register_routes()  | 
                                                        |
| 124 | -    { | 
                                                        |
| 125 | -        EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); | 
                                                        |
| 126 | -        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); | 
                                                        |
| 127 | -        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); | 
                                                        |
| 128 | -        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); | 
                                                        |
| 129 | -        do_action('AHEE__EED_Messages___register_routes'); | 
                                                        |
| 130 | - }  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - /**  | 
                                                        |
| 134 | - * This is called when a browser display trigger is executed.  | 
                                                        |
| 135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the  | 
                                                        |
| 136 | - * browser.  | 
                                                        |
| 137 | - *  | 
                                                        |
| 138 | - * @since 4.9.0  | 
                                                        |
| 139 | - * @param WP $WP  | 
                                                        |
| 140 | - */  | 
                                                        |
| 141 | - public function browser_trigger($WP)  | 
                                                        |
| 142 | -    { | 
                                                        |
| 143 | - //ensure controller is loaded  | 
                                                        |
| 144 | - self::_load_controller();  | 
                                                        |
| 145 | -        $token = EE_Registry::instance()->REQ->get('token'); | 
                                                        |
| 146 | -        try { | 
                                                        |
| 147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);  | 
                                                        |
| 148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg);  | 
                                                        |
| 149 | -        } catch (EE_Error $e) { | 
                                                        |
| 150 | -            $error_msg = __('Please note that a system message failed to send due to a technical issue.', | 
                                                        |
| 151 | - 'event_espresso');  | 
                                                        |
| 152 | - // add specific message for developers if WP_DEBUG in on  | 
                                                        |
| 153 | - $error_msg .= '||' . $e->getMessage();  | 
                                                        |
| 154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 155 | - }  | 
                                                        |
| 156 | - }  | 
                                                        |
| 157 | -  | 
                                                        |
| 158 | -  | 
                                                        |
| 159 | - /**  | 
                                                        |
| 160 | - * This is called when a browser error trigger is executed.  | 
                                                        |
| 161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error  | 
                                                        |
| 162 | - * message and display it.  | 
                                                        |
| 163 | - *  | 
                                                        |
| 164 | - * @since 4.9.0  | 
                                                        |
| 165 | - * @param $WP  | 
                                                        |
| 166 | - */  | 
                                                        |
| 167 | - public function browser_error_trigger($WP)  | 
                                                        |
| 168 | -    { | 
                                                        |
| 169 | -        $token = EE_Registry::instance()->REQ->get('token'); | 
                                                        |
| 170 | -        if ($token) { | 
                                                        |
| 171 | - $message = EEM_Message::instance()->get_one_by_token($token);  | 
                                                        |
| 172 | -            if ($message instanceof EE_Message) { | 
                                                        |
| 173 | -                header('HTTP/1.1 200 OK'); | 
                                                        |
| 174 | - $error_msg = nl2br($message->error_message());  | 
                                                        |
| 175 | - ?>  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * This holds the EE_messages controller  | 
                                                        |
| 18 | + *  | 
                                                        |
| 19 | + * @deprecated 4.9.0  | 
                                                        |
| 20 | + * @var EE_messages $_EEMSG  | 
                                                        |
| 21 | + */  | 
                                                        |
| 22 | + protected static $_EEMSG;  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * @type EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 26 | + */  | 
                                                        |
| 27 | + protected static $_message_resource_manager;  | 
                                                        |
| 28 | +  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + * This holds the EE_Messages_Processor business class.  | 
                                                        |
| 31 | + *  | 
                                                        |
| 32 | + * @type EE_Messages_Processor  | 
                                                        |
| 33 | + */  | 
                                                        |
| 34 | + protected static $_MSG_PROCESSOR;  | 
                                                        |
| 35 | +  | 
                                                        |
| 36 | + /**  | 
                                                        |
| 37 | + * holds all the paths for various messages components.  | 
                                                        |
| 38 | + * Utilized by autoloader registry  | 
                                                        |
| 39 | + *  | 
                                                        |
| 40 | + * @var array  | 
                                                        |
| 41 | + */  | 
                                                        |
| 42 | + protected static $_MSG_PATHS;  | 
                                                        |
| 43 | +  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /**  | 
                                                        |
| 46 | + * This will hold an array of messages template packs that are registered in the messages system.  | 
                                                        |
| 47 | + * Format is:  | 
                                                        |
| 48 | + * array(  | 
                                                        |
| 49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance)  | 
                                                        |
| 50 | + * )  | 
                                                        |
| 51 | + *  | 
                                                        |
| 52 | + * @var EE_Messages_Template_Pack[]  | 
                                                        |
| 53 | + */  | 
                                                        |
| 54 | + protected static $_TMP_PACKS = array();  | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + /**  | 
                                                        |
| 58 | + * @return EED_Messages  | 
                                                        |
| 59 | + */  | 
                                                        |
| 60 | + public static function instance()  | 
                                                        |
| 61 | +	{ | 
                                                        |
| 62 | + return parent::get_instance(__CLASS__);  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * set_hooks - for hooking into EE Core, other modules, etc  | 
                                                        |
| 68 | + *  | 
                                                        |
| 69 | + * @since 4.5.0  | 
                                                        |
| 70 | + * @return void  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | + public static function set_hooks()  | 
                                                        |
| 73 | +	{ | 
                                                        |
| 74 | + //actions  | 
                                                        |
| 75 | +		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); | 
                                                        |
| 76 | +		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', | 
                                                        |
| 77 | +			array('EED_Messages', 'maybe_registration'), 10, 2); | 
                                                        |
| 78 | + //filters  | 
                                                        |
| 79 | +		add_filter('FHEE__EE_Registration__receipt_url__receipt_url', | 
                                                        |
| 80 | +			array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 81 | +		add_filter('FHEE__EE_Registration__invoice_url__invoice_url', | 
                                                        |
| 82 | +			array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 83 | + //register routes  | 
                                                        |
| 84 | + self::_register_routes();  | 
                                                        |
| 85 | + }  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + /**  | 
                                                        |
| 88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc  | 
                                                        |
| 89 | + *  | 
                                                        |
| 90 | + * @access public  | 
                                                        |
| 91 | + * @return void  | 
                                                        |
| 92 | + */  | 
                                                        |
| 93 | + public static function set_hooks_admin()  | 
                                                        |
| 94 | +	{ | 
                                                        |
| 95 | + //actions  | 
                                                        |
| 96 | +		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); | 
                                                        |
| 97 | +		add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', | 
                                                        |
| 98 | +			array('EED_Messages', 'payment_reminder'), 10); | 
                                                        |
| 99 | +		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', | 
                                                        |
| 100 | +			array('EED_Messages', 'maybe_registration'), 10, 3); | 
                                                        |
| 101 | +		add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', | 
                                                        |
| 102 | +			array('EED_Messages', 'send_newsletter_message'), 10, 2); | 
                                                        |
| 103 | +		add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', | 
                                                        |
| 104 | +			array('EED_Messages', 'cancelled_registration'), 10); | 
                                                        |
| 105 | +		add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', | 
                                                        |
| 106 | +			array('EED_Messages', 'process_admin_payment'), 10, 1); | 
                                                        |
| 107 | + //filters  | 
                                                        |
| 108 | +		add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', | 
                                                        |
| 109 | +			array('EED_Messages', 'process_resend'), 10, 2); | 
                                                        |
| 110 | +		add_filter('FHEE__EE_Registration__receipt_url__receipt_url', | 
                                                        |
| 111 | +			array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 112 | +		add_filter('FHEE__EE_Registration__invoice_url__invoice_url', | 
                                                        |
| 113 | +			array('EED_Messages', 'registration_message_trigger_url'), 10, 4); | 
                                                        |
| 114 | + }  | 
                                                        |
| 115 | +  | 
                                                        |
| 116 | +  | 
                                                        |
| 117 | + /**  | 
                                                        |
| 118 | + * All the message triggers done by route go in here.  | 
                                                        |
| 119 | + *  | 
                                                        |
| 120 | + * @since 4.5.0  | 
                                                        |
| 121 | + * @return void  | 
                                                        |
| 122 | + */  | 
                                                        |
| 123 | + protected static function _register_routes()  | 
                                                        |
| 124 | +	{ | 
                                                        |
| 125 | +		EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); | 
                                                        |
| 126 | +		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); | 
                                                        |
| 127 | +		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); | 
                                                        |
| 128 | +		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); | 
                                                        |
| 129 | +		do_action('AHEE__EED_Messages___register_routes'); | 
                                                        |
| 130 | + }  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + /**  | 
                                                        |
| 134 | + * This is called when a browser display trigger is executed.  | 
                                                        |
| 135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the  | 
                                                        |
| 136 | + * browser.  | 
                                                        |
| 137 | + *  | 
                                                        |
| 138 | + * @since 4.9.0  | 
                                                        |
| 139 | + * @param WP $WP  | 
                                                        |
| 140 | + */  | 
                                                        |
| 141 | + public function browser_trigger($WP)  | 
                                                        |
| 142 | +	{ | 
                                                        |
| 143 | + //ensure controller is loaded  | 
                                                        |
| 144 | + self::_load_controller();  | 
                                                        |
| 145 | +		$token = EE_Registry::instance()->REQ->get('token'); | 
                                                        |
| 146 | +		try { | 
                                                        |
| 147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);  | 
                                                        |
| 148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg);  | 
                                                        |
| 149 | +		} catch (EE_Error $e) { | 
                                                        |
| 150 | +			$error_msg = __('Please note that a system message failed to send due to a technical issue.', | 
                                                        |
| 151 | + 'event_espresso');  | 
                                                        |
| 152 | + // add specific message for developers if WP_DEBUG in on  | 
                                                        |
| 153 | + $error_msg .= '||' . $e->getMessage();  | 
                                                        |
| 154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 155 | + }  | 
                                                        |
| 156 | + }  | 
                                                        |
| 157 | +  | 
                                                        |
| 158 | +  | 
                                                        |
| 159 | + /**  | 
                                                        |
| 160 | + * This is called when a browser error trigger is executed.  | 
                                                        |
| 161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error  | 
                                                        |
| 162 | + * message and display it.  | 
                                                        |
| 163 | + *  | 
                                                        |
| 164 | + * @since 4.9.0  | 
                                                        |
| 165 | + * @param $WP  | 
                                                        |
| 166 | + */  | 
                                                        |
| 167 | + public function browser_error_trigger($WP)  | 
                                                        |
| 168 | +	{ | 
                                                        |
| 169 | +		$token = EE_Registry::instance()->REQ->get('token'); | 
                                                        |
| 170 | +		if ($token) { | 
                                                        |
| 171 | + $message = EEM_Message::instance()->get_one_by_token($token);  | 
                                                        |
| 172 | +			if ($message instanceof EE_Message) { | 
                                                        |
| 173 | +				header('HTTP/1.1 200 OK'); | 
                                                        |
| 174 | + $error_msg = nl2br($message->error_message());  | 
                                                        |
| 175 | + ?>  | 
                                                        |
| 176 | 176 | <!DOCTYPE html>  | 
                                                        
| 177 | 177 | <html>  | 
                                                        
| 178 | 178 | <head></head>  | 
                                                        
| 179 | 179 | <body>  | 
                                                        
| 180 | 180 | <?php echo empty($error_msg)  | 
                                                        
| 181 | -                    ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', | 
                                                        |
| 182 | - 'event_espresso')  | 
                                                        |
| 183 | - : wp_kses(  | 
                                                        |
| 184 | - $error_msg,  | 
                                                        |
| 185 | - array(  | 
                                                        |
| 186 | - 'a' => array(  | 
                                                        |
| 187 | - 'href' => array(),  | 
                                                        |
| 188 | - 'title' => array(),  | 
                                                        |
| 189 | - ),  | 
                                                        |
| 190 | - 'span' => array(),  | 
                                                        |
| 191 | - 'div' => array(),  | 
                                                        |
| 192 | - 'p' => array(),  | 
                                                        |
| 193 | - 'strong' => array(),  | 
                                                        |
| 194 | - 'em' => array(),  | 
                                                        |
| 195 | - 'br' => array(),  | 
                                                        |
| 196 | - )  | 
                                                        |
| 197 | - ); ?>  | 
                                                        |
| 181 | +					? esc_html__('Unfortunately, we were unable to capture the error message for this message.', | 
                                                        |
| 182 | + 'event_espresso')  | 
                                                        |
| 183 | + : wp_kses(  | 
                                                        |
| 184 | + $error_msg,  | 
                                                        |
| 185 | + array(  | 
                                                        |
| 186 | + 'a' => array(  | 
                                                        |
| 187 | + 'href' => array(),  | 
                                                        |
| 188 | + 'title' => array(),  | 
                                                        |
| 189 | + ),  | 
                                                        |
| 190 | + 'span' => array(),  | 
                                                        |
| 191 | + 'div' => array(),  | 
                                                        |
| 192 | + 'p' => array(),  | 
                                                        |
| 193 | + 'strong' => array(),  | 
                                                        |
| 194 | + 'em' => array(),  | 
                                                        |
| 195 | + 'br' => array(),  | 
                                                        |
| 196 | + )  | 
                                                        |
| 197 | + ); ?>  | 
                                                        |
| 198 | 198 | </body>  | 
                                                        
| 199 | 199 | </html>  | 
                                                        
| 200 | 200 | <?php  | 
                                                        
| 201 | - exit;  | 
                                                        |
| 202 | - }  | 
                                                        |
| 203 | - }  | 
                                                        |
| 204 | - return;  | 
                                                        |
| 205 | - }  | 
                                                        |
| 206 | -  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | - /**  | 
                                                        |
| 209 | - * This runs when the msg_url_trigger route has initiated.  | 
                                                        |
| 210 | - *  | 
                                                        |
| 211 | - * @since 4.5.0  | 
                                                        |
| 212 | - * @param WP $WP  | 
                                                        |
| 213 | - * @throws EE_Error  | 
                                                        |
| 214 | - * @return void  | 
                                                        |
| 215 | - */  | 
                                                        |
| 216 | - public function run($WP)  | 
                                                        |
| 217 | -    { | 
                                                        |
| 218 | - //ensure controller is loaded  | 
                                                        |
| 219 | - self::_load_controller();  | 
                                                        |
| 220 | - // attempt to process message  | 
                                                        |
| 221 | -        try { | 
                                                        |
| 222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */  | 
                                                        |
| 223 | -            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); | 
                                                        |
| 224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);  | 
                                                        |
| 225 | -        } catch (EE_Error $e) { | 
                                                        |
| 226 | -            $error_msg = __('Please note that a system message failed to send due to a technical issue.', | 
                                                        |
| 227 | - 'event_espresso');  | 
                                                        |
| 228 | - // add specific message for developers if WP_DEBUG in on  | 
                                                        |
| 229 | - $error_msg .= '||' . $e->getMessage();  | 
                                                        |
| 230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 231 | - }  | 
                                                        |
| 232 | - }  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | - /**  | 
                                                        |
| 236 | - * This is triggered by the 'msg_cron_trigger' route.  | 
                                                        |
| 237 | - *  | 
                                                        |
| 238 | - * @param WP $WP  | 
                                                        |
| 239 | - */  | 
                                                        |
| 240 | - public function execute_batch_request($WP)  | 
                                                        |
| 241 | -    { | 
                                                        |
| 242 | - $this->run_cron();  | 
                                                        |
| 243 | -        header('HTTP/1.1 200 OK'); | 
                                                        |
| 244 | - exit();  | 
                                                        |
| 245 | - }  | 
                                                        |
| 246 | -  | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | - /**  | 
                                                        |
| 249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp  | 
                                                        |
| 250 | - * request.  | 
                                                        |
| 251 | - */  | 
                                                        |
| 252 | - public function run_cron()  | 
                                                        |
| 253 | -    { | 
                                                        |
| 254 | - self::_load_controller();  | 
                                                        |
| 255 | - //get required vars  | 
                                                        |
| 256 | -        $cron_type     = EE_Registry::instance()->REQ->get('type'); | 
                                                        |
| 257 | -        $transient_key = EE_Registry::instance()->REQ->get('key'); | 
                                                        |
| 258 | -  | 
                                                        |
| 259 | - //now let's verify transient, if not valid exit immediately  | 
                                                        |
| 260 | -        if (! get_transient($transient_key)) { | 
                                                        |
| 261 | - /**  | 
                                                        |
| 262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request.  | 
                                                        |
| 263 | - */  | 
                                                        |
| 264 | -            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); | 
                                                        |
| 265 | - }  | 
                                                        |
| 266 | -  | 
                                                        |
| 267 | - //if made it here, lets' delete the transient to keep the db clean  | 
                                                        |
| 268 | - delete_transient($transient_key);  | 
                                                        |
| 269 | -  | 
                                                        |
| 270 | -        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { | 
                                                        |
| 271 | -  | 
                                                        |
| 272 | - $method = 'batch_' . $cron_type . '_from_queue';  | 
                                                        |
| 273 | -            if (method_exists(self::$_MSG_PROCESSOR, $method)) { | 
                                                        |
| 274 | - self::$_MSG_PROCESSOR->$method();  | 
                                                        |
| 275 | -            } else { | 
                                                        |
| 276 | - //no matching task  | 
                                                        |
| 277 | - /**  | 
                                                        |
| 278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request.  | 
                                                        |
| 279 | - */  | 
                                                        |
| 280 | -                trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), | 
                                                        |
| 281 | - $cron_type)));  | 
                                                        |
| 282 | - }  | 
                                                        |
| 283 | - }  | 
                                                        |
| 284 | -  | 
                                                        |
| 285 | -        do_action('FHEE__EED_Messages__run_cron__end'); | 
                                                        |
| 286 | - }  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | -  | 
                                                        |
| 289 | - /**  | 
                                                        |
| 290 | - * This is used to retrieve the template pack for the given name.  | 
                                                        |
| 291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then  | 
                                                        |
| 292 | - * the default template pack is returned.  | 
                                                        |
| 293 | - *  | 
                                                        |
| 294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack()  | 
                                                        |
| 295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used  | 
                                                        |
| 296 | - * in generating the Pack class name).  | 
                                                        |
| 297 | - * @return EE_Messages_Template_Pack  | 
                                                        |
| 298 | - */  | 
                                                        |
| 299 | - public static function get_template_pack($template_pack_name)  | 
                                                        |
| 300 | -    { | 
                                                        |
| 301 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 302 | - return EEH_MSG_Template::get_template_pack($template_pack_name);  | 
                                                        |
| 303 | - }  | 
                                                        |
| 304 | -  | 
                                                        |
| 305 | -  | 
                                                        |
| 306 | - /**  | 
                                                        |
| 307 | - * Retrieves an array of all template packs.  | 
                                                        |
| 308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )  | 
                                                        |
| 309 | - *  | 
                                                        |
| 310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection  | 
                                                        |
| 311 | - * @return EE_Messages_Template_Pack[]  | 
                                                        |
| 312 | - */  | 
                                                        |
| 313 | - public static function get_template_packs()  | 
                                                        |
| 314 | -    { | 
                                                        |
| 315 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 316 | -  | 
                                                        |
| 317 | - //for backward compat, let's make sure this returns in the same format as originally.  | 
                                                        |
| 318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 319 | - $template_pack_collection->rewind();  | 
                                                        |
| 320 | - $template_packs = array();  | 
                                                        |
| 321 | -        while ($template_pack_collection->valid()) { | 
                                                        |
| 322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();  | 
                                                        |
| 323 | - $template_pack_collection->next();  | 
                                                        |
| 324 | - }  | 
                                                        |
| 325 | - return $template_packs;  | 
                                                        |
| 326 | - }  | 
                                                        |
| 327 | -  | 
                                                        |
| 328 | -  | 
                                                        |
| 329 | - /**  | 
                                                        |
| 330 | - * This simply makes sure the autoloaders are registered for the EE_messages system.  | 
                                                        |
| 331 | - *  | 
                                                        |
| 332 | - * @since 4.5.0  | 
                                                        |
| 333 | - * @return void  | 
                                                        |
| 334 | - */  | 
                                                        |
| 335 | - public static function set_autoloaders()  | 
                                                        |
| 336 | -    { | 
                                                        |
| 337 | -        if (empty(self::$_MSG_PATHS)) { | 
                                                        |
| 338 | - self::_set_messages_paths();  | 
                                                        |
| 339 | -            foreach (self::$_MSG_PATHS as $path) { | 
                                                        |
| 340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);  | 
                                                        |
| 341 | - }  | 
                                                        |
| 342 | - // add aliases  | 
                                                        |
| 343 | -            EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); | 
                                                        |
| 344 | -            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); | 
                                                        |
| 345 | - }  | 
                                                        |
| 346 | - }  | 
                                                        |
| 347 | -  | 
                                                        |
| 348 | -  | 
                                                        |
| 349 | - /**  | 
                                                        |
| 350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property  | 
                                                        |
| 351 | - * for use by the Messages Autoloaders  | 
                                                        |
| 352 | - *  | 
                                                        |
| 353 | - * @since 4.5.0  | 
                                                        |
| 354 | - * @return void.  | 
                                                        |
| 355 | - */  | 
                                                        |
| 356 | - protected static function _set_messages_paths()  | 
                                                        |
| 357 | -    { | 
                                                        |
| 358 | - $dir_ref = array(  | 
                                                        |
| 359 | - 'messages/message_type',  | 
                                                        |
| 360 | - 'messages/messenger',  | 
                                                        |
| 361 | - 'messages/defaults',  | 
                                                        |
| 362 | - 'messages/defaults/email',  | 
                                                        |
| 363 | - 'messages/data_class',  | 
                                                        |
| 364 | - 'messages/validators',  | 
                                                        |
| 365 | - 'messages/validators/email',  | 
                                                        |
| 366 | - 'messages/validators/html',  | 
                                                        |
| 367 | - 'shortcodes',  | 
                                                        |
| 368 | - );  | 
                                                        |
| 369 | - $paths = array();  | 
                                                        |
| 370 | -        foreach ($dir_ref as $index => $dir) { | 
                                                        |
| 371 | - $paths[$index] = EE_LIBRARIES . $dir;  | 
                                                        |
| 372 | - }  | 
                                                        |
| 373 | -        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); | 
                                                        |
| 374 | - }  | 
                                                        |
| 375 | -  | 
                                                        |
| 376 | -  | 
                                                        |
| 377 | - /**  | 
                                                        |
| 378 | - * Takes care of loading dependencies  | 
                                                        |
| 379 | - *  | 
                                                        |
| 380 | - * @since 4.5.0  | 
                                                        |
| 381 | - * @return void  | 
                                                        |
| 382 | - */  | 
                                                        |
| 383 | - protected static function _load_controller()  | 
                                                        |
| 384 | -    { | 
                                                        |
| 385 | -        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { | 
                                                        |
| 386 | -            EE_Registry::instance()->load_core('Request_Handler'); | 
                                                        |
| 387 | - self::set_autoloaders();  | 
                                                        |
| 388 | -            self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages'); | 
                                                        |
| 389 | -            self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor'); | 
                                                        |
| 390 | -            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 391 | - }  | 
                                                        |
| 392 | - }  | 
                                                        |
| 393 | -  | 
                                                        |
| 394 | -  | 
                                                        |
| 395 | - /**  | 
                                                        |
| 396 | - * @param EE_Transaction $transaction  | 
                                                        |
| 397 | - */  | 
                                                        |
| 398 | - public static function payment_reminder(EE_Transaction $transaction)  | 
                                                        |
| 399 | -    { | 
                                                        |
| 400 | - self::_load_controller();  | 
                                                        |
| 401 | - $data = array($transaction, null);  | 
                                                        |
| 402 | -        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); | 
                                                        |
| 403 | - }  | 
                                                        |
| 404 | -  | 
                                                        |
| 405 | -  | 
                                                        |
| 406 | - /**  | 
                                                        |
| 407 | - * Any messages triggers for after successful gateway payments should go in here.  | 
                                                        |
| 408 | - *  | 
                                                        |
| 409 | - * @param EE_Transaction object  | 
                                                        |
| 410 | - * @param EE_Payment object  | 
                                                        |
| 411 | - * @return void  | 
                                                        |
| 412 | - */  | 
                                                        |
| 413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment)  | 
                                                        |
| 414 | -    { | 
                                                        |
| 415 | - self::_load_controller();  | 
                                                        |
| 416 | - $data = array($transaction, $payment);  | 
                                                        |
| 417 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());  | 
                                                        |
| 419 | - //if payment amount is less than 0 then switch to payment_refund message type.  | 
                                                        |
| 420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;  | 
                                                        |
| 421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);  | 
                                                        |
| 422 | - }  | 
                                                        |
| 423 | -  | 
                                                        |
| 424 | -  | 
                                                        |
| 425 | - /**  | 
                                                        |
| 426 | - * @param EE_Transaction $transaction  | 
                                                        |
| 427 | - */  | 
                                                        |
| 428 | - public static function cancelled_registration(EE_Transaction $transaction)  | 
                                                        |
| 429 | -    { | 
                                                        |
| 430 | - self::_load_controller();  | 
                                                        |
| 431 | - $data = array($transaction, null);  | 
                                                        |
| 432 | -        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); | 
                                                        |
| 433 | - }  | 
                                                        |
| 434 | -  | 
                                                        |
| 435 | -  | 
                                                        |
| 436 | - /**  | 
                                                        |
| 437 | - * Trigger for Registration messages  | 
                                                        |
| 438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the  | 
                                                        |
| 439 | - * incoming transaction.  | 
                                                        |
| 440 | - *  | 
                                                        |
| 441 | - * @param EE_Registration $registration  | 
                                                        |
| 442 | - * @param array $extra_details  | 
                                                        |
| 443 | - * @return void  | 
                                                        |
| 444 | - */  | 
                                                        |
| 445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array())  | 
                                                        |
| 446 | -    { | 
                                                        |
| 447 | -  | 
                                                        |
| 448 | -        if (! self::_verify_registration_notification_send($registration, $extra_details)) { | 
                                                        |
| 449 | - //no messages please  | 
                                                        |
| 450 | - return;  | 
                                                        |
| 451 | - }  | 
                                                        |
| 452 | -  | 
                                                        |
| 453 | -  | 
                                                        |
| 454 | - //get all registrations so we make sure we send messages for the right status.  | 
                                                        |
| 455 | - $all_registrations = $registration->transaction()->registrations();  | 
                                                        |
| 456 | -  | 
                                                        |
| 457 | - //cached array of statuses so we only trigger messages once per status.  | 
                                                        |
| 458 | - $statuses_sent = array();  | 
                                                        |
| 459 | - self::_load_controller();  | 
                                                        |
| 460 | - $mtgs = array();  | 
                                                        |
| 461 | -  | 
                                                        |
| 462 | - //loop through registrations and trigger messages once per status.  | 
                                                        |
| 463 | -        foreach ($all_registrations as $reg) { | 
                                                        |
| 464 | -  | 
                                                        |
| 465 | - //already triggered?  | 
                                                        |
| 466 | -            if (in_array($reg->status_ID(), $statuses_sent)) { | 
                                                        |
| 467 | - continue;  | 
                                                        |
| 468 | - }  | 
                                                        |
| 469 | -  | 
                                                        |
| 470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());  | 
                                                        |
| 471 | - $mtgs = array_merge(  | 
                                                        |
| 472 | - $mtgs,  | 
                                                        |
| 473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(  | 
                                                        |
| 474 | - $message_type,  | 
                                                        |
| 475 | - array($registration->transaction(), null, $reg->status_ID())  | 
                                                        |
| 476 | - )  | 
                                                        |
| 477 | - );  | 
                                                        |
| 478 | - $statuses_sent[] = $reg->status_ID();  | 
                                                        |
| 479 | - }  | 
                                                        |
| 480 | -  | 
                                                        |
| 481 | -        if (count($statuses_sent) > 1) { | 
                                                        |
| 482 | - $mtgs = array_merge(  | 
                                                        |
| 483 | - $mtgs,  | 
                                                        |
| 484 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(  | 
                                                        |
| 485 | - 'registration_summary',  | 
                                                        |
| 486 | - array($registration->transaction(), null)  | 
                                                        |
| 487 | - )  | 
                                                        |
| 488 | - );  | 
                                                        |
| 489 | - }  | 
                                                        |
| 490 | -  | 
                                                        |
| 491 | - //batch queue and initiate request  | 
                                                        |
| 492 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);  | 
                                                        |
| 493 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();  | 
                                                        |
| 494 | - }  | 
                                                        |
| 495 | -  | 
                                                        |
| 496 | -  | 
                                                        |
| 497 | - /**  | 
                                                        |
| 498 | - * This is a helper method used to very whether a registration notification should be sent or  | 
                                                        |
| 499 | - * not. Prevents duplicate notifications going out for registration context notifications.  | 
                                                        |
| 500 | - *  | 
                                                        |
| 501 | - * @param EE_Registration $registration [description]  | 
                                                        |
| 502 | - * @param array $extra_details [description]  | 
                                                        |
| 503 | - * @return bool true = send away, false = nope halt the presses.  | 
                                                        |
| 504 | - */  | 
                                                        |
| 505 | - protected static function _verify_registration_notification_send(  | 
                                                        |
| 506 | - EE_Registration $registration,  | 
                                                        |
| 507 | - $extra_details = array()  | 
                                                        |
| 508 | -    ) { | 
                                                        |
| 509 | - //self::log(  | 
                                                        |
| 510 | - // __CLASS__, __FUNCTION__, __LINE__,  | 
                                                        |
| 511 | - // $registration->transaction(),  | 
                                                        |
| 512 | - // array( '$extra_details' => $extra_details )  | 
                                                        |
| 513 | - //);  | 
                                                        |
| 514 | - // currently only using this to send messages for the primary registrant  | 
                                                        |
| 515 | -        if (! $registration->is_primary_registrant()) { | 
                                                        |
| 516 | - return false;  | 
                                                        |
| 517 | - }  | 
                                                        |
| 518 | - // first we check if we're in admin and not doing front ajax  | 
                                                        |
| 519 | -        if (is_admin() && ! EE_FRONT_AJAX) { | 
                                                        |
| 520 | - //make sure appropriate admin params are set for sending messages  | 
                                                        |
| 521 | -            if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { | 
                                                        |
| 522 | - //no messages sent please.  | 
                                                        |
| 523 | - return false;  | 
                                                        |
| 524 | - }  | 
                                                        |
| 525 | -        } else { | 
                                                        |
| 526 | - // frontend request (either regular or via AJAX)  | 
                                                        |
| 527 | - // TXN is NOT finalized ?  | 
                                                        |
| 528 | -            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { | 
                                                        |
| 529 | - return false;  | 
                                                        |
| 530 | - }  | 
                                                        |
| 531 | - // return visit but nothing changed ???  | 
                                                        |
| 532 | - if (  | 
                                                        |
| 533 | - isset($extra_details['revisit'], $extra_details['status_updates']) &&  | 
                                                        |
| 534 | - $extra_details['revisit'] && ! $extra_details['status_updates']  | 
                                                        |
| 535 | -            ) { | 
                                                        |
| 536 | - return false;  | 
                                                        |
| 537 | - }  | 
                                                        |
| 538 | - // NOT sending messages && reg status is something other than "Not-Approved"  | 
                                                        |
| 539 | - if (  | 
                                                        |
| 540 | -                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && | 
                                                        |
| 541 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved  | 
                                                        |
| 542 | -            ) { | 
                                                        |
| 543 | - return false;  | 
                                                        |
| 544 | - }  | 
                                                        |
| 545 | - }  | 
                                                        |
| 546 | - // release the kraken  | 
                                                        |
| 547 | - return true;  | 
                                                        |
| 548 | - }  | 
                                                        |
| 549 | -  | 
                                                        |
| 550 | -  | 
                                                        |
| 551 | - /**  | 
                                                        |
| 552 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that  | 
                                                        |
| 553 | - * status id.  | 
                                                        |
| 554 | - *  | 
                                                        |
| 555 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array()  | 
                                                        |
| 556 | - * or EEH_MSG_Template::convert_reg_status_to_message_type  | 
                                                        |
| 557 | - * @param string $reg_status  | 
                                                        |
| 558 | - * @return array  | 
                                                        |
| 559 | - */  | 
                                                        |
| 560 | - protected static function _get_reg_status_array($reg_status = '')  | 
                                                        |
| 561 | -    { | 
                                                        |
| 562 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 563 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 564 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 565 | - : EEH_MSG_Template::reg_status_to_message_type_array();  | 
                                                        |
| 566 | - }  | 
                                                        |
| 567 | -  | 
                                                        |
| 568 | -  | 
                                                        |
| 569 | - /**  | 
                                                        |
| 570 | - * Simply returns the payment message type for the given payment status.  | 
                                                        |
| 571 | - *  | 
                                                        |
| 572 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array  | 
                                                        |
| 573 | - * or EEH_MSG_Template::convert_payment_status_to_message_type  | 
                                                        |
| 574 | - * @param string $payment_status The payment status being matched.  | 
                                                        |
| 575 | - * @return string|bool The payment message type slug matching the status or false if no match.  | 
                                                        |
| 576 | - */  | 
                                                        |
| 577 | - protected static function _get_payment_message_type($payment_status)  | 
                                                        |
| 578 | -    { | 
                                                        |
| 579 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 580 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 581 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 582 | - : false;  | 
                                                        |
| 583 | - }  | 
                                                        |
| 584 | -  | 
                                                        |
| 585 | -  | 
                                                        |
| 586 | - /**  | 
                                                        |
| 587 | - * Message triggers for a resending already sent message(s) (via EE_Message list table)  | 
                                                        |
| 588 | - *  | 
                                                        |
| 589 | - * @access public  | 
                                                        |
| 590 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages  | 
                                                        |
| 591 | - * @return bool success/fail  | 
                                                        |
| 592 | - */  | 
                                                        |
| 593 | - public static function process_resend($req_data)  | 
                                                        |
| 594 | -    { | 
                                                        |
| 595 | - self::_load_controller();  | 
                                                        |
| 596 | -  | 
                                                        |
| 597 | - //if $msgID in this request then skip to the new resend_message  | 
                                                        |
| 598 | -        if (EE_Registry::instance()->REQ->get('MSG_ID')) { | 
                                                        |
| 599 | - return self::resend_message();  | 
                                                        |
| 600 | - }  | 
                                                        |
| 601 | -  | 
                                                        |
| 602 | - //make sure any incoming request data is set on the REQ so that it gets picked up later.  | 
                                                        |
| 603 | - $req_data = (array)$req_data;  | 
                                                        |
| 604 | -        foreach ($req_data as $request_key => $request_value) { | 
                                                        |
| 605 | - EE_Registry::instance()->REQ->set($request_key, $request_value);  | 
                                                        |
| 606 | - }  | 
                                                        |
| 607 | -  | 
                                                        |
| 608 | -        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { | 
                                                        |
| 609 | - return false;  | 
                                                        |
| 610 | - }  | 
                                                        |
| 611 | -  | 
                                                        |
| 612 | -        try { | 
                                                        |
| 613 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);  | 
                                                        |
| 614 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();  | 
                                                        |
| 615 | -        } catch (EE_Error $e) { | 
                                                        |
| 616 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 617 | - return false;  | 
                                                        |
| 618 | - }  | 
                                                        |
| 619 | - EE_Error::add_success(  | 
                                                        |
| 620 | -            __('Messages have been successfully queued for generation and sending.', 'event_espresso') | 
                                                        |
| 621 | - );  | 
                                                        |
| 622 | - return true; //everything got queued.  | 
                                                        |
| 623 | - }  | 
                                                        |
| 624 | -  | 
                                                        |
| 625 | -  | 
                                                        |
| 626 | - /**  | 
                                                        |
| 627 | - * Message triggers for a resending already sent message(s) (via EE_Message list table)  | 
                                                        |
| 628 | - *  | 
                                                        |
| 629 | - * @return bool  | 
                                                        |
| 630 | - */  | 
                                                        |
| 631 | - public static function resend_message()  | 
                                                        |
| 632 | -    { | 
                                                        |
| 633 | - self::_load_controller();  | 
                                                        |
| 634 | -  | 
                                                        |
| 635 | -        $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); | 
                                                        |
| 636 | -        if (! $msgID) { | 
                                                        |
| 637 | -            EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', | 
                                                        |
| 638 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 639 | - return false;  | 
                                                        |
| 640 | - }  | 
                                                        |
| 641 | -  | 
                                                        |
| 642 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);  | 
                                                        |
| 643 | -  | 
                                                        |
| 644 | - //setup success message.  | 
                                                        |
| 645 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);  | 
                                                        |
| 646 | - EE_Error::add_success(sprintf(  | 
                                                        |
| 647 | - _n(  | 
                                                        |
| 648 | - 'There was %d message queued for resending.',  | 
                                                        |
| 649 | - 'There were %d messages queued for resending.',  | 
                                                        |
| 650 | - $count_ready_for_resend,  | 
                                                        |
| 651 | - 'event_espresso'  | 
                                                        |
| 652 | - ),  | 
                                                        |
| 653 | - $count_ready_for_resend  | 
                                                        |
| 654 | - ));  | 
                                                        |
| 655 | - return true;  | 
                                                        |
| 656 | - }  | 
                                                        |
| 657 | -  | 
                                                        |
| 658 | -  | 
                                                        |
| 659 | - /**  | 
                                                        |
| 660 | - * Message triggers for manual payment applied by admin  | 
                                                        |
| 661 | - *  | 
                                                        |
| 662 | - * @param EE_Payment $payment EE_payment object  | 
                                                        |
| 663 | - * @return bool success/fail  | 
                                                        |
| 664 | - */  | 
                                                        |
| 665 | - public static function process_admin_payment(EE_Payment $payment)  | 
                                                        |
| 666 | -    { | 
                                                        |
| 667 | -        EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 668 | - //we need to get the transaction object  | 
                                                        |
| 669 | - $transaction = $payment->transaction();  | 
                                                        |
| 670 | -        if ($transaction instanceof EE_Transaction) { | 
                                                        |
| 671 | - $data = array($transaction, $payment);  | 
                                                        |
| 672 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());  | 
                                                        |
| 673 | -  | 
                                                        |
| 674 | - //if payment amount is less than 0 then switch to payment_refund message type.  | 
                                                        |
| 675 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;  | 
                                                        |
| 676 | -  | 
                                                        |
| 677 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out.  | 
                                                        |
| 678 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;  | 
                                                        |
| 679 | -  | 
                                                        |
| 680 | - self::_load_controller();  | 
                                                        |
| 681 | -  | 
                                                        |
| 682 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);  | 
                                                        |
| 683 | -  | 
                                                        |
| 684 | - //get count of queued for generation  | 
                                                        |
| 685 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(  | 
                                                        |
| 686 | - EEM_Message::status_incomplete,  | 
                                                        |
| 687 | - EEM_Message::status_idle,  | 
                                                        |
| 688 | - ));  | 
                                                        |
| 689 | -  | 
                                                        |
| 690 | -            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { | 
                                                        |
| 691 | -                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); | 
                                                        |
| 692 | - return true;  | 
                                                        |
| 693 | -            } else { | 
                                                        |
| 694 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());  | 
                                                        |
| 695 | - /**  | 
                                                        |
| 696 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful  | 
                                                        |
| 697 | - * IMMEDIATE generation.  | 
                                                        |
| 698 | - */  | 
                                                        |
| 699 | -                if ($count_failed > 0) { | 
                                                        |
| 700 | - EE_Error::add_error(sprintf(  | 
                                                        |
| 701 | - _n(  | 
                                                        |
| 702 | - 'The payment notification generation failed.',  | 
                                                        |
| 703 | - '%d payment notifications failed being sent.',  | 
                                                        |
| 704 | - $count_failed,  | 
                                                        |
| 705 | - 'event_espresso'  | 
                                                        |
| 706 | - ),  | 
                                                        |
| 707 | - $count_failed  | 
                                                        |
| 708 | - ), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 709 | -  | 
                                                        |
| 710 | - return false;  | 
                                                        |
| 711 | -                } else { | 
                                                        |
| 712 | -                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); | 
                                                        |
| 713 | - return true;  | 
                                                        |
| 714 | - }  | 
                                                        |
| 715 | - }  | 
                                                        |
| 716 | -        } else { | 
                                                        |
| 717 | - EE_Error::add_error(  | 
                                                        |
| 718 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.',  | 
                                                        |
| 719 | - 'event_espresso'  | 
                                                        |
| 720 | - );  | 
                                                        |
| 721 | - return false;  | 
                                                        |
| 722 | - }  | 
                                                        |
| 723 | - }  | 
                                                        |
| 724 | -  | 
                                                        |
| 725 | -  | 
                                                        |
| 726 | - /**  | 
                                                        |
| 727 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger  | 
                                                        |
| 728 | - *  | 
                                                        |
| 729 | - * @since 4.3.0  | 
                                                        |
| 730 | - * @param EE_Registration[] $registrations an array of EE_Registration objects  | 
                                                        |
| 731 | - * @param int $grp_id a specific message template group id.  | 
                                                        |
| 732 | - * @return void  | 
                                                        |
| 733 | - */  | 
                                                        |
| 734 | - public static function send_newsletter_message($registrations, $grp_id)  | 
                                                        |
| 735 | -    { | 
                                                        |
| 736 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup.  | 
                                                        |
| 737 | -        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); | 
                                                        |
| 738 | - self::_load_controller();  | 
                                                        |
| 739 | -        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); | 
                                                        |
| 740 | - }  | 
                                                        |
| 741 | -  | 
                                                        |
| 742 | -  | 
                                                        |
| 743 | - /**  | 
                                                        |
| 744 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url  | 
                                                        |
| 745 | - *  | 
                                                        |
| 746 | - * @since 4.3.0  | 
                                                        |
| 747 | - * @param string $registration_message_trigger_url  | 
                                                        |
| 748 | - * @param EE_Registration $registration  | 
                                                        |
| 749 | - * @param string $messenger  | 
                                                        |
| 750 | - * @param string $message_type  | 
                                                        |
| 751 | - * @return string  | 
                                                        |
| 752 | - */  | 
                                                        |
| 753 | - public static function registration_message_trigger_url(  | 
                                                        |
| 754 | - $registration_message_trigger_url,  | 
                                                        |
| 755 | - EE_Registration $registration,  | 
                                                        |
| 756 | - $messenger = 'html',  | 
                                                        |
| 757 | - $message_type = 'invoice'  | 
                                                        |
| 758 | -    ) { | 
                                                        |
| 759 | - // whitelist $messenger  | 
                                                        |
| 760 | -        switch ($messenger) { | 
                                                        |
| 761 | - case 'pdf' :  | 
                                                        |
| 762 | - $sending_messenger = 'pdf';  | 
                                                        |
| 763 | - $generating_messenger = 'html';  | 
                                                        |
| 764 | - break;  | 
                                                        |
| 765 | - case 'html' :  | 
                                                        |
| 766 | - default :  | 
                                                        |
| 767 | - $sending_messenger = 'html';  | 
                                                        |
| 768 | - $generating_messenger = 'html';  | 
                                                        |
| 769 | - break;  | 
                                                        |
| 770 | - }  | 
                                                        |
| 771 | - // whitelist $message_type  | 
                                                        |
| 772 | -        switch ($message_type) { | 
                                                        |
| 773 | - case 'receipt' :  | 
                                                        |
| 774 | - $message_type = 'receipt';  | 
                                                        |
| 775 | - break;  | 
                                                        |
| 776 | - case 'invoice' :  | 
                                                        |
| 777 | - default :  | 
                                                        |
| 778 | - $message_type = 'invoice';  | 
                                                        |
| 779 | - break;  | 
                                                        |
| 780 | - }  | 
                                                        |
| 781 | - // verify that both the messenger AND the message type are active  | 
                                                        |
| 782 | -        if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { | 
                                                        |
| 783 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)  | 
                                                        |
| 784 | - $template_query_params = array(  | 
                                                        |
| 785 | - 'MTP_is_active' => true,  | 
                                                        |
| 786 | - 'MTP_messenger' => $generating_messenger,  | 
                                                        |
| 787 | - 'MTP_message_type' => $message_type,  | 
                                                        |
| 788 | - 'Event.EVT_ID' => $registration->event_ID(),  | 
                                                        |
| 789 | - );  | 
                                                        |
| 790 | - //get the message template group.  | 
                                                        |
| 791 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));  | 
                                                        |
| 792 | - //if we don't have an EE_Message_Template_Group then return  | 
                                                        |
| 793 | -            if (! $msg_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 794 | - // remove EVT_ID from query params so that global templates get picked up  | 
                                                        |
| 795 | - unset($template_query_params['Event.EVT_ID']);  | 
                                                        |
| 796 | - //get global template as the fallback  | 
                                                        |
| 797 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));  | 
                                                        |
| 798 | - }  | 
                                                        |
| 799 | - //if we don't have an EE_Message_Template_Group then return  | 
                                                        |
| 800 | -            if (! $msg_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 801 | - return '';  | 
                                                        |
| 802 | - }  | 
                                                        |
| 803 | - // generate the URL  | 
                                                        |
| 804 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(  | 
                                                        |
| 805 | - $sending_messenger,  | 
                                                        |
| 806 | - $generating_messenger,  | 
                                                        |
| 807 | - 'purchaser',  | 
                                                        |
| 808 | - $message_type,  | 
                                                        |
| 809 | - $registration,  | 
                                                        |
| 810 | - $msg_template_group->ID(),  | 
                                                        |
| 811 | - $registration->transaction_ID()  | 
                                                        |
| 812 | - );  | 
                                                        |
| 813 | -  | 
                                                        |
| 814 | - }  | 
                                                        |
| 815 | - return $registration_message_trigger_url;  | 
                                                        |
| 816 | - }  | 
                                                        |
| 817 | -  | 
                                                        |
| 818 | -  | 
                                                        |
| 819 | - /**  | 
                                                        |
| 820 | - * Use to generate and return a message preview!  | 
                                                        |
| 821 | - *  | 
                                                        |
| 822 | - * @param string $type This should correspond with a valid message type  | 
                                                        |
| 823 | - * @param string $context This should correspond with a valid context for the message type  | 
                                                        |
| 824 | - * @param string $messenger This should correspond with a valid messenger.  | 
                                                        |
| 825 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular  | 
                                                        |
| 826 | - * preview  | 
                                                        |
| 827 | - * @return bool|string The body of the message or if send is requested, sends.  | 
                                                        |
| 828 | - * @throws EE_Error  | 
                                                        |
| 829 | - */  | 
                                                        |
| 830 | - public static function preview_message($type, $context, $messenger, $send = false)  | 
                                                        |
| 831 | -    { | 
                                                        |
| 832 | - self::_load_controller();  | 
                                                        |
| 833 | - $mtg = new EE_Message_To_Generate(  | 
                                                        |
| 834 | - $messenger,  | 
                                                        |
| 835 | - $type,  | 
                                                        |
| 836 | - array(),  | 
                                                        |
| 837 | - $context,  | 
                                                        |
| 838 | - true  | 
                                                        |
| 839 | - );  | 
                                                        |
| 840 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);  | 
                                                        |
| 841 | -        if ($generated_preview_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 842 | - $content = $generated_preview_queue->get_message_repository()->current()->content();  | 
                                                        |
| 843 | - //if the current message was persisted to the db (which will happen with any extra fields on a message) then  | 
                                                        |
| 844 | - //let's delete it because we don't need previews cluttering up the db.  | 
                                                        |
| 845 | - if ($generated_preview_queue->get_message_repository()->current()->ID() > 0  | 
                                                        |
| 846 | - && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed  | 
                                                        |
| 847 | -            ) { | 
                                                        |
| 848 | - $generated_preview_queue->get_message_repository()->delete();  | 
                                                        |
| 849 | - }  | 
                                                        |
| 850 | - return $content;  | 
                                                        |
| 851 | -        } else { | 
                                                        |
| 852 | - return $generated_preview_queue;  | 
                                                        |
| 853 | - }  | 
                                                        |
| 854 | - }  | 
                                                        |
| 855 | -  | 
                                                        |
| 856 | -  | 
                                                        |
| 857 | - /**  | 
                                                        |
| 858 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided  | 
                                                        |
| 859 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the  | 
                                                        |
| 860 | - * content found in the EE_Message objects in the queue.  | 
                                                        |
| 861 | - *  | 
                                                        |
| 862 | - * @since 4.9.0  | 
                                                        |
| 863 | - * @param string $messenger a string matching a valid active messenger in the system  | 
                                                        |
| 864 | - * @param string $message_type Although it seems contrary to the name of the method, a message  | 
                                                        |
| 865 | - * type name is still required to send along the message type to the  | 
                                                        |
| 866 | - * messenger because this is used for determining what specific  | 
                                                        |
| 867 | - * variations might be loaded for the generated message.  | 
                                                        |
| 868 | - * @param EE_Messages_Queue $queue  | 
                                                        |
| 869 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the  | 
                                                        |
| 870 | - * aggregate EE_Message object.  | 
                                                        |
| 871 | - * @return bool success or fail.  | 
                                                        |
| 872 | - */  | 
                                                        |
| 873 | - public static function send_message_with_messenger_only(  | 
                                                        |
| 874 | - $messenger,  | 
                                                        |
| 875 | - $message_type,  | 
                                                        |
| 876 | - EE_Messages_Queue $queue,  | 
                                                        |
| 877 | - $custom_subject = ''  | 
                                                        |
| 878 | -    ) { | 
                                                        |
| 879 | - self::_load_controller();  | 
                                                        |
| 880 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */  | 
                                                        |
| 881 | - $message_to_generate = EE_Registry::instance()->load_lib(  | 
                                                        |
| 882 | - 'Message_To_Generate_From_Queue',  | 
                                                        |
| 883 | - array(  | 
                                                        |
| 884 | - $messenger,  | 
                                                        |
| 885 | - $message_type,  | 
                                                        |
| 886 | - $queue,  | 
                                                        |
| 887 | - $custom_subject,  | 
                                                        |
| 888 | - )  | 
                                                        |
| 889 | - );  | 
                                                        |
| 890 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);  | 
                                                        |
| 891 | - }  | 
                                                        |
| 892 | -  | 
                                                        |
| 893 | -  | 
                                                        |
| 894 | - /**  | 
                                                        |
| 895 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)  | 
                                                        |
| 896 | - *  | 
                                                        |
| 897 | - * @since 4.9.0  | 
                                                        |
| 898 | - * @param array $message_ids An array of message ids  | 
                                                        |
| 899 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated  | 
                                                        |
| 900 | - * messages.  | 
                                                        |
| 901 | - */  | 
                                                        |
| 902 | - public static function generate_now($message_ids)  | 
                                                        |
| 903 | -    { | 
                                                        |
| 904 | - self::_load_controller();  | 
                                                        |
| 905 | - $messages = EEM_Message::instance()->get_all(  | 
                                                        |
| 906 | - array(  | 
                                                        |
| 907 | - 0 => array(  | 
                                                        |
| 908 | -                    'MSG_ID' => array('IN', $message_ids), | 
                                                        |
| 909 | - 'STS_ID' => EEM_Message::status_incomplete,  | 
                                                        |
| 910 | - ),  | 
                                                        |
| 911 | - )  | 
                                                        |
| 912 | - );  | 
                                                        |
| 913 | - $generated_queue = false;  | 
                                                        |
| 914 | -        if ($messages) { | 
                                                        |
| 915 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);  | 
                                                        |
| 916 | - }  | 
                                                        |
| 917 | -  | 
                                                        |
| 918 | -        if (! $generated_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 919 | - EE_Error::add_error(  | 
                                                        |
| 920 | -                __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', | 
                                                        |
| 921 | - 'event_espresso'),  | 
                                                        |
| 922 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 923 | - );  | 
                                                        |
| 924 | - }  | 
                                                        |
| 925 | - return $generated_queue;  | 
                                                        |
| 926 | - }  | 
                                                        |
| 927 | -  | 
                                                        |
| 928 | -  | 
                                                        |
| 929 | - /**  | 
                                                        |
| 930 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,  | 
                                                        |
| 931 | - * EEM_Message::status_idle  | 
                                                        |
| 932 | - *  | 
                                                        |
| 933 | - * @since 4.9.0  | 
                                                        |
| 934 | - * @param $message_ids  | 
                                                        |
| 935 | - * @return bool | EE_Messages_Queue false if no messages sent.  | 
                                                        |
| 936 | - */  | 
                                                        |
| 937 | - public static function send_now($message_ids)  | 
                                                        |
| 938 | -    { | 
                                                        |
| 939 | - self::_load_controller();  | 
                                                        |
| 940 | - $messages = EEM_Message::instance()->get_all(  | 
                                                        |
| 941 | - array(  | 
                                                        |
| 942 | - 0 => array(  | 
                                                        |
| 943 | -                    'MSG_ID' => array('IN', $message_ids), | 
                                                        |
| 944 | - 'STS_ID' => array(  | 
                                                        |
| 945 | - 'IN',  | 
                                                        |
| 946 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),  | 
                                                        |
| 947 | - ),  | 
                                                        |
| 948 | - ),  | 
                                                        |
| 949 | - )  | 
                                                        |
| 950 | - );  | 
                                                        |
| 951 | - $sent_queue = false;  | 
                                                        |
| 952 | -        if ($messages) { | 
                                                        |
| 953 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);  | 
                                                        |
| 954 | - }  | 
                                                        |
| 955 | -  | 
                                                        |
| 956 | -        if (! $sent_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 957 | - EE_Error::add_error(  | 
                                                        |
| 958 | -                __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', | 
                                                        |
| 959 | - 'event_espresso'),  | 
                                                        |
| 960 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 961 | - );  | 
                                                        |
| 962 | -        } else { | 
                                                        |
| 963 | - //can count how many sent by using the messages in the queue  | 
                                                        |
| 964 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());  | 
                                                        |
| 965 | -            if ($sent_count > 0) { | 
                                                        |
| 966 | - EE_Error::add_success(  | 
                                                        |
| 967 | - sprintf(  | 
                                                        |
| 968 | - _n(  | 
                                                        |
| 969 | - 'There was %d message successfully sent.',  | 
                                                        |
| 970 | - 'There were %d messages successfully sent.',  | 
                                                        |
| 971 | - $sent_count,  | 
                                                        |
| 972 | - 'event_espresso'  | 
                                                        |
| 973 | - ),  | 
                                                        |
| 974 | - $sent_count  | 
                                                        |
| 975 | - )  | 
                                                        |
| 976 | - );  | 
                                                        |
| 977 | -            } else { | 
                                                        |
| 978 | - EE_Error::overwrite_errors();  | 
                                                        |
| 979 | - EE_Error::add_error(  | 
                                                        |
| 980 | -                    __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. | 
                                                        |
| 201 | + exit;  | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | + }  | 
                                                        |
| 204 | + return;  | 
                                                        |
| 205 | + }  | 
                                                        |
| 206 | +  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | + /**  | 
                                                        |
| 209 | + * This runs when the msg_url_trigger route has initiated.  | 
                                                        |
| 210 | + *  | 
                                                        |
| 211 | + * @since 4.5.0  | 
                                                        |
| 212 | + * @param WP $WP  | 
                                                        |
| 213 | + * @throws EE_Error  | 
                                                        |
| 214 | + * @return void  | 
                                                        |
| 215 | + */  | 
                                                        |
| 216 | + public function run($WP)  | 
                                                        |
| 217 | +	{ | 
                                                        |
| 218 | + //ensure controller is loaded  | 
                                                        |
| 219 | + self::_load_controller();  | 
                                                        |
| 220 | + // attempt to process message  | 
                                                        |
| 221 | +		try { | 
                                                        |
| 222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */  | 
                                                        |
| 223 | +			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); | 
                                                        |
| 224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);  | 
                                                        |
| 225 | +		} catch (EE_Error $e) { | 
                                                        |
| 226 | +			$error_msg = __('Please note that a system message failed to send due to a technical issue.', | 
                                                        |
| 227 | + 'event_espresso');  | 
                                                        |
| 228 | + // add specific message for developers if WP_DEBUG in on  | 
                                                        |
| 229 | + $error_msg .= '||' . $e->getMessage();  | 
                                                        |
| 230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 231 | + }  | 
                                                        |
| 232 | + }  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | + /**  | 
                                                        |
| 236 | + * This is triggered by the 'msg_cron_trigger' route.  | 
                                                        |
| 237 | + *  | 
                                                        |
| 238 | + * @param WP $WP  | 
                                                        |
| 239 | + */  | 
                                                        |
| 240 | + public function execute_batch_request($WP)  | 
                                                        |
| 241 | +	{ | 
                                                        |
| 242 | + $this->run_cron();  | 
                                                        |
| 243 | +		header('HTTP/1.1 200 OK'); | 
                                                        |
| 244 | + exit();  | 
                                                        |
| 245 | + }  | 
                                                        |
| 246 | +  | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | + /**  | 
                                                        |
| 249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp  | 
                                                        |
| 250 | + * request.  | 
                                                        |
| 251 | + */  | 
                                                        |
| 252 | + public function run_cron()  | 
                                                        |
| 253 | +	{ | 
                                                        |
| 254 | + self::_load_controller();  | 
                                                        |
| 255 | + //get required vars  | 
                                                        |
| 256 | +		$cron_type     = EE_Registry::instance()->REQ->get('type'); | 
                                                        |
| 257 | +		$transient_key = EE_Registry::instance()->REQ->get('key'); | 
                                                        |
| 258 | +  | 
                                                        |
| 259 | + //now let's verify transient, if not valid exit immediately  | 
                                                        |
| 260 | +		if (! get_transient($transient_key)) { | 
                                                        |
| 261 | + /**  | 
                                                        |
| 262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request.  | 
                                                        |
| 263 | + */  | 
                                                        |
| 264 | +			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); | 
                                                        |
| 265 | + }  | 
                                                        |
| 266 | +  | 
                                                        |
| 267 | + //if made it here, lets' delete the transient to keep the db clean  | 
                                                        |
| 268 | + delete_transient($transient_key);  | 
                                                        |
| 269 | +  | 
                                                        |
| 270 | +		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { | 
                                                        |
| 271 | +  | 
                                                        |
| 272 | + $method = 'batch_' . $cron_type . '_from_queue';  | 
                                                        |
| 273 | +			if (method_exists(self::$_MSG_PROCESSOR, $method)) { | 
                                                        |
| 274 | + self::$_MSG_PROCESSOR->$method();  | 
                                                        |
| 275 | +			} else { | 
                                                        |
| 276 | + //no matching task  | 
                                                        |
| 277 | + /**  | 
                                                        |
| 278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request.  | 
                                                        |
| 279 | + */  | 
                                                        |
| 280 | +				trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), | 
                                                        |
| 281 | + $cron_type)));  | 
                                                        |
| 282 | + }  | 
                                                        |
| 283 | + }  | 
                                                        |
| 284 | +  | 
                                                        |
| 285 | +		do_action('FHEE__EED_Messages__run_cron__end'); | 
                                                        |
| 286 | + }  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | +  | 
                                                        |
| 289 | + /**  | 
                                                        |
| 290 | + * This is used to retrieve the template pack for the given name.  | 
                                                        |
| 291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then  | 
                                                        |
| 292 | + * the default template pack is returned.  | 
                                                        |
| 293 | + *  | 
                                                        |
| 294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack()  | 
                                                        |
| 295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used  | 
                                                        |
| 296 | + * in generating the Pack class name).  | 
                                                        |
| 297 | + * @return EE_Messages_Template_Pack  | 
                                                        |
| 298 | + */  | 
                                                        |
| 299 | + public static function get_template_pack($template_pack_name)  | 
                                                        |
| 300 | +	{ | 
                                                        |
| 301 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 302 | + return EEH_MSG_Template::get_template_pack($template_pack_name);  | 
                                                        |
| 303 | + }  | 
                                                        |
| 304 | +  | 
                                                        |
| 305 | +  | 
                                                        |
| 306 | + /**  | 
                                                        |
| 307 | + * Retrieves an array of all template packs.  | 
                                                        |
| 308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )  | 
                                                        |
| 309 | + *  | 
                                                        |
| 310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection  | 
                                                        |
| 311 | + * @return EE_Messages_Template_Pack[]  | 
                                                        |
| 312 | + */  | 
                                                        |
| 313 | + public static function get_template_packs()  | 
                                                        |
| 314 | +	{ | 
                                                        |
| 315 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 316 | +  | 
                                                        |
| 317 | + //for backward compat, let's make sure this returns in the same format as originally.  | 
                                                        |
| 318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 319 | + $template_pack_collection->rewind();  | 
                                                        |
| 320 | + $template_packs = array();  | 
                                                        |
| 321 | +		while ($template_pack_collection->valid()) { | 
                                                        |
| 322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();  | 
                                                        |
| 323 | + $template_pack_collection->next();  | 
                                                        |
| 324 | + }  | 
                                                        |
| 325 | + return $template_packs;  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | +  | 
                                                        |
| 328 | +  | 
                                                        |
| 329 | + /**  | 
                                                        |
| 330 | + * This simply makes sure the autoloaders are registered for the EE_messages system.  | 
                                                        |
| 331 | + *  | 
                                                        |
| 332 | + * @since 4.5.0  | 
                                                        |
| 333 | + * @return void  | 
                                                        |
| 334 | + */  | 
                                                        |
| 335 | + public static function set_autoloaders()  | 
                                                        |
| 336 | +	{ | 
                                                        |
| 337 | +		if (empty(self::$_MSG_PATHS)) { | 
                                                        |
| 338 | + self::_set_messages_paths();  | 
                                                        |
| 339 | +			foreach (self::$_MSG_PATHS as $path) { | 
                                                        |
| 340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);  | 
                                                        |
| 341 | + }  | 
                                                        |
| 342 | + // add aliases  | 
                                                        |
| 343 | +			EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); | 
                                                        |
| 344 | +			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); | 
                                                        |
| 345 | + }  | 
                                                        |
| 346 | + }  | 
                                                        |
| 347 | +  | 
                                                        |
| 348 | +  | 
                                                        |
| 349 | + /**  | 
                                                        |
| 350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property  | 
                                                        |
| 351 | + * for use by the Messages Autoloaders  | 
                                                        |
| 352 | + *  | 
                                                        |
| 353 | + * @since 4.5.0  | 
                                                        |
| 354 | + * @return void.  | 
                                                        |
| 355 | + */  | 
                                                        |
| 356 | + protected static function _set_messages_paths()  | 
                                                        |
| 357 | +	{ | 
                                                        |
| 358 | + $dir_ref = array(  | 
                                                        |
| 359 | + 'messages/message_type',  | 
                                                        |
| 360 | + 'messages/messenger',  | 
                                                        |
| 361 | + 'messages/defaults',  | 
                                                        |
| 362 | + 'messages/defaults/email',  | 
                                                        |
| 363 | + 'messages/data_class',  | 
                                                        |
| 364 | + 'messages/validators',  | 
                                                        |
| 365 | + 'messages/validators/email',  | 
                                                        |
| 366 | + 'messages/validators/html',  | 
                                                        |
| 367 | + 'shortcodes',  | 
                                                        |
| 368 | + );  | 
                                                        |
| 369 | + $paths = array();  | 
                                                        |
| 370 | +		foreach ($dir_ref as $index => $dir) { | 
                                                        |
| 371 | + $paths[$index] = EE_LIBRARIES . $dir;  | 
                                                        |
| 372 | + }  | 
                                                        |
| 373 | +		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); | 
                                                        |
| 374 | + }  | 
                                                        |
| 375 | +  | 
                                                        |
| 376 | +  | 
                                                        |
| 377 | + /**  | 
                                                        |
| 378 | + * Takes care of loading dependencies  | 
                                                        |
| 379 | + *  | 
                                                        |
| 380 | + * @since 4.5.0  | 
                                                        |
| 381 | + * @return void  | 
                                                        |
| 382 | + */  | 
                                                        |
| 383 | + protected static function _load_controller()  | 
                                                        |
| 384 | +	{ | 
                                                        |
| 385 | +		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { | 
                                                        |
| 386 | +			EE_Registry::instance()->load_core('Request_Handler'); | 
                                                        |
| 387 | + self::set_autoloaders();  | 
                                                        |
| 388 | +			self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages'); | 
                                                        |
| 389 | +			self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor'); | 
                                                        |
| 390 | +			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 391 | + }  | 
                                                        |
| 392 | + }  | 
                                                        |
| 393 | +  | 
                                                        |
| 394 | +  | 
                                                        |
| 395 | + /**  | 
                                                        |
| 396 | + * @param EE_Transaction $transaction  | 
                                                        |
| 397 | + */  | 
                                                        |
| 398 | + public static function payment_reminder(EE_Transaction $transaction)  | 
                                                        |
| 399 | +	{ | 
                                                        |
| 400 | + self::_load_controller();  | 
                                                        |
| 401 | + $data = array($transaction, null);  | 
                                                        |
| 402 | +		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); | 
                                                        |
| 403 | + }  | 
                                                        |
| 404 | +  | 
                                                        |
| 405 | +  | 
                                                        |
| 406 | + /**  | 
                                                        |
| 407 | + * Any messages triggers for after successful gateway payments should go in here.  | 
                                                        |
| 408 | + *  | 
                                                        |
| 409 | + * @param EE_Transaction object  | 
                                                        |
| 410 | + * @param EE_Payment object  | 
                                                        |
| 411 | + * @return void  | 
                                                        |
| 412 | + */  | 
                                                        |
| 413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment)  | 
                                                        |
| 414 | +	{ | 
                                                        |
| 415 | + self::_load_controller();  | 
                                                        |
| 416 | + $data = array($transaction, $payment);  | 
                                                        |
| 417 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());  | 
                                                        |
| 419 | + //if payment amount is less than 0 then switch to payment_refund message type.  | 
                                                        |
| 420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;  | 
                                                        |
| 421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);  | 
                                                        |
| 422 | + }  | 
                                                        |
| 423 | +  | 
                                                        |
| 424 | +  | 
                                                        |
| 425 | + /**  | 
                                                        |
| 426 | + * @param EE_Transaction $transaction  | 
                                                        |
| 427 | + */  | 
                                                        |
| 428 | + public static function cancelled_registration(EE_Transaction $transaction)  | 
                                                        |
| 429 | +	{ | 
                                                        |
| 430 | + self::_load_controller();  | 
                                                        |
| 431 | + $data = array($transaction, null);  | 
                                                        |
| 432 | +		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); | 
                                                        |
| 433 | + }  | 
                                                        |
| 434 | +  | 
                                                        |
| 435 | +  | 
                                                        |
| 436 | + /**  | 
                                                        |
| 437 | + * Trigger for Registration messages  | 
                                                        |
| 438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the  | 
                                                        |
| 439 | + * incoming transaction.  | 
                                                        |
| 440 | + *  | 
                                                        |
| 441 | + * @param EE_Registration $registration  | 
                                                        |
| 442 | + * @param array $extra_details  | 
                                                        |
| 443 | + * @return void  | 
                                                        |
| 444 | + */  | 
                                                        |
| 445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array())  | 
                                                        |
| 446 | +	{ | 
                                                        |
| 447 | +  | 
                                                        |
| 448 | +		if (! self::_verify_registration_notification_send($registration, $extra_details)) { | 
                                                        |
| 449 | + //no messages please  | 
                                                        |
| 450 | + return;  | 
                                                        |
| 451 | + }  | 
                                                        |
| 452 | +  | 
                                                        |
| 453 | +  | 
                                                        |
| 454 | + //get all registrations so we make sure we send messages for the right status.  | 
                                                        |
| 455 | + $all_registrations = $registration->transaction()->registrations();  | 
                                                        |
| 456 | +  | 
                                                        |
| 457 | + //cached array of statuses so we only trigger messages once per status.  | 
                                                        |
| 458 | + $statuses_sent = array();  | 
                                                        |
| 459 | + self::_load_controller();  | 
                                                        |
| 460 | + $mtgs = array();  | 
                                                        |
| 461 | +  | 
                                                        |
| 462 | + //loop through registrations and trigger messages once per status.  | 
                                                        |
| 463 | +		foreach ($all_registrations as $reg) { | 
                                                        |
| 464 | +  | 
                                                        |
| 465 | + //already triggered?  | 
                                                        |
| 466 | +			if (in_array($reg->status_ID(), $statuses_sent)) { | 
                                                        |
| 467 | + continue;  | 
                                                        |
| 468 | + }  | 
                                                        |
| 469 | +  | 
                                                        |
| 470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());  | 
                                                        |
| 471 | + $mtgs = array_merge(  | 
                                                        |
| 472 | + $mtgs,  | 
                                                        |
| 473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(  | 
                                                        |
| 474 | + $message_type,  | 
                                                        |
| 475 | + array($registration->transaction(), null, $reg->status_ID())  | 
                                                        |
| 476 | + )  | 
                                                        |
| 477 | + );  | 
                                                        |
| 478 | + $statuses_sent[] = $reg->status_ID();  | 
                                                        |
| 479 | + }  | 
                                                        |
| 480 | +  | 
                                                        |
| 481 | +		if (count($statuses_sent) > 1) { | 
                                                        |
| 482 | + $mtgs = array_merge(  | 
                                                        |
| 483 | + $mtgs,  | 
                                                        |
| 484 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(  | 
                                                        |
| 485 | + 'registration_summary',  | 
                                                        |
| 486 | + array($registration->transaction(), null)  | 
                                                        |
| 487 | + )  | 
                                                        |
| 488 | + );  | 
                                                        |
| 489 | + }  | 
                                                        |
| 490 | +  | 
                                                        |
| 491 | + //batch queue and initiate request  | 
                                                        |
| 492 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);  | 
                                                        |
| 493 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();  | 
                                                        |
| 494 | + }  | 
                                                        |
| 495 | +  | 
                                                        |
| 496 | +  | 
                                                        |
| 497 | + /**  | 
                                                        |
| 498 | + * This is a helper method used to very whether a registration notification should be sent or  | 
                                                        |
| 499 | + * not. Prevents duplicate notifications going out for registration context notifications.  | 
                                                        |
| 500 | + *  | 
                                                        |
| 501 | + * @param EE_Registration $registration [description]  | 
                                                        |
| 502 | + * @param array $extra_details [description]  | 
                                                        |
| 503 | + * @return bool true = send away, false = nope halt the presses.  | 
                                                        |
| 504 | + */  | 
                                                        |
| 505 | + protected static function _verify_registration_notification_send(  | 
                                                        |
| 506 | + EE_Registration $registration,  | 
                                                        |
| 507 | + $extra_details = array()  | 
                                                        |
| 508 | +	) { | 
                                                        |
| 509 | + //self::log(  | 
                                                        |
| 510 | + // __CLASS__, __FUNCTION__, __LINE__,  | 
                                                        |
| 511 | + // $registration->transaction(),  | 
                                                        |
| 512 | + // array( '$extra_details' => $extra_details )  | 
                                                        |
| 513 | + //);  | 
                                                        |
| 514 | + // currently only using this to send messages for the primary registrant  | 
                                                        |
| 515 | +		if (! $registration->is_primary_registrant()) { | 
                                                        |
| 516 | + return false;  | 
                                                        |
| 517 | + }  | 
                                                        |
| 518 | + // first we check if we're in admin and not doing front ajax  | 
                                                        |
| 519 | +		if (is_admin() && ! EE_FRONT_AJAX) { | 
                                                        |
| 520 | + //make sure appropriate admin params are set for sending messages  | 
                                                        |
| 521 | +			if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { | 
                                                        |
| 522 | + //no messages sent please.  | 
                                                        |
| 523 | + return false;  | 
                                                        |
| 524 | + }  | 
                                                        |
| 525 | +		} else { | 
                                                        |
| 526 | + // frontend request (either regular or via AJAX)  | 
                                                        |
| 527 | + // TXN is NOT finalized ?  | 
                                                        |
| 528 | +			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { | 
                                                        |
| 529 | + return false;  | 
                                                        |
| 530 | + }  | 
                                                        |
| 531 | + // return visit but nothing changed ???  | 
                                                        |
| 532 | + if (  | 
                                                        |
| 533 | + isset($extra_details['revisit'], $extra_details['status_updates']) &&  | 
                                                        |
| 534 | + $extra_details['revisit'] && ! $extra_details['status_updates']  | 
                                                        |
| 535 | +			) { | 
                                                        |
| 536 | + return false;  | 
                                                        |
| 537 | + }  | 
                                                        |
| 538 | + // NOT sending messages && reg status is something other than "Not-Approved"  | 
                                                        |
| 539 | + if (  | 
                                                        |
| 540 | +				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && | 
                                                        |
| 541 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved  | 
                                                        |
| 542 | +			) { | 
                                                        |
| 543 | + return false;  | 
                                                        |
| 544 | + }  | 
                                                        |
| 545 | + }  | 
                                                        |
| 546 | + // release the kraken  | 
                                                        |
| 547 | + return true;  | 
                                                        |
| 548 | + }  | 
                                                        |
| 549 | +  | 
                                                        |
| 550 | +  | 
                                                        |
| 551 | + /**  | 
                                                        |
| 552 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that  | 
                                                        |
| 553 | + * status id.  | 
                                                        |
| 554 | + *  | 
                                                        |
| 555 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array()  | 
                                                        |
| 556 | + * or EEH_MSG_Template::convert_reg_status_to_message_type  | 
                                                        |
| 557 | + * @param string $reg_status  | 
                                                        |
| 558 | + * @return array  | 
                                                        |
| 559 | + */  | 
                                                        |
| 560 | + protected static function _get_reg_status_array($reg_status = '')  | 
                                                        |
| 561 | +	{ | 
                                                        |
| 562 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 563 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 564 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 565 | + : EEH_MSG_Template::reg_status_to_message_type_array();  | 
                                                        |
| 566 | + }  | 
                                                        |
| 567 | +  | 
                                                        |
| 568 | +  | 
                                                        |
| 569 | + /**  | 
                                                        |
| 570 | + * Simply returns the payment message type for the given payment status.  | 
                                                        |
| 571 | + *  | 
                                                        |
| 572 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array  | 
                                                        |
| 573 | + * or EEH_MSG_Template::convert_payment_status_to_message_type  | 
                                                        |
| 574 | + * @param string $payment_status The payment status being matched.  | 
                                                        |
| 575 | + * @return string|bool The payment message type slug matching the status or false if no match.  | 
                                                        |
| 576 | + */  | 
                                                        |
| 577 | + protected static function _get_payment_message_type($payment_status)  | 
                                                        |
| 578 | +	{ | 
                                                        |
| 579 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 580 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 581 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 582 | + : false;  | 
                                                        |
| 583 | + }  | 
                                                        |
| 584 | +  | 
                                                        |
| 585 | +  | 
                                                        |
| 586 | + /**  | 
                                                        |
| 587 | + * Message triggers for a resending already sent message(s) (via EE_Message list table)  | 
                                                        |
| 588 | + *  | 
                                                        |
| 589 | + * @access public  | 
                                                        |
| 590 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages  | 
                                                        |
| 591 | + * @return bool success/fail  | 
                                                        |
| 592 | + */  | 
                                                        |
| 593 | + public static function process_resend($req_data)  | 
                                                        |
| 594 | +	{ | 
                                                        |
| 595 | + self::_load_controller();  | 
                                                        |
| 596 | +  | 
                                                        |
| 597 | + //if $msgID in this request then skip to the new resend_message  | 
                                                        |
| 598 | +		if (EE_Registry::instance()->REQ->get('MSG_ID')) { | 
                                                        |
| 599 | + return self::resend_message();  | 
                                                        |
| 600 | + }  | 
                                                        |
| 601 | +  | 
                                                        |
| 602 | + //make sure any incoming request data is set on the REQ so that it gets picked up later.  | 
                                                        |
| 603 | + $req_data = (array)$req_data;  | 
                                                        |
| 604 | +		foreach ($req_data as $request_key => $request_value) { | 
                                                        |
| 605 | + EE_Registry::instance()->REQ->set($request_key, $request_value);  | 
                                                        |
| 606 | + }  | 
                                                        |
| 607 | +  | 
                                                        |
| 608 | +		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { | 
                                                        |
| 609 | + return false;  | 
                                                        |
| 610 | + }  | 
                                                        |
| 611 | +  | 
                                                        |
| 612 | +		try { | 
                                                        |
| 613 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);  | 
                                                        |
| 614 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();  | 
                                                        |
| 615 | +		} catch (EE_Error $e) { | 
                                                        |
| 616 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 617 | + return false;  | 
                                                        |
| 618 | + }  | 
                                                        |
| 619 | + EE_Error::add_success(  | 
                                                        |
| 620 | +			__('Messages have been successfully queued for generation and sending.', 'event_espresso') | 
                                                        |
| 621 | + );  | 
                                                        |
| 622 | + return true; //everything got queued.  | 
                                                        |
| 623 | + }  | 
                                                        |
| 624 | +  | 
                                                        |
| 625 | +  | 
                                                        |
| 626 | + /**  | 
                                                        |
| 627 | + * Message triggers for a resending already sent message(s) (via EE_Message list table)  | 
                                                        |
| 628 | + *  | 
                                                        |
| 629 | + * @return bool  | 
                                                        |
| 630 | + */  | 
                                                        |
| 631 | + public static function resend_message()  | 
                                                        |
| 632 | +	{ | 
                                                        |
| 633 | + self::_load_controller();  | 
                                                        |
| 634 | +  | 
                                                        |
| 635 | +		$msgID = EE_Registry::instance()->REQ->get('MSG_ID'); | 
                                                        |
| 636 | +		if (! $msgID) { | 
                                                        |
| 637 | +			EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', | 
                                                        |
| 638 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 639 | + return false;  | 
                                                        |
| 640 | + }  | 
                                                        |
| 641 | +  | 
                                                        |
| 642 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);  | 
                                                        |
| 643 | +  | 
                                                        |
| 644 | + //setup success message.  | 
                                                        |
| 645 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);  | 
                                                        |
| 646 | + EE_Error::add_success(sprintf(  | 
                                                        |
| 647 | + _n(  | 
                                                        |
| 648 | + 'There was %d message queued for resending.',  | 
                                                        |
| 649 | + 'There were %d messages queued for resending.',  | 
                                                        |
| 650 | + $count_ready_for_resend,  | 
                                                        |
| 651 | + 'event_espresso'  | 
                                                        |
| 652 | + ),  | 
                                                        |
| 653 | + $count_ready_for_resend  | 
                                                        |
| 654 | + ));  | 
                                                        |
| 655 | + return true;  | 
                                                        |
| 656 | + }  | 
                                                        |
| 657 | +  | 
                                                        |
| 658 | +  | 
                                                        |
| 659 | + /**  | 
                                                        |
| 660 | + * Message triggers for manual payment applied by admin  | 
                                                        |
| 661 | + *  | 
                                                        |
| 662 | + * @param EE_Payment $payment EE_payment object  | 
                                                        |
| 663 | + * @return bool success/fail  | 
                                                        |
| 664 | + */  | 
                                                        |
| 665 | + public static function process_admin_payment(EE_Payment $payment)  | 
                                                        |
| 666 | +	{ | 
                                                        |
| 667 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 668 | + //we need to get the transaction object  | 
                                                        |
| 669 | + $transaction = $payment->transaction();  | 
                                                        |
| 670 | +		if ($transaction instanceof EE_Transaction) { | 
                                                        |
| 671 | + $data = array($transaction, $payment);  | 
                                                        |
| 672 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());  | 
                                                        |
| 673 | +  | 
                                                        |
| 674 | + //if payment amount is less than 0 then switch to payment_refund message type.  | 
                                                        |
| 675 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;  | 
                                                        |
| 676 | +  | 
                                                        |
| 677 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out.  | 
                                                        |
| 678 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;  | 
                                                        |
| 679 | +  | 
                                                        |
| 680 | + self::_load_controller();  | 
                                                        |
| 681 | +  | 
                                                        |
| 682 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);  | 
                                                        |
| 683 | +  | 
                                                        |
| 684 | + //get count of queued for generation  | 
                                                        |
| 685 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(  | 
                                                        |
| 686 | + EEM_Message::status_incomplete,  | 
                                                        |
| 687 | + EEM_Message::status_idle,  | 
                                                        |
| 688 | + ));  | 
                                                        |
| 689 | +  | 
                                                        |
| 690 | +			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { | 
                                                        |
| 691 | +				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); | 
                                                        |
| 692 | + return true;  | 
                                                        |
| 693 | +			} else { | 
                                                        |
| 694 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());  | 
                                                        |
| 695 | + /**  | 
                                                        |
| 696 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful  | 
                                                        |
| 697 | + * IMMEDIATE generation.  | 
                                                        |
| 698 | + */  | 
                                                        |
| 699 | +				if ($count_failed > 0) { | 
                                                        |
| 700 | + EE_Error::add_error(sprintf(  | 
                                                        |
| 701 | + _n(  | 
                                                        |
| 702 | + 'The payment notification generation failed.',  | 
                                                        |
| 703 | + '%d payment notifications failed being sent.',  | 
                                                        |
| 704 | + $count_failed,  | 
                                                        |
| 705 | + 'event_espresso'  | 
                                                        |
| 706 | + ),  | 
                                                        |
| 707 | + $count_failed  | 
                                                        |
| 708 | + ), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 709 | +  | 
                                                        |
| 710 | + return false;  | 
                                                        |
| 711 | +				} else { | 
                                                        |
| 712 | +					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); | 
                                                        |
| 713 | + return true;  | 
                                                        |
| 714 | + }  | 
                                                        |
| 715 | + }  | 
                                                        |
| 716 | +		} else { | 
                                                        |
| 717 | + EE_Error::add_error(  | 
                                                        |
| 718 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.',  | 
                                                        |
| 719 | + 'event_espresso'  | 
                                                        |
| 720 | + );  | 
                                                        |
| 721 | + return false;  | 
                                                        |
| 722 | + }  | 
                                                        |
| 723 | + }  | 
                                                        |
| 724 | +  | 
                                                        |
| 725 | +  | 
                                                        |
| 726 | + /**  | 
                                                        |
| 727 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger  | 
                                                        |
| 728 | + *  | 
                                                        |
| 729 | + * @since 4.3.0  | 
                                                        |
| 730 | + * @param EE_Registration[] $registrations an array of EE_Registration objects  | 
                                                        |
| 731 | + * @param int $grp_id a specific message template group id.  | 
                                                        |
| 732 | + * @return void  | 
                                                        |
| 733 | + */  | 
                                                        |
| 734 | + public static function send_newsletter_message($registrations, $grp_id)  | 
                                                        |
| 735 | +	{ | 
                                                        |
| 736 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup.  | 
                                                        |
| 737 | +		EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); | 
                                                        |
| 738 | + self::_load_controller();  | 
                                                        |
| 739 | +		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); | 
                                                        |
| 740 | + }  | 
                                                        |
| 741 | +  | 
                                                        |
| 742 | +  | 
                                                        |
| 743 | + /**  | 
                                                        |
| 744 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url  | 
                                                        |
| 745 | + *  | 
                                                        |
| 746 | + * @since 4.3.0  | 
                                                        |
| 747 | + * @param string $registration_message_trigger_url  | 
                                                        |
| 748 | + * @param EE_Registration $registration  | 
                                                        |
| 749 | + * @param string $messenger  | 
                                                        |
| 750 | + * @param string $message_type  | 
                                                        |
| 751 | + * @return string  | 
                                                        |
| 752 | + */  | 
                                                        |
| 753 | + public static function registration_message_trigger_url(  | 
                                                        |
| 754 | + $registration_message_trigger_url,  | 
                                                        |
| 755 | + EE_Registration $registration,  | 
                                                        |
| 756 | + $messenger = 'html',  | 
                                                        |
| 757 | + $message_type = 'invoice'  | 
                                                        |
| 758 | +	) { | 
                                                        |
| 759 | + // whitelist $messenger  | 
                                                        |
| 760 | +		switch ($messenger) { | 
                                                        |
| 761 | + case 'pdf' :  | 
                                                        |
| 762 | + $sending_messenger = 'pdf';  | 
                                                        |
| 763 | + $generating_messenger = 'html';  | 
                                                        |
| 764 | + break;  | 
                                                        |
| 765 | + case 'html' :  | 
                                                        |
| 766 | + default :  | 
                                                        |
| 767 | + $sending_messenger = 'html';  | 
                                                        |
| 768 | + $generating_messenger = 'html';  | 
                                                        |
| 769 | + break;  | 
                                                        |
| 770 | + }  | 
                                                        |
| 771 | + // whitelist $message_type  | 
                                                        |
| 772 | +		switch ($message_type) { | 
                                                        |
| 773 | + case 'receipt' :  | 
                                                        |
| 774 | + $message_type = 'receipt';  | 
                                                        |
| 775 | + break;  | 
                                                        |
| 776 | + case 'invoice' :  | 
                                                        |
| 777 | + default :  | 
                                                        |
| 778 | + $message_type = 'invoice';  | 
                                                        |
| 779 | + break;  | 
                                                        |
| 780 | + }  | 
                                                        |
| 781 | + // verify that both the messenger AND the message type are active  | 
                                                        |
| 782 | +		if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { | 
                                                        |
| 783 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)  | 
                                                        |
| 784 | + $template_query_params = array(  | 
                                                        |
| 785 | + 'MTP_is_active' => true,  | 
                                                        |
| 786 | + 'MTP_messenger' => $generating_messenger,  | 
                                                        |
| 787 | + 'MTP_message_type' => $message_type,  | 
                                                        |
| 788 | + 'Event.EVT_ID' => $registration->event_ID(),  | 
                                                        |
| 789 | + );  | 
                                                        |
| 790 | + //get the message template group.  | 
                                                        |
| 791 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));  | 
                                                        |
| 792 | + //if we don't have an EE_Message_Template_Group then return  | 
                                                        |
| 793 | +			if (! $msg_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 794 | + // remove EVT_ID from query params so that global templates get picked up  | 
                                                        |
| 795 | + unset($template_query_params['Event.EVT_ID']);  | 
                                                        |
| 796 | + //get global template as the fallback  | 
                                                        |
| 797 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));  | 
                                                        |
| 798 | + }  | 
                                                        |
| 799 | + //if we don't have an EE_Message_Template_Group then return  | 
                                                        |
| 800 | +			if (! $msg_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 801 | + return '';  | 
                                                        |
| 802 | + }  | 
                                                        |
| 803 | + // generate the URL  | 
                                                        |
| 804 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(  | 
                                                        |
| 805 | + $sending_messenger,  | 
                                                        |
| 806 | + $generating_messenger,  | 
                                                        |
| 807 | + 'purchaser',  | 
                                                        |
| 808 | + $message_type,  | 
                                                        |
| 809 | + $registration,  | 
                                                        |
| 810 | + $msg_template_group->ID(),  | 
                                                        |
| 811 | + $registration->transaction_ID()  | 
                                                        |
| 812 | + );  | 
                                                        |
| 813 | +  | 
                                                        |
| 814 | + }  | 
                                                        |
| 815 | + return $registration_message_trigger_url;  | 
                                                        |
| 816 | + }  | 
                                                        |
| 817 | +  | 
                                                        |
| 818 | +  | 
                                                        |
| 819 | + /**  | 
                                                        |
| 820 | + * Use to generate and return a message preview!  | 
                                                        |
| 821 | + *  | 
                                                        |
| 822 | + * @param string $type This should correspond with a valid message type  | 
                                                        |
| 823 | + * @param string $context This should correspond with a valid context for the message type  | 
                                                        |
| 824 | + * @param string $messenger This should correspond with a valid messenger.  | 
                                                        |
| 825 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular  | 
                                                        |
| 826 | + * preview  | 
                                                        |
| 827 | + * @return bool|string The body of the message or if send is requested, sends.  | 
                                                        |
| 828 | + * @throws EE_Error  | 
                                                        |
| 829 | + */  | 
                                                        |
| 830 | + public static function preview_message($type, $context, $messenger, $send = false)  | 
                                                        |
| 831 | +	{ | 
                                                        |
| 832 | + self::_load_controller();  | 
                                                        |
| 833 | + $mtg = new EE_Message_To_Generate(  | 
                                                        |
| 834 | + $messenger,  | 
                                                        |
| 835 | + $type,  | 
                                                        |
| 836 | + array(),  | 
                                                        |
| 837 | + $context,  | 
                                                        |
| 838 | + true  | 
                                                        |
| 839 | + );  | 
                                                        |
| 840 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);  | 
                                                        |
| 841 | +		if ($generated_preview_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 842 | + $content = $generated_preview_queue->get_message_repository()->current()->content();  | 
                                                        |
| 843 | + //if the current message was persisted to the db (which will happen with any extra fields on a message) then  | 
                                                        |
| 844 | + //let's delete it because we don't need previews cluttering up the db.  | 
                                                        |
| 845 | + if ($generated_preview_queue->get_message_repository()->current()->ID() > 0  | 
                                                        |
| 846 | + && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed  | 
                                                        |
| 847 | +			) { | 
                                                        |
| 848 | + $generated_preview_queue->get_message_repository()->delete();  | 
                                                        |
| 849 | + }  | 
                                                        |
| 850 | + return $content;  | 
                                                        |
| 851 | +		} else { | 
                                                        |
| 852 | + return $generated_preview_queue;  | 
                                                        |
| 853 | + }  | 
                                                        |
| 854 | + }  | 
                                                        |
| 855 | +  | 
                                                        |
| 856 | +  | 
                                                        |
| 857 | + /**  | 
                                                        |
| 858 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided  | 
                                                        |
| 859 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the  | 
                                                        |
| 860 | + * content found in the EE_Message objects in the queue.  | 
                                                        |
| 861 | + *  | 
                                                        |
| 862 | + * @since 4.9.0  | 
                                                        |
| 863 | + * @param string $messenger a string matching a valid active messenger in the system  | 
                                                        |
| 864 | + * @param string $message_type Although it seems contrary to the name of the method, a message  | 
                                                        |
| 865 | + * type name is still required to send along the message type to the  | 
                                                        |
| 866 | + * messenger because this is used for determining what specific  | 
                                                        |
| 867 | + * variations might be loaded for the generated message.  | 
                                                        |
| 868 | + * @param EE_Messages_Queue $queue  | 
                                                        |
| 869 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the  | 
                                                        |
| 870 | + * aggregate EE_Message object.  | 
                                                        |
| 871 | + * @return bool success or fail.  | 
                                                        |
| 872 | + */  | 
                                                        |
| 873 | + public static function send_message_with_messenger_only(  | 
                                                        |
| 874 | + $messenger,  | 
                                                        |
| 875 | + $message_type,  | 
                                                        |
| 876 | + EE_Messages_Queue $queue,  | 
                                                        |
| 877 | + $custom_subject = ''  | 
                                                        |
| 878 | +	) { | 
                                                        |
| 879 | + self::_load_controller();  | 
                                                        |
| 880 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */  | 
                                                        |
| 881 | + $message_to_generate = EE_Registry::instance()->load_lib(  | 
                                                        |
| 882 | + 'Message_To_Generate_From_Queue',  | 
                                                        |
| 883 | + array(  | 
                                                        |
| 884 | + $messenger,  | 
                                                        |
| 885 | + $message_type,  | 
                                                        |
| 886 | + $queue,  | 
                                                        |
| 887 | + $custom_subject,  | 
                                                        |
| 888 | + )  | 
                                                        |
| 889 | + );  | 
                                                        |
| 890 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);  | 
                                                        |
| 891 | + }  | 
                                                        |
| 892 | +  | 
                                                        |
| 893 | +  | 
                                                        |
| 894 | + /**  | 
                                                        |
| 895 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)  | 
                                                        |
| 896 | + *  | 
                                                        |
| 897 | + * @since 4.9.0  | 
                                                        |
| 898 | + * @param array $message_ids An array of message ids  | 
                                                        |
| 899 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated  | 
                                                        |
| 900 | + * messages.  | 
                                                        |
| 901 | + */  | 
                                                        |
| 902 | + public static function generate_now($message_ids)  | 
                                                        |
| 903 | +	{ | 
                                                        |
| 904 | + self::_load_controller();  | 
                                                        |
| 905 | + $messages = EEM_Message::instance()->get_all(  | 
                                                        |
| 906 | + array(  | 
                                                        |
| 907 | + 0 => array(  | 
                                                        |
| 908 | +					'MSG_ID' => array('IN', $message_ids), | 
                                                        |
| 909 | + 'STS_ID' => EEM_Message::status_incomplete,  | 
                                                        |
| 910 | + ),  | 
                                                        |
| 911 | + )  | 
                                                        |
| 912 | + );  | 
                                                        |
| 913 | + $generated_queue = false;  | 
                                                        |
| 914 | +		if ($messages) { | 
                                                        |
| 915 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);  | 
                                                        |
| 916 | + }  | 
                                                        |
| 917 | +  | 
                                                        |
| 918 | +		if (! $generated_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 919 | + EE_Error::add_error(  | 
                                                        |
| 920 | +				__('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', | 
                                                        |
| 921 | + 'event_espresso'),  | 
                                                        |
| 922 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 923 | + );  | 
                                                        |
| 924 | + }  | 
                                                        |
| 925 | + return $generated_queue;  | 
                                                        |
| 926 | + }  | 
                                                        |
| 927 | +  | 
                                                        |
| 928 | +  | 
                                                        |
| 929 | + /**  | 
                                                        |
| 930 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,  | 
                                                        |
| 931 | + * EEM_Message::status_idle  | 
                                                        |
| 932 | + *  | 
                                                        |
| 933 | + * @since 4.9.0  | 
                                                        |
| 934 | + * @param $message_ids  | 
                                                        |
| 935 | + * @return bool | EE_Messages_Queue false if no messages sent.  | 
                                                        |
| 936 | + */  | 
                                                        |
| 937 | + public static function send_now($message_ids)  | 
                                                        |
| 938 | +	{ | 
                                                        |
| 939 | + self::_load_controller();  | 
                                                        |
| 940 | + $messages = EEM_Message::instance()->get_all(  | 
                                                        |
| 941 | + array(  | 
                                                        |
| 942 | + 0 => array(  | 
                                                        |
| 943 | +					'MSG_ID' => array('IN', $message_ids), | 
                                                        |
| 944 | + 'STS_ID' => array(  | 
                                                        |
| 945 | + 'IN',  | 
                                                        |
| 946 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),  | 
                                                        |
| 947 | + ),  | 
                                                        |
| 948 | + ),  | 
                                                        |
| 949 | + )  | 
                                                        |
| 950 | + );  | 
                                                        |
| 951 | + $sent_queue = false;  | 
                                                        |
| 952 | +		if ($messages) { | 
                                                        |
| 953 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);  | 
                                                        |
| 954 | + }  | 
                                                        |
| 955 | +  | 
                                                        |
| 956 | +		if (! $sent_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 957 | + EE_Error::add_error(  | 
                                                        |
| 958 | +				__('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', | 
                                                        |
| 959 | + 'event_espresso'),  | 
                                                        |
| 960 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 961 | + );  | 
                                                        |
| 962 | +		} else { | 
                                                        |
| 963 | + //can count how many sent by using the messages in the queue  | 
                                                        |
| 964 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());  | 
                                                        |
| 965 | +			if ($sent_count > 0) { | 
                                                        |
| 966 | + EE_Error::add_success(  | 
                                                        |
| 967 | + sprintf(  | 
                                                        |
| 968 | + _n(  | 
                                                        |
| 969 | + 'There was %d message successfully sent.',  | 
                                                        |
| 970 | + 'There were %d messages successfully sent.',  | 
                                                        |
| 971 | + $sent_count,  | 
                                                        |
| 972 | + 'event_espresso'  | 
                                                        |
| 973 | + ),  | 
                                                        |
| 974 | + $sent_count  | 
                                                        |
| 975 | + )  | 
                                                        |
| 976 | + );  | 
                                                        |
| 977 | +			} else { | 
                                                        |
| 978 | + EE_Error::overwrite_errors();  | 
                                                        |
| 979 | + EE_Error::add_error(  | 
                                                        |
| 980 | +					__('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. | 
                                                        |
| 981 | 981 | If there was an error, you can look at the messages in the message activity list table for any error messages.',  | 
                                                        
| 982 | - 'event_espresso'),  | 
                                                        |
| 983 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 984 | - );  | 
                                                        |
| 985 | - }  | 
                                                        |
| 986 | - }  | 
                                                        |
| 987 | - return $sent_queue;  | 
                                                        |
| 988 | - }  | 
                                                        |
| 989 | -  | 
                                                        |
| 990 | -  | 
                                                        |
| 991 | - /**  | 
                                                        |
| 992 | - * This will queue the incoming message ids for resending.  | 
                                                        |
| 993 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.  | 
                                                        |
| 994 | - *  | 
                                                        |
| 995 | - * @since 4.9.0  | 
                                                        |
| 996 | - * @param array $message_ids An array of EE_Message IDs  | 
                                                        |
| 997 | - * @return bool true means messages were successfully queued for resending, false means none were queued for  | 
                                                        |
| 998 | - * resending.  | 
                                                        |
| 999 | - */  | 
                                                        |
| 1000 | - public static function queue_for_resending($message_ids)  | 
                                                        |
| 1001 | -    { | 
                                                        |
| 1002 | - self::_load_controller();  | 
                                                        |
| 1003 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);  | 
                                                        |
| 1004 | -  | 
                                                        |
| 1005 | - //get queue and count  | 
                                                        |
| 1006 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);  | 
                                                        |
| 1007 | -  | 
                                                        |
| 1008 | - if (  | 
                                                        |
| 1009 | - $queue_count > 0  | 
                                                        |
| 1010 | -        ) { | 
                                                        |
| 1011 | - EE_Error::add_success(  | 
                                                        |
| 1012 | - sprintf(  | 
                                                        |
| 1013 | - _n(  | 
                                                        |
| 1014 | - '%d message successfully queued for resending.',  | 
                                                        |
| 1015 | - '%d messages successfully queued for resending.',  | 
                                                        |
| 1016 | - $queue_count,  | 
                                                        |
| 1017 | - 'event_espresso'  | 
                                                        |
| 1018 | - ),  | 
                                                        |
| 1019 | - $queue_count  | 
                                                        |
| 1020 | - )  | 
                                                        |
| 1021 | - );  | 
                                                        |
| 1022 | - /**  | 
                                                        |
| 1023 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority  | 
                                                        |
| 1024 | - */  | 
                                                        |
| 1025 | - } elseif (  | 
                                                        |
| 1026 | -            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) | 
                                                        |
| 1027 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request  | 
                                                        |
| 1028 | -        ) { | 
                                                        |
| 1029 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);  | 
                                                        |
| 1030 | -            if ($queue_count > 0) { | 
                                                        |
| 1031 | - EE_Error::add_success(  | 
                                                        |
| 1032 | - sprintf(  | 
                                                        |
| 1033 | - _n(  | 
                                                        |
| 1034 | - '%d message successfully sent.',  | 
                                                        |
| 1035 | - '%d messages successfully sent.',  | 
                                                        |
| 1036 | - $queue_count,  | 
                                                        |
| 1037 | - 'event_espresso'  | 
                                                        |
| 1038 | - ),  | 
                                                        |
| 1039 | - $queue_count  | 
                                                        |
| 1040 | - )  | 
                                                        |
| 1041 | - );  | 
                                                        |
| 1042 | -            } else { | 
                                                        |
| 1043 | - EE_Error::add_error(  | 
                                                        |
| 1044 | -                    __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', | 
                                                        |
| 1045 | - 'event_espresso'),  | 
                                                        |
| 1046 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1047 | - );  | 
                                                        |
| 1048 | - }  | 
                                                        |
| 1049 | -        } else { | 
                                                        |
| 1050 | - EE_Error::add_error(  | 
                                                        |
| 1051 | -                __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', | 
                                                        |
| 1052 | - 'event_espresso'),  | 
                                                        |
| 1053 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1054 | - );  | 
                                                        |
| 1055 | - }  | 
                                                        |
| 1056 | - return (bool)$queue_count;  | 
                                                        |
| 1057 | - }  | 
                                                        |
| 1058 | -  | 
                                                        |
| 1059 | -  | 
                                                        |
| 1060 | - /**  | 
                                                        |
| 1061 | - * debug  | 
                                                        |
| 1062 | - *  | 
                                                        |
| 1063 | - * @param string $class  | 
                                                        |
| 1064 | - * @param string $func  | 
                                                        |
| 1065 | - * @param string $line  | 
                                                        |
| 1066 | - * @param \EE_Transaction $transaction  | 
                                                        |
| 1067 | - * @param array $info  | 
                                                        |
| 1068 | - * @param bool $display_request  | 
                                                        |
| 1069 | - */  | 
                                                        |
| 1070 | - protected static function log(  | 
                                                        |
| 1071 | - $class = '',  | 
                                                        |
| 1072 | - $func = '',  | 
                                                        |
| 1073 | - $line = '',  | 
                                                        |
| 1074 | - EE_Transaction $transaction,  | 
                                                        |
| 1075 | - $info = array(),  | 
                                                        |
| 1076 | - $display_request = false  | 
                                                        |
| 1077 | -    ) { | 
                                                        |
| 1078 | -        if (WP_DEBUG && false) { | 
                                                        |
| 1079 | -            if ($transaction instanceof EE_Transaction) { | 
                                                        |
| 1080 | - // don't serialize objects  | 
                                                        |
| 1081 | - $info = EEH_Debug_Tools::strip_objects($info);  | 
                                                        |
| 1082 | - $info['TXN_status'] = $transaction->status_ID();  | 
                                                        |
| 1083 | - $info['TXN_reg_steps'] = $transaction->reg_steps();  | 
                                                        |
| 1084 | -                if ($transaction->ID()) { | 
                                                        |
| 1085 | - $index = 'EE_Transaction: ' . $transaction->ID();  | 
                                                        |
| 1086 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);  | 
                                                        |
| 1087 | - }  | 
                                                        |
| 1088 | - }  | 
                                                        |
| 1089 | - }  | 
                                                        |
| 1090 | -  | 
                                                        |
| 1091 | - }  | 
                                                        |
| 1092 | -  | 
                                                        |
| 1093 | -  | 
                                                        |
| 1094 | - /**  | 
                                                        |
| 1095 | - * Resets all the static properties in this class when called.  | 
                                                        |
| 1096 | - */  | 
                                                        |
| 1097 | - public static function reset()  | 
                                                        |
| 1098 | -    { | 
                                                        |
| 1099 | - self::$_EEMSG = null;  | 
                                                        |
| 1100 | - self::$_message_resource_manager = null;  | 
                                                        |
| 1101 | - self::$_MSG_PROCESSOR = null;  | 
                                                        |
| 1102 | - self::$_MSG_PATHS = null;  | 
                                                        |
| 1103 | - self::$_TMP_PACKS = array();  | 
                                                        |
| 1104 | - }  | 
                                                        |
| 982 | + 'event_espresso'),  | 
                                                        |
| 983 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 984 | + );  | 
                                                        |
| 985 | + }  | 
                                                        |
| 986 | + }  | 
                                                        |
| 987 | + return $sent_queue;  | 
                                                        |
| 988 | + }  | 
                                                        |
| 989 | +  | 
                                                        |
| 990 | +  | 
                                                        |
| 991 | + /**  | 
                                                        |
| 992 | + * This will queue the incoming message ids for resending.  | 
                                                        |
| 993 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.  | 
                                                        |
| 994 | + *  | 
                                                        |
| 995 | + * @since 4.9.0  | 
                                                        |
| 996 | + * @param array $message_ids An array of EE_Message IDs  | 
                                                        |
| 997 | + * @return bool true means messages were successfully queued for resending, false means none were queued for  | 
                                                        |
| 998 | + * resending.  | 
                                                        |
| 999 | + */  | 
                                                        |
| 1000 | + public static function queue_for_resending($message_ids)  | 
                                                        |
| 1001 | +	{ | 
                                                        |
| 1002 | + self::_load_controller();  | 
                                                        |
| 1003 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);  | 
                                                        |
| 1004 | +  | 
                                                        |
| 1005 | + //get queue and count  | 
                                                        |
| 1006 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);  | 
                                                        |
| 1007 | +  | 
                                                        |
| 1008 | + if (  | 
                                                        |
| 1009 | + $queue_count > 0  | 
                                                        |
| 1010 | +		) { | 
                                                        |
| 1011 | + EE_Error::add_success(  | 
                                                        |
| 1012 | + sprintf(  | 
                                                        |
| 1013 | + _n(  | 
                                                        |
| 1014 | + '%d message successfully queued for resending.',  | 
                                                        |
| 1015 | + '%d messages successfully queued for resending.',  | 
                                                        |
| 1016 | + $queue_count,  | 
                                                        |
| 1017 | + 'event_espresso'  | 
                                                        |
| 1018 | + ),  | 
                                                        |
| 1019 | + $queue_count  | 
                                                        |
| 1020 | + )  | 
                                                        |
| 1021 | + );  | 
                                                        |
| 1022 | + /**  | 
                                                        |
| 1023 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority  | 
                                                        |
| 1024 | + */  | 
                                                        |
| 1025 | + } elseif (  | 
                                                        |
| 1026 | +			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) | 
                                                        |
| 1027 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request  | 
                                                        |
| 1028 | +		) { | 
                                                        |
| 1029 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);  | 
                                                        |
| 1030 | +			if ($queue_count > 0) { | 
                                                        |
| 1031 | + EE_Error::add_success(  | 
                                                        |
| 1032 | + sprintf(  | 
                                                        |
| 1033 | + _n(  | 
                                                        |
| 1034 | + '%d message successfully sent.',  | 
                                                        |
| 1035 | + '%d messages successfully sent.',  | 
                                                        |
| 1036 | + $queue_count,  | 
                                                        |
| 1037 | + 'event_espresso'  | 
                                                        |
| 1038 | + ),  | 
                                                        |
| 1039 | + $queue_count  | 
                                                        |
| 1040 | + )  | 
                                                        |
| 1041 | + );  | 
                                                        |
| 1042 | +			} else { | 
                                                        |
| 1043 | + EE_Error::add_error(  | 
                                                        |
| 1044 | +					__('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', | 
                                                        |
| 1045 | + 'event_espresso'),  | 
                                                        |
| 1046 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1047 | + );  | 
                                                        |
| 1048 | + }  | 
                                                        |
| 1049 | +		} else { | 
                                                        |
| 1050 | + EE_Error::add_error(  | 
                                                        |
| 1051 | +				__('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', | 
                                                        |
| 1052 | + 'event_espresso'),  | 
                                                        |
| 1053 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1054 | + );  | 
                                                        |
| 1055 | + }  | 
                                                        |
| 1056 | + return (bool)$queue_count;  | 
                                                        |
| 1057 | + }  | 
                                                        |
| 1058 | +  | 
                                                        |
| 1059 | +  | 
                                                        |
| 1060 | + /**  | 
                                                        |
| 1061 | + * debug  | 
                                                        |
| 1062 | + *  | 
                                                        |
| 1063 | + * @param string $class  | 
                                                        |
| 1064 | + * @param string $func  | 
                                                        |
| 1065 | + * @param string $line  | 
                                                        |
| 1066 | + * @param \EE_Transaction $transaction  | 
                                                        |
| 1067 | + * @param array $info  | 
                                                        |
| 1068 | + * @param bool $display_request  | 
                                                        |
| 1069 | + */  | 
                                                        |
| 1070 | + protected static function log(  | 
                                                        |
| 1071 | + $class = '',  | 
                                                        |
| 1072 | + $func = '',  | 
                                                        |
| 1073 | + $line = '',  | 
                                                        |
| 1074 | + EE_Transaction $transaction,  | 
                                                        |
| 1075 | + $info = array(),  | 
                                                        |
| 1076 | + $display_request = false  | 
                                                        |
| 1077 | +	) { | 
                                                        |
| 1078 | +		if (WP_DEBUG && false) { | 
                                                        |
| 1079 | +			if ($transaction instanceof EE_Transaction) { | 
                                                        |
| 1080 | + // don't serialize objects  | 
                                                        |
| 1081 | + $info = EEH_Debug_Tools::strip_objects($info);  | 
                                                        |
| 1082 | + $info['TXN_status'] = $transaction->status_ID();  | 
                                                        |
| 1083 | + $info['TXN_reg_steps'] = $transaction->reg_steps();  | 
                                                        |
| 1084 | +				if ($transaction->ID()) { | 
                                                        |
| 1085 | + $index = 'EE_Transaction: ' . $transaction->ID();  | 
                                                        |
| 1086 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);  | 
                                                        |
| 1087 | + }  | 
                                                        |
| 1088 | + }  | 
                                                        |
| 1089 | + }  | 
                                                        |
| 1090 | +  | 
                                                        |
| 1091 | + }  | 
                                                        |
| 1092 | +  | 
                                                        |
| 1093 | +  | 
                                                        |
| 1094 | + /**  | 
                                                        |
| 1095 | + * Resets all the static properties in this class when called.  | 
                                                        |
| 1096 | + */  | 
                                                        |
| 1097 | + public static function reset()  | 
                                                        |
| 1098 | +	{ | 
                                                        |
| 1099 | + self::$_EEMSG = null;  | 
                                                        |
| 1100 | + self::$_message_resource_manager = null;  | 
                                                        |
| 1101 | + self::$_MSG_PROCESSOR = null;  | 
                                                        |
| 1102 | + self::$_MSG_PATHS = null;  | 
                                                        |
| 1103 | + self::$_TMP_PACKS = array();  | 
                                                        |
| 1104 | + }  | 
                                                        |
| 1105 | 1105 | |
| 1106 | 1106 | }  | 
                                                        
| 1107 | 1107 | // End of file EED_Messages.module.php  | 
                                                        
@@ -35,7 +35,7 @@ discard block  | 
                                                    ||
| 35 | 35 | *  | 
                                                        
| 36 | 36 | * @param EE_Message_Resource_Manager $message_resource_manager  | 
                                                        
| 37 | 37 | */  | 
                                                        
| 38 | -	public function __construct( EE_Message_Resource_Manager $message_resource_manager ) { | 
                                                        |
| 38 | +	public function __construct(EE_Message_Resource_Manager $message_resource_manager) { | 
                                                        |
| 39 | 39 | $this->_message_resource_manager = $message_resource_manager;  | 
                                                        
| 40 | 40 | $this->_init_queue_and_generator();  | 
                                                        
| 41 | 41 | }  | 
                                                        
@@ -50,7 +50,7 @@ discard block  | 
                                                    ||
| 50 | 50 | * - $_generator = holds the messages generator  | 
                                                        
| 51 | 51 | */  | 
                                                        
| 52 | 52 |  	protected function _init_queue_and_generator() { | 
                                                        
| 53 | - $this->_generator = EE_Registry::factory( 'EE_Messages_Generator' );  | 
                                                        |
| 53 | +		$this->_generator = EE_Registry::factory('EE_Messages_Generator'); | 
                                                        |
| 54 | 54 | $this->_queue = $this->_generator->generation_queue();  | 
                                                        
| 55 | 55 | }  | 
                                                        
| 56 | 56 | |
@@ -75,31 +75,31 @@ discard block  | 
                                                    ||
| 75 | 75 | * @param EE_Messages_Queue $queue_to_process  | 
                                                        
| 76 | 76 | * @return bool true for success false for error.  | 
                                                        
| 77 | 77 | */  | 
                                                        
| 78 | -	public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) { | 
                                                        |
| 78 | +	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) { | 
                                                        |
| 79 | 79 | $success = false;  | 
                                                        
| 80 | 80 | $messages_to_send = array();  | 
                                                        
| 81 | 81 | $messages_to_generate = array();  | 
                                                        
| 82 | 82 | //loop through and setup the various messages from the queue so we know what is being processed  | 
                                                        
| 83 | 83 | $queue_to_process->get_message_repository()->rewind();  | 
                                                        
| 84 | -		foreach ( $queue_to_process->get_message_repository() as $message ) { | 
                                                        |
| 85 | -			if ( $message->STS_ID() === EEM_Message::status_incomplete ) { | 
                                                        |
| 84 | +		foreach ($queue_to_process->get_message_repository() as $message) { | 
                                                        |
| 85 | +			if ($message->STS_ID() === EEM_Message::status_incomplete) { | 
                                                        |
| 86 | 86 | $messages_to_generate[] = $message;  | 
                                                        
| 87 | 87 | continue;  | 
                                                        
| 88 | 88 | }  | 
                                                        
| 89 | 89 | |
| 90 | -			if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) { | 
                                                        |
| 90 | +			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { | 
                                                        |
| 91 | 91 | $messages_to_send[] = $message;  | 
                                                        
| 92 | 92 | continue;  | 
                                                        
| 93 | 93 | }  | 
                                                        
| 94 | 94 | }  | 
                                                        
| 95 | 95 | |
| 96 | 96 | //do generation/sends  | 
                                                        
| 97 | -		if ( $messages_to_generate ) { | 
                                                        |
| 98 | - $success = $this->batch_generate_from_queue( $messages_to_generate, true );  | 
                                                        |
| 97 | +		if ($messages_to_generate) { | 
                                                        |
| 98 | + $success = $this->batch_generate_from_queue($messages_to_generate, true);  | 
                                                        |
| 99 | 99 | }  | 
                                                        
| 100 | 100 | |
| 101 | -		if ( $messages_to_send ) { | 
                                                        |
| 102 | - $sent = $this->batch_send_from_queue( $messages_to_send, true );  | 
                                                        |
| 101 | +		if ($messages_to_send) { | 
                                                        |
| 102 | + $sent = $this->batch_send_from_queue($messages_to_send, true);  | 
                                                        |
| 103 | 103 | //if there was messages to generate and it failed, then we override any success value for the sending process  | 
                                                        
| 104 | 104 | //otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail.  | 
                                                        
| 105 | 105 | //Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing  | 
                                                        
@@ -119,13 +119,13 @@ discard block  | 
                                                    ||
| 119 | 119 | * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with  | 
                                                        
| 120 | 120 | * generated messages.  | 
                                                        
| 121 | 121 | */  | 
                                                        
| 122 | -	public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) { | 
                                                        |
| 123 | -		if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) { | 
                                                        |
| 122 | +	public function batch_generate_from_queue($messages = array(), $clear_queue = false) { | 
                                                        |
| 123 | +		if ($this->_build_queue_for_generation($messages, $clear_queue)) { | 
                                                        |
| 124 | 124 | $new_queue = $this->_generator->generate();  | 
                                                        
| 125 | -			if ( $new_queue instanceof EE_Messages_Queue ) { | 
                                                        |
| 125 | +			if ($new_queue instanceof EE_Messages_Queue) { | 
                                                        |
| 126 | 126 | //unlock queue  | 
                                                        
| 127 | 127 | $this->_queue->unlock_queue();  | 
                                                        
| 128 | - $new_queue->initiate_request_by_priority( 'send' );  | 
                                                        |
| 128 | +				$new_queue->initiate_request_by_priority('send'); | 
                                                        |
| 129 | 129 | return $new_queue;  | 
                                                        
| 130 | 130 | }  | 
                                                        
| 131 | 131 | }  | 
                                                        
@@ -146,24 +146,24 @@ discard block  | 
                                                    ||
| 146 | 146 | *  | 
                                                        
| 147 | 147 | * @return bool true means queue prepped, false means there was a lock so no generation please.  | 
                                                        
| 148 | 148 | */  | 
                                                        
| 149 | -	protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) { | 
                                                        |
| 149 | +	protected function _build_queue_for_generation($messages = array(), $clear_queue = false) { | 
                                                        |
| 150 | 150 | |
| 151 | -		if ( $clear_queue ) { | 
                                                        |
| 151 | +		if ($clear_queue) { | 
                                                        |
| 152 | 152 | $this->_init_queue_and_generator();  | 
                                                        
| 153 | 153 | }  | 
                                                        
| 154 | 154 | |
| 155 | -		if ( $messages ) { | 
                                                        |
| 155 | +		if ($messages) { | 
                                                        |
| 156 | 156 | //if generation is locked then get out now because that means processing is already happening.  | 
                                                        
| 157 | -			if ( $this->_queue->is_locked() ) { | 
                                                        |
| 157 | +			if ($this->_queue->is_locked()) { | 
                                                        |
| 158 | 158 | return false;  | 
                                                        
| 159 | 159 | }  | 
                                                        
| 160 | 160 | |
| 161 | 161 | $this->_queue->lock_queue();  | 
                                                        
| 162 | - $messages = is_array( $messages ) ? $messages : array( $messages );  | 
                                                        |
| 163 | -			foreach ( $messages as $message ) { | 
                                                        |
| 164 | -				if ( $message instanceof EE_Message ) { | 
                                                        |
| 162 | + $messages = is_array($messages) ? $messages : array($messages);  | 
                                                        |
| 163 | +			foreach ($messages as $message) { | 
                                                        |
| 164 | +				if ($message instanceof EE_Message) { | 
                                                        |
| 165 | 165 | $data = $message->all_extra_meta_array();  | 
                                                        
| 166 | - $this->_queue->add( $message, $data );  | 
                                                        |
| 166 | + $this->_queue->add($message, $data);  | 
                                                        |
| 167 | 167 | }  | 
                                                        
| 168 | 168 | }  | 
                                                        
| 169 | 169 | return true;  | 
                                                        
@@ -181,22 +181,22 @@ discard block  | 
                                                    ||
| 181 | 181 | *  | 
                                                        
| 182 | 182 | * @return bool true means queue prepped, false means there was a lock so no queue prepped.  | 
                                                        
| 183 | 183 | */  | 
                                                        
| 184 | -	protected function _build_queue_for_sending( $messages, $clear_queue = false ) { | 
                                                        |
| 184 | +	protected function _build_queue_for_sending($messages, $clear_queue = false) { | 
                                                        |
| 185 | 185 | //if sending is locked then get out now because that means processing is already happening.  | 
                                                        
| 186 | -		if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) { | 
                                                        |
| 186 | +		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { | 
                                                        |
| 187 | 187 | return false;  | 
                                                        
| 188 | 188 | }  | 
                                                        
| 189 | 189 | |
| 190 | - $this->_queue->lock_queue( EE_Messages_Queue::action_sending );  | 
                                                        |
| 190 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending);  | 
                                                        |
| 191 | 191 | |
| 192 | -		if ( $clear_queue ) { | 
                                                        |
| 192 | +		if ($clear_queue) { | 
                                                        |
| 193 | 193 | $this->_init_queue_and_generator();  | 
                                                        
| 194 | 194 | }  | 
                                                        
| 195 | 195 | |
| 196 | - $messages = is_array( $messages ) ? $messages : array( $messages );  | 
                                                        |
| 196 | + $messages = is_array($messages) ? $messages : array($messages);  | 
                                                        |
| 197 | 197 | |
| 198 | -		foreach ( $messages as $message ) { | 
                                                        |
| 199 | - $this->_queue->add( $message );  | 
                                                        |
| 198 | +		foreach ($messages as $message) { | 
                                                        |
| 199 | + $this->_queue->add($message);  | 
                                                        |
| 200 | 200 | }  | 
                                                        
| 201 | 201 | return true;  | 
                                                        
| 202 | 202 | }  | 
                                                        
@@ -212,11 +212,11 @@ discard block  | 
                                                    ||
| 212 | 212 | *  | 
                                                        
| 213 | 213 | * @return EE_Messages_Queue  | 
                                                        
| 214 | 214 | */  | 
                                                        
| 215 | -	public function batch_send_from_queue( $messages = array(), $clear_queue = false ) { | 
                                                        |
| 215 | +	public function batch_send_from_queue($messages = array(), $clear_queue = false) { | 
                                                        |
| 216 | 216 | |
| 217 | -		if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) { | 
                                                        |
| 217 | +		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { | 
                                                        |
| 218 | 218 | $this->_queue->execute();  | 
                                                        
| 219 | - $this->_queue->unlock_queue( EE_Messages_Queue::action_sending );  | 
                                                        |
| 219 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending);  | 
                                                        |
| 220 | 220 |  		} else { | 
                                                        
| 221 | 221 | //get messages to send and execute.  | 
                                                        
| 222 | 222 | $this->_queue->get_to_send_batch_and_send();  | 
                                                        
@@ -239,10 +239,10 @@ discard block  | 
                                                    ||
| 239 | 239 | * @param EE_Message_To_Generate[] $messages_to_generate  | 
                                                        
| 240 | 240 | * @return EE_Messages_Queue  | 
                                                        
| 241 | 241 | */  | 
                                                        
| 242 | -	public function generate_and_return(  $messages_to_generate ) { | 
                                                        |
| 242 | +	public function generate_and_return($messages_to_generate) { | 
                                                        |
| 243 | 243 | $this->_init_queue_and_generator();  | 
                                                        
| 244 | - $this->_queue_for_generation_loop( $messages_to_generate );  | 
                                                        |
| 245 | - return $this->_generator->generate( false );  | 
                                                        |
| 244 | + $this->_queue_for_generation_loop($messages_to_generate);  | 
                                                        |
| 245 | + return $this->_generator->generate(false);  | 
                                                        |
| 246 | 246 | }  | 
                                                        
| 247 | 247 | |
| 248 | 248 | |
@@ -253,8 +253,8 @@ discard block  | 
                                                    ||
| 253 | 253 | * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false).  | 
                                                        
| 254 | 254 | * @return EE_Messages_Queue  | 
                                                        
| 255 | 255 | */  | 
                                                        
| 256 | -	public function generate_queue( $persist = true ) { | 
                                                        |
| 257 | - return $this->_generator->generate( $persist );  | 
                                                        |
| 256 | +	public function generate_queue($persist = true) { | 
                                                        |
| 257 | + return $this->_generator->generate($persist);  | 
                                                        |
| 258 | 258 | }  | 
                                                        
| 259 | 259 | |
| 260 | 260 | |
@@ -267,9 +267,9 @@ discard block  | 
                                                    ||
| 267 | 267 | * @param bool $test_send Whether this item is for a test send or not.  | 
                                                        
| 268 | 268 | * @return EE_Messages_Queue  | 
                                                        
| 269 | 269 | */  | 
                                                        
| 270 | -	public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) { | 
                                                        |
| 271 | -		if ( $message_to_generate->valid() ) { | 
                                                        |
| 272 | - $this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send );  | 
                                                        |
| 270 | +	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) { | 
                                                        |
| 271 | +		if ($message_to_generate->valid()) { | 
                                                        |
| 272 | + $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);  | 
                                                        |
| 273 | 273 | }  | 
                                                        
| 274 | 274 | }  | 
                                                        
| 275 | 275 | |
@@ -285,9 +285,9 @@ discard block  | 
                                                    ||
| 285 | 285 | *  | 
                                                        
| 286 | 286 | * @param EE_Message_To_Generate[] $messages_to_generate  | 
                                                        
| 287 | 287 | */  | 
                                                        
| 288 | -	public function batch_queue_for_generation_and_persist( $messages_to_generate ) { | 
                                                        |
| 288 | +	public function batch_queue_for_generation_and_persist($messages_to_generate) { | 
                                                        |
| 289 | 289 | $this->_init_queue_and_generator();  | 
                                                        
| 290 | - $this->_queue_for_generation_loop( $messages_to_generate );  | 
                                                        |
| 290 | + $this->_queue_for_generation_loop($messages_to_generate);  | 
                                                        |
| 291 | 291 | $this->_queue->save();  | 
                                                        
| 292 | 292 | }  | 
                                                        
| 293 | 293 | |
@@ -303,9 +303,9 @@ discard block  | 
                                                    ||
| 303 | 303 | *  | 
                                                        
| 304 | 304 | * @param EE_Message_To_Generate[] $messages_to_generate  | 
                                                        
| 305 | 305 | */  | 
                                                        
| 306 | -	public function batch_queue_for_generation_no_persist( $messages_to_generate ) { | 
                                                        |
| 306 | +	public function batch_queue_for_generation_no_persist($messages_to_generate) { | 
                                                        |
| 307 | 307 | $this->_init_queue_and_generator();  | 
                                                        
| 308 | - $this->_queue_for_generation_loop( $messages_to_generate );  | 
                                                        |
| 308 | + $this->_queue_for_generation_loop($messages_to_generate);  | 
                                                        |
| 309 | 309 | }  | 
                                                        
| 310 | 310 | |
| 311 | 311 | |
@@ -317,15 +317,15 @@ discard block  | 
                                                    ||
| 317 | 317 | *  | 
                                                        
| 318 | 318 | * @param EE_Message_To_Generate[] $messages_to_generate  | 
                                                        
| 319 | 319 | */  | 
                                                        
| 320 | -	protected function _queue_for_generation_loop( $messages_to_generate ) { | 
                                                        |
| 320 | +	protected function _queue_for_generation_loop($messages_to_generate) { | 
                                                        |
| 321 | 321 | //make sure is in an array.  | 
                                                        
| 322 | -		if ( ! is_array( $messages_to_generate ) ) { | 
                                                        |
| 323 | - $messages_to_generate = array( $messages_to_generate );  | 
                                                        |
| 322 | +		if ( ! is_array($messages_to_generate)) { | 
                                                        |
| 323 | + $messages_to_generate = array($messages_to_generate);  | 
                                                        |
| 324 | 324 | }  | 
                                                        
| 325 | 325 | |
| 326 | -		foreach ( $messages_to_generate as $message_to_generate ) { | 
                                                        |
| 327 | -			if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) { | 
                                                        |
| 328 | - $this->queue_for_generation( $message_to_generate );  | 
                                                        |
| 326 | +		foreach ($messages_to_generate as $message_to_generate) { | 
                                                        |
| 327 | +			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { | 
                                                        |
| 328 | + $this->queue_for_generation($message_to_generate);  | 
                                                        |
| 329 | 329 | }  | 
                                                        
| 330 | 330 | }  | 
                                                        
| 331 | 331 | }  | 
                                                        
@@ -340,10 +340,10 @@ discard block  | 
                                                    ||
| 340 | 340 | * @param EE_Message_To_Generate[]  | 
                                                        
| 341 | 341 | * @return EE_Messages_Queue  | 
                                                        
| 342 | 342 | */  | 
                                                        
| 343 | -	public function generate_and_queue_for_sending( $messages_to_generate ) { | 
                                                        |
| 343 | +	public function generate_and_queue_for_sending($messages_to_generate) { | 
                                                        |
| 344 | 344 | $this->_init_queue_and_generator();  | 
                                                        
| 345 | - $this->_queue_for_generation_loop( $messages_to_generate );  | 
                                                        |
| 346 | - return $this->_generator->generate( true );  | 
                                                        |
| 345 | + $this->_queue_for_generation_loop($messages_to_generate);  | 
                                                        |
| 346 | + return $this->_generator->generate(true);  | 
                                                        |
| 347 | 347 | }  | 
                                                        
| 348 | 348 | |
| 349 | 349 | |
@@ -357,10 +357,10 @@ discard block  | 
                                                    ||
| 357 | 357 | * @param bool $test_send Whether this is a test send or not.  | 
                                                        
| 358 | 358 | * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue.  | 
                                                        
| 359 | 359 | */  | 
                                                        
| 360 | -	public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) { | 
                                                        |
| 361 | -		if ( ! $message_to_generate->valid() ) { | 
                                                        |
| 360 | +	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) { | 
                                                        |
| 361 | +		if ( ! $message_to_generate->valid()) { | 
                                                        |
| 362 | 362 | EE_Error::add_error(  | 
                                                        
| 363 | - __( 'Unable to generate preview because of invalid data', 'event_espresso' ),  | 
                                                        |
| 363 | +				__('Unable to generate preview because of invalid data', 'event_espresso'), | 
                                                        |
| 364 | 364 | __FILE__,  | 
                                                        
| 365 | 365 | __FUNCTION__,  | 
                                                        
| 366 | 366 | __LINE__  | 
                                                        
@@ -368,14 +368,14 @@ discard block  | 
                                                    ||
| 368 | 368 | return false;  | 
                                                        
| 369 | 369 | }  | 
                                                        
| 370 | 370 | //just make sure preview is set on the $message_to_generate (in case client forgot)  | 
                                                        
| 371 | - $message_to_generate->set_preview( true );  | 
                                                        |
| 371 | + $message_to_generate->set_preview(true);  | 
                                                        |
| 372 | 372 | $this->_init_queue_and_generator();  | 
                                                        
| 373 | - $this->queue_for_generation( $message_to_generate, $test_send );  | 
                                                        |
| 374 | - $generated_queue = $this->_generator->generate( false );  | 
                                                        |
| 375 | -		if ( $generated_queue->execute( false ) ) { | 
                                                        |
| 373 | + $this->queue_for_generation($message_to_generate, $test_send);  | 
                                                        |
| 374 | + $generated_queue = $this->_generator->generate(false);  | 
                                                        |
| 375 | +		if ($generated_queue->execute(false)) { | 
                                                        |
| 376 | 376 | //the first queue item should be the preview  | 
                                                        
| 377 | 377 | $generated_queue->get_message_repository()->rewind();  | 
                                                        
| 378 | -			if ( ! $generated_queue->get_message_repository()->valid() ) { | 
                                                        |
| 378 | +			if ( ! $generated_queue->get_message_repository()->valid()) { | 
                                                        |
| 379 | 379 | return $generated_queue;  | 
                                                        
| 380 | 380 | }  | 
                                                        
| 381 | 381 | return $generated_queue;  | 
                                                        
@@ -392,15 +392,15 @@ discard block  | 
                                                    ||
| 392 | 392 | * @param EE_Message_To_Generate $message_to_generate  | 
                                                        
| 393 | 393 | * @return bool true or false for success.  | 
                                                        
| 394 | 394 | */  | 
                                                        
| 395 | -	public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) { | 
                                                        |
| 396 | -		if ( ! $message_to_generate->valid() ) { | 
                                                        |
| 395 | +	public function queue_for_sending(EE_Message_To_Generate $message_to_generate) { | 
                                                        |
| 396 | +		if ( ! $message_to_generate->valid()) { | 
                                                        |
| 397 | 397 | return false;  | 
                                                        
| 398 | 398 | }  | 
                                                        
| 399 | 399 | $this->_init_queue_and_generator();  | 
                                                        
| 400 | 400 | $message = $message_to_generate->get_EE_Message();  | 
                                                        
| 401 | - $this->_queue->add( $message );  | 
                                                        |
| 402 | -		if ( $message->send_now() ) { | 
                                                        |
| 403 | - $this->_queue->execute( false );  | 
                                                        |
| 401 | + $this->_queue->add($message);  | 
                                                        |
| 402 | +		if ($message->send_now()) { | 
                                                        |
| 403 | + $this->_queue->execute(false);  | 
                                                        |
| 404 | 404 |  		} else { | 
                                                        
| 405 | 405 | $this->_queue->save();  | 
                                                        
| 406 | 406 | }  | 
                                                        
@@ -413,12 +413,12 @@ discard block  | 
                                                    ||
| 413 | 413 | * @param EE_Message_To_Generate $message_to_generate  | 
                                                        
| 414 | 414 | * @return EE_Messages_Queue | null  | 
                                                        
| 415 | 415 | */  | 
                                                        
| 416 | -	public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) { | 
                                                        |
| 417 | -		if ( ! $message_to_generate->valid() ) { | 
                                                        |
| 416 | +	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) { | 
                                                        |
| 417 | +		if ( ! $message_to_generate->valid()) { | 
                                                        |
| 418 | 418 | return null;  | 
                                                        
| 419 | 419 | }  | 
                                                        
| 420 | 420 | // is there supposed to be a sending messenger for this message?  | 
                                                        
| 421 | -		if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) { | 
                                                        |
| 421 | +		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { | 
                                                        |
| 422 | 422 | // make sure it's valid, but if it's not,  | 
                                                        
| 423 | 423 | // then set the value of $sending_messenger to an EE_Error object  | 
                                                        
| 424 | 424 | // so that downstream code can easily see that things went wrong.  | 
                                                        
@@ -434,14 +434,14 @@ discard block  | 
                                                    ||
| 434 | 434 | $sending_messenger = null;  | 
                                                        
| 435 | 435 | }  | 
                                                        
| 436 | 436 | |
| 437 | -		if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) { | 
                                                        |
| 437 | +		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { | 
                                                        |
| 438 | 438 | $this->_init_queue_and_generator();  | 
                                                        
| 439 | - $this->_queue->add( $message_to_generate->get_EE_Message() );  | 
                                                        |
| 440 | - $this->_queue->execute( false, $sending_messenger );  | 
                                                        |
| 439 | + $this->_queue->add($message_to_generate->get_EE_Message());  | 
                                                        |
| 440 | + $this->_queue->execute(false, $sending_messenger);  | 
                                                        |
| 441 | 441 | return $this->_queue;  | 
                                                        
| 442 | -		} elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) { | 
                                                        |
| 443 | - $generated_queue = $this->generate_and_return( array( $message_to_generate ) );  | 
                                                        |
| 444 | - $generated_queue->execute( false, $sending_messenger );  | 
                                                        |
| 442 | +		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { | 
                                                        |
| 443 | + $generated_queue = $this->generate_and_return(array($message_to_generate));  | 
                                                        |
| 444 | + $generated_queue->execute(false, $sending_messenger);  | 
                                                        |
| 445 | 445 | return $generated_queue;  | 
                                                        
| 446 | 446 | }  | 
                                                        
| 447 | 447 | return null;  | 
                                                        
@@ -458,13 +458,13 @@ discard block  | 
                                                    ||
| 458 | 458 | * @param mixed $data The data being used for generation.  | 
                                                        
| 459 | 459 | * @param bool $persist Whether to persist the queued messages to the db or not.  | 
                                                        
| 460 | 460 | */  | 
                                                        
| 461 | -	public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) { | 
                                                        |
| 462 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data );  | 
                                                        |
| 463 | -		if ( $persist ) { | 
                                                        |
| 464 | - $this->batch_queue_for_generation_and_persist( $messages_to_generate );  | 
                                                        |
| 461 | +	public function generate_for_all_active_messengers($message_type, $data, $persist = true) { | 
                                                        |
| 462 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);  | 
                                                        |
| 463 | +		if ($persist) { | 
                                                        |
| 464 | + $this->batch_queue_for_generation_and_persist($messages_to_generate);  | 
                                                        |
| 465 | 465 | $this->_queue->initiate_request_by_priority();  | 
                                                        
| 466 | 466 |  		} else { | 
                                                        
| 467 | - $this->batch_queue_for_generation_no_persist( $messages_to_generate );  | 
                                                        |
| 467 | + $this->batch_queue_for_generation_no_persist($messages_to_generate);  | 
                                                        |
| 468 | 468 | }  | 
                                                        
| 469 | 469 | }  | 
                                                        
| 470 | 470 | |
@@ -479,11 +479,11 @@ discard block  | 
                                                    ||
| 479 | 479 | *  | 
                                                        
| 480 | 480 | * @return EE_Message_To_Generate[]  | 
                                                        
| 481 | 481 | */  | 
                                                        
| 482 | -	public function setup_mtgs_for_all_active_messengers( $message_type, $data ) { | 
                                                        |
| 482 | +	public function setup_mtgs_for_all_active_messengers($message_type, $data) { | 
                                                        |
| 483 | 483 | $messages_to_generate = array();  | 
                                                        
| 484 | -		foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object  ) { | 
                                                        |
| 485 | - $message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data );  | 
                                                        |
| 486 | -			if ( $message_to_generate->valid() ) { | 
                                                        |
| 484 | +		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { | 
                                                        |
| 485 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);  | 
                                                        |
| 486 | +			if ($message_to_generate->valid()) { | 
                                                        |
| 487 | 487 | $messages_to_generate[] = $message_to_generate;  | 
                                                        
| 488 | 488 | }  | 
                                                        
| 489 | 489 | }  | 
                                                        
@@ -498,29 +498,29 @@ discard block  | 
                                                    ||
| 498 | 498 | * and send.  | 
                                                        
| 499 | 499 | * @param array $message_ids  | 
                                                        
| 500 | 500 | */  | 
                                                        
| 501 | -	public function setup_messages_from_ids_and_send( $message_ids ) { | 
                                                        |
| 501 | +	public function setup_messages_from_ids_and_send($message_ids) { | 
                                                        |
| 502 | 502 | $this->_init_queue_and_generator();  | 
                                                        
| 503 | - $messages = EEM_Message::instance()->get_all( array(  | 
                                                        |
| 503 | + $messages = EEM_Message::instance()->get_all(array(  | 
                                                        |
| 504 | 504 | array(  | 
                                                        
| 505 | - 'MSG_ID' => array( 'IN', $message_ids ),  | 
                                                        |
| 505 | +				'MSG_ID' => array('IN', $message_ids), | 
                                                        |
| 506 | 506 | 'STS_ID' => array(  | 
                                                        
| 507 | 507 | 'IN',  | 
                                                        
| 508 | 508 | array_merge(  | 
                                                        
| 509 | 509 | EEM_Message::instance()->stati_indicating_sent(),  | 
                                                        
| 510 | - array( EEM_Message::status_retry )  | 
                                                        |
| 510 | + array(EEM_Message::status_retry)  | 
                                                        |
| 511 | 511 | ),  | 
                                                        
| 512 | 512 | ),  | 
                                                        
| 513 | 513 | ),  | 
                                                        
| 514 | 514 | ));  | 
                                                        
| 515 | 515 | //set the Messages to resend.  | 
                                                        
| 516 | -		foreach ( $messages as $message ) { | 
                                                        |
| 517 | -			if ( $message instanceof EE_Message ) { | 
                                                        |
| 518 | - $message->set_STS_ID( EEM_Message::status_resend );  | 
                                                        |
| 519 | - $this->_queue->add( $message );  | 
                                                        |
| 516 | +		foreach ($messages as $message) { | 
                                                        |
| 517 | +			if ($message instanceof EE_Message) { | 
                                                        |
| 518 | + $message->set_STS_ID(EEM_Message::status_resend);  | 
                                                        |
| 519 | + $this->_queue->add($message);  | 
                                                        |
| 520 | 520 | }  | 
                                                        
| 521 | 521 | }  | 
                                                        
| 522 | 522 | |
| 523 | - $this->_queue->initiate_request_by_priority( 'send' );  | 
                                                        |
| 523 | +		$this->_queue->initiate_request_by_priority('send'); | 
                                                        |
| 524 | 524 | }  | 
                                                        
| 525 | 525 | |
| 526 | 526 | |
@@ -534,23 +534,23 @@ discard block  | 
                                                    ||
| 534 | 534 | *  | 
                                                        
| 535 | 535 | * @return EE_Message_To_Generate[]  | 
                                                        
| 536 | 536 | */  | 
                                                        
| 537 | -	public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) { | 
                                                        |
| 538 | - EE_Registry::instance()->load_core( 'Request_Handler' );  | 
                                                        |
| 539 | - EE_Registry::instance()->load_helper( 'MSG_Template' );  | 
                                                        |
| 537 | +	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') { | 
                                                        |
| 538 | +		EE_Registry::instance()->load_core('Request_Handler'); | 
                                                        |
| 539 | +		EE_Registry::instance()->load_helper('MSG_Template'); | 
                                                        |
| 540 | 540 | $regs_to_send = array();  | 
                                                        
| 541 | - $regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key );  | 
                                                        |
| 542 | -		if ( empty( $regIDs ) ) { | 
                                                        |
| 543 | -			EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); | 
                                                        |
| 541 | + $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);  | 
                                                        |
| 542 | +		if (empty($regIDs)) { | 
                                                        |
| 543 | +			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); | 
                                                        |
| 544 | 544 | return false;  | 
                                                        
| 545 | 545 | }  | 
                                                        
| 546 | 546 | |
| 547 | 547 | //make sure is an array  | 
                                                        
| 548 | - $regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs );  | 
                                                        |
| 548 | + $regIDs = is_array($regIDs) ? $regIDs : array($regIDs);  | 
                                                        |
| 549 | 549 | |
| 550 | -		foreach( $regIDs as $regID ) { | 
                                                        |
| 551 | - $reg = EEM_Registration::instance()->get_one_by_ID( $regID );  | 
                                                        |
| 552 | -			if ( ! $reg instanceof EE_Registration ) { | 
                                                        |
| 553 | -				EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) ); | 
                                                        |
| 550 | +		foreach ($regIDs as $regID) { | 
                                                        |
| 551 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID);  | 
                                                        |
| 552 | +			if ( ! $reg instanceof EE_Registration) { | 
                                                        |
| 553 | +				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); | 
                                                        |
| 554 | 554 | return false;  | 
                                                        
| 555 | 555 | }  | 
                                                        
| 556 | 556 | $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;  | 
                                                        
@@ -558,13 +558,13 @@ discard block  | 
                                                    ||
| 558 | 558 | |
| 559 | 559 | $messages_to_generate = array();  | 
                                                        
| 560 | 560 | |
| 561 | -		foreach ( $regs_to_send as $status_group ) { | 
                                                        |
| 562 | -			foreach ( $status_group as $status_id => $registrations ) { | 
                                                        |
| 561 | +		foreach ($regs_to_send as $status_group) { | 
                                                        |
| 562 | +			foreach ($status_group as $status_id => $registrations) { | 
                                                        |
| 563 | 563 | $messages_to_generate = array_merge(  | 
                                                        
| 564 | 564 | $messages_to_generate,  | 
                                                        
| 565 | 565 | $this->setup_mtgs_for_all_active_messengers(  | 
                                                        
| 566 | - EEH_MSG_Template::convert_reg_status_to_message_type( $status_id ),  | 
                                                        |
| 567 | - array( $registrations, $status_id )  | 
                                                        |
| 566 | + EEH_MSG_Template::convert_reg_status_to_message_type($status_id),  | 
                                                        |
| 567 | + array($registrations, $status_id)  | 
                                                        |
| 568 | 568 | )  | 
                                                        
| 569 | 569 | );  | 
                                                        
| 570 | 570 | }  | 
                                                        
@@ -1,5 +1,5 @@ discard block  | 
                                                    ||
| 1 | 1 |  <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
                                                        
| 2 | -    exit('NO direct script access allowed'); | 
                                                        |
| 2 | +	exit('NO direct script access allowed'); | 
                                                        |
| 3 | 3 | }  | 
                                                        
| 4 | 4 | |
| 5 | 5 | /**  | 
                                                        
@@ -17,2222 +17,2222 @@ discard block  | 
                                                    ||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | 19 | |
| 20 | - /**  | 
                                                        |
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 22 | - */  | 
                                                        |
| 23 | - protected $_message_resource_manager;  | 
                                                        |
| 24 | -  | 
                                                        |
| 25 | - /**  | 
                                                        |
| 26 | - * @type string $_active_message_type_name  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - protected $_active_message_type_name = '';  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - /**  | 
                                                        |
| 31 | - * @type EE_messenger $_active_messenger  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - protected $_active_messenger;  | 
                                                        |
| 34 | - protected $_activate_state;  | 
                                                        |
| 35 | - protected $_activate_meta_box_type;  | 
                                                        |
| 36 | - protected $_current_message_meta_box;  | 
                                                        |
| 37 | - protected $_current_message_meta_box_object;  | 
                                                        |
| 38 | - protected $_context_switcher;  | 
                                                        |
| 39 | - protected $_shortcodes = array();  | 
                                                        |
| 40 | - protected $_active_messengers = array();  | 
                                                        |
| 41 | - protected $_active_message_types = array();  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | - /**  | 
                                                        |
| 44 | - * @var EE_Message_Template_Group $_message_template_group  | 
                                                        |
| 45 | - */  | 
                                                        |
| 46 | - protected $_message_template_group;  | 
                                                        |
| 47 | - protected $_m_mt_settings = array();  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.  | 
                                                        |
| 52 | - * IF there is no group then it gets automatically set to the Default template pack.  | 
                                                        |
| 53 | - *  | 
                                                        |
| 54 | - * @since 4.5.0  | 
                                                        |
| 55 | - *  | 
                                                        |
| 56 | - * @var EE_Messages_Template_Pack  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - protected $_template_pack;  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | -  | 
                                                        |
| 61 | - /**  | 
                                                        |
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the  | 
                                                        |
| 63 | - * group is. If there is no group then it automatically gets set to default.  | 
                                                        |
| 64 | - *  | 
                                                        |
| 65 | - * @since 4.5.0  | 
                                                        |
| 66 | - *  | 
                                                        |
| 67 | - * @var string  | 
                                                        |
| 68 | - */  | 
                                                        |
| 69 | - protected $_variation;  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - /**  | 
                                                        |
| 73 | - * @param bool $routing  | 
                                                        |
| 74 | - */  | 
                                                        |
| 75 | - public function __construct($routing = true)  | 
                                                        |
| 76 | -    { | 
                                                        |
| 77 | - //make sure messages autoloader is running  | 
                                                        |
| 78 | - EED_Messages::set_autoloaders();  | 
                                                        |
| 79 | - parent::__construct($routing);  | 
                                                        |
| 80 | - }  | 
                                                        |
| 81 | -  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - protected function _init_page_props()  | 
                                                        |
| 84 | -    { | 
                                                        |
| 85 | - $this->page_slug = EE_MSG_PG_SLUG;  | 
                                                        |
| 86 | -        $this->page_label       = __('Messages Settings', 'event_espresso'); | 
                                                        |
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL;  | 
                                                        |
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN;  | 
                                                        |
| 89 | -  | 
                                                        |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();  | 
                                                        |
| 91 | -  | 
                                                        |
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;  | 
                                                        |
| 93 | - $this->_load_message_resource_manager();  | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | -  | 
                                                        |
| 97 | - /**  | 
                                                        |
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods)  | 
                                                        |
| 99 | - *  | 
                                                        |
| 100 | - *  | 
                                                        |
| 101 | - * @throws EE_Error  | 
                                                        |
| 102 | - */  | 
                                                        |
| 103 | - protected function _load_message_resource_manager()  | 
                                                        |
| 104 | -    { | 
                                                        |
| 105 | -        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 106 | - }  | 
                                                        |
| 107 | -  | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | - /**  | 
                                                        |
| 110 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 111 | - * @return array  | 
                                                        |
| 112 | - */  | 
                                                        |
| 113 | - public function get_messengers_for_list_table()  | 
                                                        |
| 114 | -    { | 
                                                        |
| 115 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 116 | - __METHOD__,  | 
                                                        |
| 117 | -            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 20 | + /**  | 
                                                        |
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 22 | + */  | 
                                                        |
| 23 | + protected $_message_resource_manager;  | 
                                                        |
| 24 | +  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @type string $_active_message_type_name  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + protected $_active_message_type_name = '';  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * @type EE_messenger $_active_messenger  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + protected $_active_messenger;  | 
                                                        |
| 34 | + protected $_activate_state;  | 
                                                        |
| 35 | + protected $_activate_meta_box_type;  | 
                                                        |
| 36 | + protected $_current_message_meta_box;  | 
                                                        |
| 37 | + protected $_current_message_meta_box_object;  | 
                                                        |
| 38 | + protected $_context_switcher;  | 
                                                        |
| 39 | + protected $_shortcodes = array();  | 
                                                        |
| 40 | + protected $_active_messengers = array();  | 
                                                        |
| 41 | + protected $_active_message_types = array();  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | + /**  | 
                                                        |
| 44 | + * @var EE_Message_Template_Group $_message_template_group  | 
                                                        |
| 45 | + */  | 
                                                        |
| 46 | + protected $_message_template_group;  | 
                                                        |
| 47 | + protected $_m_mt_settings = array();  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.  | 
                                                        |
| 52 | + * IF there is no group then it gets automatically set to the Default template pack.  | 
                                                        |
| 53 | + *  | 
                                                        |
| 54 | + * @since 4.5.0  | 
                                                        |
| 55 | + *  | 
                                                        |
| 56 | + * @var EE_Messages_Template_Pack  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + protected $_template_pack;  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | +  | 
                                                        |
| 61 | + /**  | 
                                                        |
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the  | 
                                                        |
| 63 | + * group is. If there is no group then it automatically gets set to default.  | 
                                                        |
| 64 | + *  | 
                                                        |
| 65 | + * @since 4.5.0  | 
                                                        |
| 66 | + *  | 
                                                        |
| 67 | + * @var string  | 
                                                        |
| 68 | + */  | 
                                                        |
| 69 | + protected $_variation;  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + /**  | 
                                                        |
| 73 | + * @param bool $routing  | 
                                                        |
| 74 | + */  | 
                                                        |
| 75 | + public function __construct($routing = true)  | 
                                                        |
| 76 | +	{ | 
                                                        |
| 77 | + //make sure messages autoloader is running  | 
                                                        |
| 78 | + EED_Messages::set_autoloaders();  | 
                                                        |
| 79 | + parent::__construct($routing);  | 
                                                        |
| 80 | + }  | 
                                                        |
| 81 | +  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + protected function _init_page_props()  | 
                                                        |
| 84 | +	{ | 
                                                        |
| 85 | + $this->page_slug = EE_MSG_PG_SLUG;  | 
                                                        |
| 86 | +		$this->page_label       = __('Messages Settings', 'event_espresso'); | 
                                                        |
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL;  | 
                                                        |
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN;  | 
                                                        |
| 89 | +  | 
                                                        |
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();  | 
                                                        |
| 91 | +  | 
                                                        |
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;  | 
                                                        |
| 93 | + $this->_load_message_resource_manager();  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | +  | 
                                                        |
| 97 | + /**  | 
                                                        |
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods)  | 
                                                        |
| 99 | + *  | 
                                                        |
| 100 | + *  | 
                                                        |
| 101 | + * @throws EE_Error  | 
                                                        |
| 102 | + */  | 
                                                        |
| 103 | + protected function _load_message_resource_manager()  | 
                                                        |
| 104 | +	{ | 
                                                        |
| 105 | +		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 106 | + }  | 
                                                        |
| 107 | +  | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | + /**  | 
                                                        |
| 110 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 111 | + * @return array  | 
                                                        |
| 112 | + */  | 
                                                        |
| 113 | + public function get_messengers_for_list_table()  | 
                                                        |
| 114 | +	{ | 
                                                        |
| 115 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 116 | + __METHOD__,  | 
                                                        |
| 117 | +			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via  | 
                                                        
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),  | 
                                                        
| 120 | - '4.9.9.rc.014'  | 
                                                        |
| 121 | - );  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - $m_values = array();  | 
                                                        |
| 124 | -        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); | 
                                                        |
| 125 | - //setup messengers for selects  | 
                                                        |
| 126 | - $i = 1;  | 
                                                        |
| 127 | -        foreach ($active_messengers as $active_messenger) { | 
                                                        |
| 128 | -            if ($active_messenger instanceof EE_Message) { | 
                                                        |
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger();  | 
                                                        |
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 131 | - $i++;  | 
                                                        |
| 132 | - }  | 
                                                        |
| 133 | - }  | 
                                                        |
| 134 | -  | 
                                                        |
| 135 | - return $m_values;  | 
                                                        |
| 136 | - }  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | - /**  | 
                                                        |
| 140 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 141 | - * @return array  | 
                                                        |
| 142 | - */  | 
                                                        |
| 143 | - public function get_message_types_for_list_table()  | 
                                                        |
| 144 | -    { | 
                                                        |
| 145 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 146 | - __METHOD__,  | 
                                                        |
| 147 | -            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 120 | + '4.9.9.rc.014'  | 
                                                        |
| 121 | + );  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + $m_values = array();  | 
                                                        |
| 124 | +		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); | 
                                                        |
| 125 | + //setup messengers for selects  | 
                                                        |
| 126 | + $i = 1;  | 
                                                        |
| 127 | +		foreach ($active_messengers as $active_messenger) { | 
                                                        |
| 128 | +			if ($active_messenger instanceof EE_Message) { | 
                                                        |
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger();  | 
                                                        |
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 131 | + $i++;  | 
                                                        |
| 132 | + }  | 
                                                        |
| 133 | + }  | 
                                                        |
| 134 | +  | 
                                                        |
| 135 | + return $m_values;  | 
                                                        |
| 136 | + }  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | + /**  | 
                                                        |
| 140 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 141 | + * @return array  | 
                                                        |
| 142 | + */  | 
                                                        |
| 143 | + public function get_message_types_for_list_table()  | 
                                                        |
| 144 | +	{ | 
                                                        |
| 145 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 146 | + __METHOD__,  | 
                                                        |
| 147 | +			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via  | 
                                                        
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),  | 
                                                        
| 150 | - '4.9.9.rc.014'  | 
                                                        |
| 151 | - );  | 
                                                        |
| 152 | -  | 
                                                        |
| 153 | - $mt_values = array();  | 
                                                        |
| 154 | -        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); | 
                                                        |
| 155 | - $i = 1;  | 
                                                        |
| 156 | -        foreach ($active_messages as $active_message) { | 
                                                        |
| 157 | -            if ($active_message instanceof EE_Message) { | 
                                                        |
| 158 | - $mt_values[$i]['id'] = $active_message->message_type();  | 
                                                        |
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 160 | - $i++;  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | - }  | 
                                                        |
| 163 | -  | 
                                                        |
| 164 | - return $mt_values;  | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | - /**  | 
                                                        |
| 169 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 170 | - * @return array  | 
                                                        |
| 171 | - */  | 
                                                        |
| 172 | - public function get_contexts_for_message_types_for_list_table()  | 
                                                        |
| 173 | -    { | 
                                                        |
| 174 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 175 | - __METHOD__,  | 
                                                        |
| 176 | -            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 150 | + '4.9.9.rc.014'  | 
                                                        |
| 151 | + );  | 
                                                        |
| 152 | +  | 
                                                        |
| 153 | + $mt_values = array();  | 
                                                        |
| 154 | +		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); | 
                                                        |
| 155 | + $i = 1;  | 
                                                        |
| 156 | +		foreach ($active_messages as $active_message) { | 
                                                        |
| 157 | +			if ($active_message instanceof EE_Message) { | 
                                                        |
| 158 | + $mt_values[$i]['id'] = $active_message->message_type();  | 
                                                        |
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 160 | + $i++;  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | + }  | 
                                                        |
| 163 | +  | 
                                                        |
| 164 | + return $mt_values;  | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | + /**  | 
                                                        |
| 169 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 170 | + * @return array  | 
                                                        |
| 171 | + */  | 
                                                        |
| 172 | + public function get_contexts_for_message_types_for_list_table()  | 
                                                        |
| 173 | +	{ | 
                                                        |
| 174 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 175 | + __METHOD__,  | 
                                                        |
| 176 | +			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of | 
                                                        |
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via  | 
                                                        
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),  | 
                                                        
| 179 | - '4.9.9.rc.014'  | 
                                                        |
| 180 | - );  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - $contexts = array();  | 
                                                        |
| 183 | -        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); | 
                                                        |
| 184 | -        foreach ($active_message_contexts as $active_message) { | 
                                                        |
| 185 | -            if ($active_message instanceof EE_Message) { | 
                                                        |
| 186 | - $message_type = $active_message->message_type_object();  | 
                                                        |
| 187 | -                if ($message_type instanceof EE_message_type) { | 
                                                        |
| 188 | - $message_type_contexts = $message_type->get_contexts();  | 
                                                        |
| 189 | -                    foreach ($message_type_contexts as $context => $context_details) { | 
                                                        |
| 190 | - $contexts[$context] = $context_details['label'];  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | - }  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | - }  | 
                                                        |
| 195 | -  | 
                                                        |
| 196 | - return $contexts;  | 
                                                        |
| 197 | - }  | 
                                                        |
| 198 | -  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | - /**  | 
                                                        |
| 201 | - * Generate select input with provided messenger options array.  | 
                                                        |
| 202 | - *  | 
                                                        |
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger  | 
                                                        |
| 204 | - * labels.  | 
                                                        |
| 205 | - *  | 
                                                        |
| 206 | - * @return string  | 
                                                        |
| 207 | - */  | 
                                                        |
| 208 | - public function get_messengers_select_input($messenger_options)  | 
                                                        |
| 209 | -    { | 
                                                        |
| 210 | - //if empty or just one value then just return an empty string  | 
                                                        |
| 211 | - if (empty($messenger_options)  | 
                                                        |
| 212 | - || ! is_array($messenger_options)  | 
                                                        |
| 213 | - || count($messenger_options) === 1  | 
                                                        |
| 214 | -        ) { | 
                                                        |
| 215 | - return '';  | 
                                                        |
| 216 | - }  | 
                                                        |
| 217 | - //merge in default  | 
                                                        |
| 218 | - $messenger_options = array_merge(  | 
                                                        |
| 219 | -            array('none_selected' => __('Show All Messengers', 'event_espresso')), | 
                                                        |
| 220 | - $messenger_options  | 
                                                        |
| 221 | - );  | 
                                                        |
| 222 | - $input = new EE_Select_Input(  | 
                                                        |
| 223 | - $messenger_options,  | 
                                                        |
| 224 | - array(  | 
                                                        |
| 225 | - 'html_name' => 'ee_messenger_filter_by',  | 
                                                        |
| 226 | - 'html_id' => 'ee_messenger_filter_by',  | 
                                                        |
| 227 | - 'html_class' => 'wide',  | 
                                                        |
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by'])  | 
                                                        |
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by'])  | 
                                                        |
| 230 | - : 'none_selected'  | 
                                                        |
| 231 | - )  | 
                                                        |
| 232 | - );  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | - return $input->get_html_for_input();  | 
                                                        |
| 235 | - }  | 
                                                        |
| 236 | -  | 
                                                        |
| 237 | -  | 
                                                        |
| 238 | - /**  | 
                                                        |
| 239 | - * Generate select input with provided message type options array.  | 
                                                        |
| 240 | - *  | 
                                                        |
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the  | 
                                                        |
| 242 | - * message type labels  | 
                                                        |
| 243 | - *  | 
                                                        |
| 244 | - * @return string  | 
                                                        |
| 245 | - */  | 
                                                        |
| 246 | - public function get_message_types_select_input($message_type_options)  | 
                                                        |
| 247 | -    { | 
                                                        |
| 248 | - //if empty or count of options is 1 then just return an empty string  | 
                                                        |
| 249 | - if (empty($message_type_options)  | 
                                                        |
| 250 | - || ! is_array($message_type_options)  | 
                                                        |
| 251 | - || count($message_type_options) === 1  | 
                                                        |
| 252 | -        ) { | 
                                                        |
| 253 | - return '';  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | - //merge in default  | 
                                                        |
| 256 | - $message_type_options = array_merge(  | 
                                                        |
| 257 | -            array('none_selected' => __('Show All Message Types', 'event_espresso')), | 
                                                        |
| 258 | - $message_type_options  | 
                                                        |
| 259 | - );  | 
                                                        |
| 260 | - $input = new EE_Select_Input(  | 
                                                        |
| 261 | - $message_type_options,  | 
                                                        |
| 262 | - array(  | 
                                                        |
| 263 | - 'html_name' => 'ee_message_type_filter_by',  | 
                                                        |
| 264 | - 'html_id' => 'ee_message_type_filter_by',  | 
                                                        |
| 265 | - 'html_class' => 'wide',  | 
                                                        |
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by'])  | 
                                                        |
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by'])  | 
                                                        |
| 268 | - : 'none_selected',  | 
                                                        |
| 269 | - )  | 
                                                        |
| 270 | - );  | 
                                                        |
| 271 | -  | 
                                                        |
| 272 | - return $input->get_html_for_input();  | 
                                                        |
| 273 | - }  | 
                                                        |
| 274 | -  | 
                                                        |
| 275 | -  | 
                                                        |
| 276 | - /**  | 
                                                        |
| 277 | - * Generate select input with provide message type contexts array.  | 
                                                        |
| 278 | - *  | 
                                                        |
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the  | 
                                                        |
| 280 | - * context label.  | 
                                                        |
| 281 | - *  | 
                                                        |
| 282 | - * @return string  | 
                                                        |
| 283 | - */  | 
                                                        |
| 284 | - public function get_contexts_for_message_types_select_input($context_options)  | 
                                                        |
| 285 | -    { | 
                                                        |
| 286 | - //if empty or count of options is one then just return empty string  | 
                                                        |
| 287 | - if (empty($context_options)  | 
                                                        |
| 288 | - || ! is_array($context_options)  | 
                                                        |
| 289 | - || count($context_options) === 1  | 
                                                        |
| 290 | -        ) { | 
                                                        |
| 291 | - return '';  | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | - //merge in default  | 
                                                        |
| 294 | - $context_options = array_merge(  | 
                                                        |
| 295 | -            array('none_selected' => __('Show all Contexts', 'event_espresso')), | 
                                                        |
| 296 | - $context_options  | 
                                                        |
| 297 | - );  | 
                                                        |
| 298 | - $input = new EE_Select_Input(  | 
                                                        |
| 299 | - $context_options,  | 
                                                        |
| 300 | - array(  | 
                                                        |
| 301 | - 'html_name' => 'ee_context_filter_by',  | 
                                                        |
| 302 | - 'html_id' => 'ee_context_filter_by',  | 
                                                        |
| 303 | - 'html_class' => 'wide',  | 
                                                        |
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by'])  | 
                                                        |
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by'])  | 
                                                        |
| 306 | - : 'none_selected',  | 
                                                        |
| 307 | - )  | 
                                                        |
| 308 | - );  | 
                                                        |
| 309 | -  | 
                                                        |
| 310 | - return $input->get_html_for_input();  | 
                                                        |
| 311 | - }  | 
                                                        |
| 312 | -  | 
                                                        |
| 313 | -  | 
                                                        |
| 314 | - protected function _ajax_hooks()  | 
                                                        |
| 315 | -    { | 
                                                        |
| 316 | -        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); | 
                                                        |
| 317 | -        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); | 
                                                        |
| 318 | -        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); | 
                                                        |
| 319 | -        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); | 
                                                        |
| 320 | -        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); | 
                                                        |
| 321 | - }  | 
                                                        |
| 322 | -  | 
                                                        |
| 323 | -  | 
                                                        |
| 324 | - protected function _define_page_props()  | 
                                                        |
| 325 | -    { | 
                                                        |
| 326 | - $this->_admin_page_title = $this->page_label;  | 
                                                        |
| 327 | - $this->_labels = array(  | 
                                                        |
| 328 | - 'buttons' => array(  | 
                                                        |
| 329 | -                'add'    => __('Add New Message Template', 'event_espresso'), | 
                                                        |
| 330 | -                'edit'   => __('Edit Message Template', 'event_espresso'), | 
                                                        |
| 331 | -                'delete' => __('Delete Message Template', 'event_espresso') | 
                                                        |
| 332 | - ),  | 
                                                        |
| 333 | -            'publishbox' => __('Update Actions', 'event_espresso') | 
                                                        |
| 334 | - );  | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | -  | 
                                                        |
| 338 | - /**  | 
                                                        |
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods  | 
                                                        |
| 340 | - * @access protected  | 
                                                        |
| 341 | - * @return void  | 
                                                        |
| 342 | - */  | 
                                                        |
| 343 | - protected function _set_page_routes()  | 
                                                        |
| 344 | -    { | 
                                                        |
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])  | 
                                                        |
| 346 | - ? $this->_req_data['GRP_ID']  | 
                                                        |
| 347 | - : 0;  | 
                                                        |
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])  | 
                                                        |
| 349 | - ? $this->_req_data['id']  | 
                                                        |
| 350 | - : $grp_id;  | 
                                                        |
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])  | 
                                                        |
| 352 | - ? $this->_req_data['MSG_ID']  | 
                                                        |
| 353 | - : 0;  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | - $this->_page_routes = array(  | 
                                                        |
| 356 | - 'default' => array(  | 
                                                        |
| 357 | - 'func' => '_message_queue_list_table',  | 
                                                        |
| 358 | - 'capability' => 'ee_read_global_messages'  | 
                                                        |
| 359 | - ),  | 
                                                        |
| 360 | - 'global_mtps' => array(  | 
                                                        |
| 361 | - 'func' => '_ee_default_messages_overview_list_table',  | 
                                                        |
| 362 | - 'capability' => 'ee_read_global_messages'  | 
                                                        |
| 363 | - ),  | 
                                                        |
| 364 | - 'custom_mtps' => array(  | 
                                                        |
| 365 | - 'func' => '_custom_mtps_preview',  | 
                                                        |
| 366 | - 'capability' => 'ee_read_messages'  | 
                                                        |
| 367 | - ),  | 
                                                        |
| 368 | - 'add_new_message_template' => array(  | 
                                                        |
| 369 | - 'func' => '_add_message_template',  | 
                                                        |
| 370 | - 'capability' => 'ee_edit_messages',  | 
                                                        |
| 371 | - 'noheader' => true  | 
                                                        |
| 372 | - ),  | 
                                                        |
| 373 | - 'edit_message_template' => array(  | 
                                                        |
| 374 | - 'func' => '_edit_message_template',  | 
                                                        |
| 375 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 376 | - 'obj_id' => $grp_id  | 
                                                        |
| 377 | - ),  | 
                                                        |
| 378 | - 'preview_message' => array(  | 
                                                        |
| 379 | - 'func' => '_preview_message',  | 
                                                        |
| 380 | - 'capability' => 'ee_read_message',  | 
                                                        |
| 381 | - 'obj_id' => $grp_id,  | 
                                                        |
| 382 | - 'noheader' => true,  | 
                                                        |
| 383 | - 'headers_sent_route' => 'display_preview_message'  | 
                                                        |
| 384 | - ),  | 
                                                        |
| 385 | - 'display_preview_message' => array(  | 
                                                        |
| 386 | - 'func' => '_display_preview_message',  | 
                                                        |
| 387 | - 'capability' => 'ee_read_message',  | 
                                                        |
| 388 | - 'obj_id' => $grp_id  | 
                                                        |
| 389 | - ),  | 
                                                        |
| 390 | - 'insert_message_template' => array(  | 
                                                        |
| 391 | - 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 392 | - 'capability' => 'ee_edit_messages',  | 
                                                        |
| 393 | -                'args'       => array('new_template' => true), | 
                                                        |
| 394 | - 'noheader' => true  | 
                                                        |
| 395 | - ),  | 
                                                        |
| 396 | - 'update_message_template' => array(  | 
                                                        |
| 397 | - 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 398 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 399 | - 'obj_id' => $grp_id,  | 
                                                        |
| 400 | -                'args'       => array('new_template' => false), | 
                                                        |
| 401 | - 'noheader' => true  | 
                                                        |
| 402 | - ),  | 
                                                        |
| 403 | - 'trash_message_template' => array(  | 
                                                        |
| 404 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 405 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 406 | - 'obj_id' => $grp_id,  | 
                                                        |
| 407 | -                'args'       => array('trash' => true, 'all' => true), | 
                                                        |
| 408 | - 'noheader' => true  | 
                                                        |
| 409 | - ),  | 
                                                        |
| 410 | - 'trash_message_template_context' => array(  | 
                                                        |
| 411 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 412 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 413 | - 'obj_id' => $grp_id,  | 
                                                        |
| 414 | -                'args'       => array('trash' => true), | 
                                                        |
| 415 | - 'noheader' => true  | 
                                                        |
| 416 | - ),  | 
                                                        |
| 417 | - 'restore_message_template' => array(  | 
                                                        |
| 418 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 419 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 420 | - 'obj_id' => $grp_id,  | 
                                                        |
| 421 | -                'args'       => array('trash' => false, 'all' => true), | 
                                                        |
| 422 | - 'noheader' => true  | 
                                                        |
| 423 | - ),  | 
                                                        |
| 424 | - 'restore_message_template_context' => array(  | 
                                                        |
| 425 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 426 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 427 | - 'obj_id' => $grp_id,  | 
                                                        |
| 428 | -                'args'       => array('trash' => false), | 
                                                        |
| 429 | - 'noheader' => true  | 
                                                        |
| 430 | - ),  | 
                                                        |
| 431 | - 'delete_message_template' => array(  | 
                                                        |
| 432 | - 'func' => '_delete_message_template',  | 
                                                        |
| 433 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 434 | - 'obj_id' => $grp_id,  | 
                                                        |
| 435 | - 'noheader' => true  | 
                                                        |
| 436 | - ),  | 
                                                        |
| 437 | - 'reset_to_default' => array(  | 
                                                        |
| 438 | - 'func' => '_reset_to_default_template',  | 
                                                        |
| 439 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 440 | - 'obj_id' => $grp_id,  | 
                                                        |
| 441 | - 'noheader' => true  | 
                                                        |
| 442 | - ),  | 
                                                        |
| 443 | - 'settings' => array(  | 
                                                        |
| 444 | - 'func' => '_settings',  | 
                                                        |
| 445 | - 'capability' => 'manage_options'  | 
                                                        |
| 446 | - ),  | 
                                                        |
| 447 | - 'update_global_settings' => array(  | 
                                                        |
| 448 | - 'func' => '_update_global_settings',  | 
                                                        |
| 449 | - 'capability' => 'manage_options',  | 
                                                        |
| 450 | - 'noheader' => true  | 
                                                        |
| 451 | - ),  | 
                                                        |
| 452 | - 'generate_now' => array(  | 
                                                        |
| 453 | - 'func' => '_generate_now',  | 
                                                        |
| 454 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 455 | - 'noheader' => true  | 
                                                        |
| 456 | - ),  | 
                                                        |
| 457 | - 'generate_and_send_now' => array(  | 
                                                        |
| 458 | - 'func' => '_generate_and_send_now',  | 
                                                        |
| 459 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 460 | - 'noheader' => true  | 
                                                        |
| 461 | - ),  | 
                                                        |
| 462 | - 'queue_for_resending' => array(  | 
                                                        |
| 463 | - 'func' => '_queue_for_resending',  | 
                                                        |
| 464 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 465 | - 'noheader' => true  | 
                                                        |
| 466 | - ),  | 
                                                        |
| 467 | - 'send_now' => array(  | 
                                                        |
| 468 | - 'func' => '_send_now',  | 
                                                        |
| 469 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 470 | - 'noheader' => true  | 
                                                        |
| 471 | - ),  | 
                                                        |
| 472 | - 'delete_ee_message' => array(  | 
                                                        |
| 473 | - 'func' => '_delete_ee_messages',  | 
                                                        |
| 474 | - 'capability' => 'ee_delete_messages',  | 
                                                        |
| 475 | - 'noheader' => true  | 
                                                        |
| 476 | - ),  | 
                                                        |
| 477 | - 'delete_ee_messages' => array(  | 
                                                        |
| 478 | - 'func' => '_delete_ee_messages',  | 
                                                        |
| 479 | - 'capability' => 'ee_delete_messages',  | 
                                                        |
| 480 | - 'noheader' => true,  | 
                                                        |
| 481 | - 'obj_id' => $msg_id  | 
                                                        |
| 482 | - )  | 
                                                        |
| 483 | - );  | 
                                                        |
| 484 | - }  | 
                                                        |
| 485 | -  | 
                                                        |
| 486 | -  | 
                                                        |
| 487 | - protected function _set_page_config()  | 
                                                        |
| 488 | -    { | 
                                                        |
| 489 | - $this->_page_config = array(  | 
                                                        |
| 490 | - 'default' => array(  | 
                                                        |
| 491 | - 'nav' => array(  | 
                                                        |
| 492 | -                    'label' => __('Message Activity', 'event_espresso'), | 
                                                        |
| 493 | - 'order' => 10  | 
                                                        |
| 494 | - ),  | 
                                                        |
| 495 | - 'list_table' => 'EE_Message_List_Table',  | 
                                                        |
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ),  | 
                                                        |
| 497 | - 'require_nonce' => false  | 
                                                        |
| 498 | - ),  | 
                                                        |
| 499 | - 'global_mtps' => array(  | 
                                                        |
| 500 | - 'nav' => array(  | 
                                                        |
| 501 | -                    'label' => __('Default Message Templates', 'event_espresso'), | 
                                                        |
| 502 | - 'order' => 20  | 
                                                        |
| 503 | - ),  | 
                                                        |
| 504 | - 'list_table' => 'Messages_Template_List_Table',  | 
                                                        |
| 505 | - 'help_tabs' => array(  | 
                                                        |
| 506 | - 'messages_overview_help_tab' => array(  | 
                                                        |
| 507 | -                        'title'    => __('Messages Overview', 'event_espresso'), | 
                                                        |
| 508 | - 'filename' => 'messages_overview'  | 
                                                        |
| 509 | - ),  | 
                                                        |
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array(  | 
                                                        |
| 511 | -                        'title'    => __('Messages Table Column Headings', 'event_espresso'), | 
                                                        |
| 512 | - 'filename' => 'messages_overview_table_column_headings'  | 
                                                        |
| 513 | - ),  | 
                                                        |
| 514 | - 'messages_overview_messages_filters_help_tab' => array(  | 
                                                        |
| 515 | -                        'title'    => __('Message Filters', 'event_espresso'), | 
                                                        |
| 516 | - 'filename' => 'messages_overview_filters'  | 
                                                        |
| 517 | - ),  | 
                                                        |
| 518 | - 'messages_overview_messages_views_help_tab' => array(  | 
                                                        |
| 519 | -                        'title'    => __('Message Views', 'event_espresso'), | 
                                                        |
| 520 | - 'filename' => 'messages_overview_views'  | 
                                                        |
| 521 | - ),  | 
                                                        |
| 522 | - 'message_overview_message_types_help_tab' => array(  | 
                                                        |
| 523 | -                        'title'    => __('Message Types', 'event_espresso'), | 
                                                        |
| 524 | - 'filename' => 'messages_overview_types'  | 
                                                        |
| 525 | - ),  | 
                                                        |
| 526 | - 'messages_overview_messengers_help_tab' => array(  | 
                                                        |
| 527 | -                        'title'    => __('Messengers', 'event_espresso'), | 
                                                        |
| 528 | - 'filename' => 'messages_overview_messengers',  | 
                                                        |
| 529 | - ),  | 
                                                        |
| 530 | - ),  | 
                                                        |
| 531 | -                'help_tour'     => array('Messages_Overview_Help_Tour'), | 
                                                        |
| 532 | - 'require_nonce' => false  | 
                                                        |
| 533 | - ),  | 
                                                        |
| 534 | - 'custom_mtps' => array(  | 
                                                        |
| 535 | - 'nav' => array(  | 
                                                        |
| 536 | -                    'label' => __('Custom Message Templates', 'event_espresso'), | 
                                                        |
| 537 | - 'order' => 30  | 
                                                        |
| 538 | - ),  | 
                                                        |
| 539 | - 'help_tabs' => array(),  | 
                                                        |
| 540 | - 'help_tour' => array(),  | 
                                                        |
| 541 | - 'require_nonce' => false  | 
                                                        |
| 542 | - ),  | 
                                                        |
| 543 | - 'add_new_message_template' => array(  | 
                                                        |
| 544 | - 'nav' => array(  | 
                                                        |
| 545 | -                    'label'      => __('Add New Message Templates', 'event_espresso'), | 
                                                        |
| 546 | - 'order' => 5,  | 
                                                        |
| 547 | - 'persistent' => false  | 
                                                        |
| 548 | - ),  | 
                                                        |
| 549 | - 'require_nonce' => false  | 
                                                        |
| 550 | - ),  | 
                                                        |
| 551 | - 'edit_message_template' => array(  | 
                                                        |
| 552 | - 'labels' => array(  | 
                                                        |
| 553 | - 'buttons' => array(  | 
                                                        |
| 554 | -                        'reset' => __('Reset Templates'), | 
                                                        |
| 555 | - ),  | 
                                                        |
| 556 | -                    'publishbox' => __('Update Actions', 'event_espresso') | 
                                                        |
| 557 | - ),  | 
                                                        |
| 558 | - 'nav' => array(  | 
                                                        |
| 559 | -                    'label'      => __('Edit Message Templates', 'event_espresso'), | 
                                                        |
| 560 | - 'order' => 5,  | 
                                                        |
| 561 | - 'persistent' => false,  | 
                                                        |
| 562 | - 'url' => ''  | 
                                                        |
| 563 | - ),  | 
                                                        |
| 564 | -                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'), | 
                                                        |
| 565 | - 'has_metaboxes' => true,  | 
                                                        |
| 566 | -                'help_tour'     => array('Message_Templates_Edit_Help_Tour'), | 
                                                        |
| 567 | - 'help_tabs' => array(  | 
                                                        |
| 568 | - 'edit_message_template' => array(  | 
                                                        |
| 569 | -                        'title'    => __('Message Template Editor', 'event_espresso'), | 
                                                        |
| 570 | - 'callback' => 'edit_message_template_help_tab'  | 
                                                        |
| 571 | - ),  | 
                                                        |
| 572 | - 'message_templates_help_tab' => array(  | 
                                                        |
| 573 | -                        'title'    => __('Message Templates', 'event_espresso'), | 
                                                        |
| 574 | - 'filename' => 'messages_templates'  | 
                                                        |
| 575 | - ),  | 
                                                        |
| 576 | - 'message_template_shortcodes' => array(  | 
                                                        |
| 577 | -                        'title'    => __('Message Shortcodes', 'event_espresso'), | 
                                                        |
| 578 | - 'callback' => 'message_template_shortcodes_help_tab'  | 
                                                        |
| 579 | - ),  | 
                                                        |
| 580 | - 'message_preview_help_tab' => array(  | 
                                                        |
| 581 | -                        'title'    => __('Message Preview', 'event_espresso'), | 
                                                        |
| 582 | - 'filename' => 'messages_preview'  | 
                                                        |
| 583 | - ),  | 
                                                        |
| 584 | - 'messages_overview_other_help_tab' => array(  | 
                                                        |
| 585 | -                        'title'    => __('Messages Other', 'event_espresso'), | 
                                                        |
| 586 | - 'filename' => 'messages_overview_other',  | 
                                                        |
| 587 | - ),  | 
                                                        |
| 588 | - ),  | 
                                                        |
| 589 | - 'require_nonce' => false  | 
                                                        |
| 590 | - ),  | 
                                                        |
| 591 | - 'display_preview_message' => array(  | 
                                                        |
| 592 | - 'nav' => array(  | 
                                                        |
| 593 | -                    'label'      => __('Message Preview', 'event_espresso'), | 
                                                        |
| 594 | - 'order' => 5,  | 
                                                        |
| 595 | - 'url' => '',  | 
                                                        |
| 596 | - 'persistent' => false  | 
                                                        |
| 597 | - ),  | 
                                                        |
| 598 | - 'help_tabs' => array(  | 
                                                        |
| 599 | - 'preview_message' => array(  | 
                                                        |
| 600 | -                        'title'    => __('About Previews', 'event_espresso'), | 
                                                        |
| 601 | - 'callback' => 'preview_message_help_tab'  | 
                                                        |
| 602 | - )  | 
                                                        |
| 603 | - ),  | 
                                                        |
| 604 | - 'require_nonce' => false  | 
                                                        |
| 605 | - ),  | 
                                                        |
| 606 | - 'settings' => array(  | 
                                                        |
| 607 | - 'nav' => array(  | 
                                                        |
| 608 | -                    'label' => __('Settings', 'event_espresso'), | 
                                                        |
| 609 | - 'order' => 40  | 
                                                        |
| 610 | - ),  | 
                                                        |
| 611 | -                'metaboxes'     => array('_messages_settings_metaboxes'), | 
                                                        |
| 612 | - 'help_tabs' => array(  | 
                                                        |
| 613 | - 'messages_settings_help_tab' => array(  | 
                                                        |
| 614 | -                        'title'    => __('Messages Settings', 'event_espresso'), | 
                                                        |
| 615 | - 'filename' => 'messages_settings'  | 
                                                        |
| 616 | - ),  | 
                                                        |
| 617 | - 'messages_settings_message_types_help_tab' => array(  | 
                                                        |
| 618 | -                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'), | 
                                                        |
| 619 | - 'filename' => 'messages_settings_message_types'  | 
                                                        |
| 620 | - ),  | 
                                                        |
| 621 | - 'messages_settings_messengers_help_tab' => array(  | 
                                                        |
| 622 | -                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'), | 
                                                        |
| 623 | - 'filename' => 'messages_settings_messengers'  | 
                                                        |
| 624 | - ),  | 
                                                        |
| 625 | - ),  | 
                                                        |
| 626 | -                'help_tour'     => array('Messages_Settings_Help_Tour'), | 
                                                        |
| 627 | - 'require_nonce' => false  | 
                                                        |
| 628 | - )  | 
                                                        |
| 629 | - );  | 
                                                        |
| 630 | - }  | 
                                                        |
| 631 | -  | 
                                                        |
| 632 | -  | 
                                                        |
| 633 | - protected function _add_screen_options()  | 
                                                        |
| 634 | -    { | 
                                                        |
| 635 | - //todo  | 
                                                        |
| 636 | - }  | 
                                                        |
| 637 | -  | 
                                                        |
| 638 | -  | 
                                                        |
| 639 | - protected function _add_screen_options_global_mtps()  | 
                                                        |
| 640 | -    { | 
                                                        |
| 641 | - /**  | 
                                                        |
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options  | 
                                                        |
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots.  | 
                                                        |
| 644 | - */  | 
                                                        |
| 645 | - $page_title = $this->_admin_page_title;  | 
                                                        |
| 646 | -        $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); | 
                                                        |
| 647 | - $this->_per_page_screen_option();  | 
                                                        |
| 648 | - $this->_admin_page_title = $page_title;  | 
                                                        |
| 649 | - }  | 
                                                        |
| 650 | -  | 
                                                        |
| 651 | -  | 
                                                        |
| 652 | - protected function _add_screen_options_default()  | 
                                                        |
| 653 | -    { | 
                                                        |
| 654 | -        $this->_admin_page_title = __('Message Activity', 'event_espresso'); | 
                                                        |
| 655 | - $this->_per_page_screen_option();  | 
                                                        |
| 656 | - }  | 
                                                        |
| 657 | -  | 
                                                        |
| 658 | -  | 
                                                        |
| 659 | - //none of the below group are currently used for Messages  | 
                                                        |
| 660 | - protected function _add_feature_pointers()  | 
                                                        |
| 661 | -    { | 
                                                        |
| 662 | - }  | 
                                                        |
| 663 | -  | 
                                                        |
| 664 | - public function admin_init()  | 
                                                        |
| 665 | -    { | 
                                                        |
| 666 | - }  | 
                                                        |
| 667 | -  | 
                                                        |
| 668 | - public function admin_notices()  | 
                                                        |
| 669 | -    { | 
                                                        |
| 670 | - }  | 
                                                        |
| 671 | -  | 
                                                        |
| 672 | - public function admin_footer_scripts()  | 
                                                        |
| 673 | -    { | 
                                                        |
| 674 | - }  | 
                                                        |
| 675 | -  | 
                                                        |
| 676 | -  | 
                                                        |
| 677 | - public function messages_help_tab()  | 
                                                        |
| 678 | -    { | 
                                                        |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 680 | - }  | 
                                                        |
| 681 | -  | 
                                                        |
| 682 | -  | 
                                                        |
| 683 | - public function messengers_help_tab()  | 
                                                        |
| 684 | -    { | 
                                                        |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 686 | - }  | 
                                                        |
| 687 | -  | 
                                                        |
| 688 | -  | 
                                                        |
| 689 | - public function message_types_help_tab()  | 
                                                        |
| 690 | -    { | 
                                                        |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 692 | - }  | 
                                                        |
| 693 | -  | 
                                                        |
| 694 | -  | 
                                                        |
| 695 | - public function messages_overview_help_tab()  | 
                                                        |
| 696 | -    { | 
                                                        |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 698 | - }  | 
                                                        |
| 699 | -  | 
                                                        |
| 700 | -  | 
                                                        |
| 701 | - public function message_templates_help_tab()  | 
                                                        |
| 702 | -    { | 
                                                        |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 704 | - }  | 
                                                        |
| 705 | -  | 
                                                        |
| 706 | -  | 
                                                        |
| 707 | - public function edit_message_template_help_tab()  | 
                                                        |
| 708 | -    { | 
                                                        |
| 709 | -        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', | 
                                                        |
| 710 | - 'event_espresso') . '" />';  | 
                                                        |
| 711 | -        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', | 
                                                        |
| 712 | - 'event_espresso') . '" />';  | 
                                                        |
| 713 | -        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', | 
                                                        |
| 714 | - 'event_espresso') . '" />';  | 
                                                        |
| 715 | -        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', | 
                                                        |
| 716 | - 'event_espresso') . '" />';  | 
                                                        |
| 717 | -        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', | 
                                                        |
| 718 | - 'event_espresso') . '" />';  | 
                                                        |
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 720 | - $args);  | 
                                                        |
| 721 | - }  | 
                                                        |
| 722 | -  | 
                                                        |
| 723 | -  | 
                                                        |
| 724 | - public function message_template_shortcodes_help_tab()  | 
                                                        |
| 725 | -    { | 
                                                        |
| 726 | - $this->_set_shortcodes();  | 
                                                        |
| 727 | - $args['shortcodes'] = $this->_shortcodes;  | 
                                                        |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 729 | - $args);  | 
                                                        |
| 730 | - }  | 
                                                        |
| 179 | + '4.9.9.rc.014'  | 
                                                        |
| 180 | + );  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + $contexts = array();  | 
                                                        |
| 183 | +		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); | 
                                                        |
| 184 | +		foreach ($active_message_contexts as $active_message) { | 
                                                        |
| 185 | +			if ($active_message instanceof EE_Message) { | 
                                                        |
| 186 | + $message_type = $active_message->message_type_object();  | 
                                                        |
| 187 | +				if ($message_type instanceof EE_message_type) { | 
                                                        |
| 188 | + $message_type_contexts = $message_type->get_contexts();  | 
                                                        |
| 189 | +					foreach ($message_type_contexts as $context => $context_details) { | 
                                                        |
| 190 | + $contexts[$context] = $context_details['label'];  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | + }  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | + }  | 
                                                        |
| 195 | +  | 
                                                        |
| 196 | + return $contexts;  | 
                                                        |
| 197 | + }  | 
                                                        |
| 198 | +  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | + /**  | 
                                                        |
| 201 | + * Generate select input with provided messenger options array.  | 
                                                        |
| 202 | + *  | 
                                                        |
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger  | 
                                                        |
| 204 | + * labels.  | 
                                                        |
| 205 | + *  | 
                                                        |
| 206 | + * @return string  | 
                                                        |
| 207 | + */  | 
                                                        |
| 208 | + public function get_messengers_select_input($messenger_options)  | 
                                                        |
| 209 | +	{ | 
                                                        |
| 210 | + //if empty or just one value then just return an empty string  | 
                                                        |
| 211 | + if (empty($messenger_options)  | 
                                                        |
| 212 | + || ! is_array($messenger_options)  | 
                                                        |
| 213 | + || count($messenger_options) === 1  | 
                                                        |
| 214 | +		) { | 
                                                        |
| 215 | + return '';  | 
                                                        |
| 216 | + }  | 
                                                        |
| 217 | + //merge in default  | 
                                                        |
| 218 | + $messenger_options = array_merge(  | 
                                                        |
| 219 | +			array('none_selected' => __('Show All Messengers', 'event_espresso')), | 
                                                        |
| 220 | + $messenger_options  | 
                                                        |
| 221 | + );  | 
                                                        |
| 222 | + $input = new EE_Select_Input(  | 
                                                        |
| 223 | + $messenger_options,  | 
                                                        |
| 224 | + array(  | 
                                                        |
| 225 | + 'html_name' => 'ee_messenger_filter_by',  | 
                                                        |
| 226 | + 'html_id' => 'ee_messenger_filter_by',  | 
                                                        |
| 227 | + 'html_class' => 'wide',  | 
                                                        |
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by'])  | 
                                                        |
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by'])  | 
                                                        |
| 230 | + : 'none_selected'  | 
                                                        |
| 231 | + )  | 
                                                        |
| 232 | + );  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | + return $input->get_html_for_input();  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | +  | 
                                                        |
| 237 | +  | 
                                                        |
| 238 | + /**  | 
                                                        |
| 239 | + * Generate select input with provided message type options array.  | 
                                                        |
| 240 | + *  | 
                                                        |
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the  | 
                                                        |
| 242 | + * message type labels  | 
                                                        |
| 243 | + *  | 
                                                        |
| 244 | + * @return string  | 
                                                        |
| 245 | + */  | 
                                                        |
| 246 | + public function get_message_types_select_input($message_type_options)  | 
                                                        |
| 247 | +	{ | 
                                                        |
| 248 | + //if empty or count of options is 1 then just return an empty string  | 
                                                        |
| 249 | + if (empty($message_type_options)  | 
                                                        |
| 250 | + || ! is_array($message_type_options)  | 
                                                        |
| 251 | + || count($message_type_options) === 1  | 
                                                        |
| 252 | +		) { | 
                                                        |
| 253 | + return '';  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | + //merge in default  | 
                                                        |
| 256 | + $message_type_options = array_merge(  | 
                                                        |
| 257 | +			array('none_selected' => __('Show All Message Types', 'event_espresso')), | 
                                                        |
| 258 | + $message_type_options  | 
                                                        |
| 259 | + );  | 
                                                        |
| 260 | + $input = new EE_Select_Input(  | 
                                                        |
| 261 | + $message_type_options,  | 
                                                        |
| 262 | + array(  | 
                                                        |
| 263 | + 'html_name' => 'ee_message_type_filter_by',  | 
                                                        |
| 264 | + 'html_id' => 'ee_message_type_filter_by',  | 
                                                        |
| 265 | + 'html_class' => 'wide',  | 
                                                        |
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by'])  | 
                                                        |
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by'])  | 
                                                        |
| 268 | + : 'none_selected',  | 
                                                        |
| 269 | + )  | 
                                                        |
| 270 | + );  | 
                                                        |
| 271 | +  | 
                                                        |
| 272 | + return $input->get_html_for_input();  | 
                                                        |
| 273 | + }  | 
                                                        |
| 274 | +  | 
                                                        |
| 275 | +  | 
                                                        |
| 276 | + /**  | 
                                                        |
| 277 | + * Generate select input with provide message type contexts array.  | 
                                                        |
| 278 | + *  | 
                                                        |
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the  | 
                                                        |
| 280 | + * context label.  | 
                                                        |
| 281 | + *  | 
                                                        |
| 282 | + * @return string  | 
                                                        |
| 283 | + */  | 
                                                        |
| 284 | + public function get_contexts_for_message_types_select_input($context_options)  | 
                                                        |
| 285 | +	{ | 
                                                        |
| 286 | + //if empty or count of options is one then just return empty string  | 
                                                        |
| 287 | + if (empty($context_options)  | 
                                                        |
| 288 | + || ! is_array($context_options)  | 
                                                        |
| 289 | + || count($context_options) === 1  | 
                                                        |
| 290 | +		) { | 
                                                        |
| 291 | + return '';  | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | + //merge in default  | 
                                                        |
| 294 | + $context_options = array_merge(  | 
                                                        |
| 295 | +			array('none_selected' => __('Show all Contexts', 'event_espresso')), | 
                                                        |
| 296 | + $context_options  | 
                                                        |
| 297 | + );  | 
                                                        |
| 298 | + $input = new EE_Select_Input(  | 
                                                        |
| 299 | + $context_options,  | 
                                                        |
| 300 | + array(  | 
                                                        |
| 301 | + 'html_name' => 'ee_context_filter_by',  | 
                                                        |
| 302 | + 'html_id' => 'ee_context_filter_by',  | 
                                                        |
| 303 | + 'html_class' => 'wide',  | 
                                                        |
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by'])  | 
                                                        |
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by'])  | 
                                                        |
| 306 | + : 'none_selected',  | 
                                                        |
| 307 | + )  | 
                                                        |
| 308 | + );  | 
                                                        |
| 309 | +  | 
                                                        |
| 310 | + return $input->get_html_for_input();  | 
                                                        |
| 311 | + }  | 
                                                        |
| 312 | +  | 
                                                        |
| 313 | +  | 
                                                        |
| 314 | + protected function _ajax_hooks()  | 
                                                        |
| 315 | +	{ | 
                                                        |
| 316 | +		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); | 
                                                        |
| 317 | +		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); | 
                                                        |
| 318 | +		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); | 
                                                        |
| 319 | +		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); | 
                                                        |
| 320 | +		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); | 
                                                        |
| 321 | + }  | 
                                                        |
| 322 | +  | 
                                                        |
| 323 | +  | 
                                                        |
| 324 | + protected function _define_page_props()  | 
                                                        |
| 325 | +	{ | 
                                                        |
| 326 | + $this->_admin_page_title = $this->page_label;  | 
                                                        |
| 327 | + $this->_labels = array(  | 
                                                        |
| 328 | + 'buttons' => array(  | 
                                                        |
| 329 | +				'add'    => __('Add New Message Template', 'event_espresso'), | 
                                                        |
| 330 | +				'edit'   => __('Edit Message Template', 'event_espresso'), | 
                                                        |
| 331 | +				'delete' => __('Delete Message Template', 'event_espresso') | 
                                                        |
| 332 | + ),  | 
                                                        |
| 333 | +			'publishbox' => __('Update Actions', 'event_espresso') | 
                                                        |
| 334 | + );  | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | +  | 
                                                        |
| 338 | + /**  | 
                                                        |
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods  | 
                                                        |
| 340 | + * @access protected  | 
                                                        |
| 341 | + * @return void  | 
                                                        |
| 342 | + */  | 
                                                        |
| 343 | + protected function _set_page_routes()  | 
                                                        |
| 344 | +	{ | 
                                                        |
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])  | 
                                                        |
| 346 | + ? $this->_req_data['GRP_ID']  | 
                                                        |
| 347 | + : 0;  | 
                                                        |
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])  | 
                                                        |
| 349 | + ? $this->_req_data['id']  | 
                                                        |
| 350 | + : $grp_id;  | 
                                                        |
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])  | 
                                                        |
| 352 | + ? $this->_req_data['MSG_ID']  | 
                                                        |
| 353 | + : 0;  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | + $this->_page_routes = array(  | 
                                                        |
| 356 | + 'default' => array(  | 
                                                        |
| 357 | + 'func' => '_message_queue_list_table',  | 
                                                        |
| 358 | + 'capability' => 'ee_read_global_messages'  | 
                                                        |
| 359 | + ),  | 
                                                        |
| 360 | + 'global_mtps' => array(  | 
                                                        |
| 361 | + 'func' => '_ee_default_messages_overview_list_table',  | 
                                                        |
| 362 | + 'capability' => 'ee_read_global_messages'  | 
                                                        |
| 363 | + ),  | 
                                                        |
| 364 | + 'custom_mtps' => array(  | 
                                                        |
| 365 | + 'func' => '_custom_mtps_preview',  | 
                                                        |
| 366 | + 'capability' => 'ee_read_messages'  | 
                                                        |
| 367 | + ),  | 
                                                        |
| 368 | + 'add_new_message_template' => array(  | 
                                                        |
| 369 | + 'func' => '_add_message_template',  | 
                                                        |
| 370 | + 'capability' => 'ee_edit_messages',  | 
                                                        |
| 371 | + 'noheader' => true  | 
                                                        |
| 372 | + ),  | 
                                                        |
| 373 | + 'edit_message_template' => array(  | 
                                                        |
| 374 | + 'func' => '_edit_message_template',  | 
                                                        |
| 375 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 376 | + 'obj_id' => $grp_id  | 
                                                        |
| 377 | + ),  | 
                                                        |
| 378 | + 'preview_message' => array(  | 
                                                        |
| 379 | + 'func' => '_preview_message',  | 
                                                        |
| 380 | + 'capability' => 'ee_read_message',  | 
                                                        |
| 381 | + 'obj_id' => $grp_id,  | 
                                                        |
| 382 | + 'noheader' => true,  | 
                                                        |
| 383 | + 'headers_sent_route' => 'display_preview_message'  | 
                                                        |
| 384 | + ),  | 
                                                        |
| 385 | + 'display_preview_message' => array(  | 
                                                        |
| 386 | + 'func' => '_display_preview_message',  | 
                                                        |
| 387 | + 'capability' => 'ee_read_message',  | 
                                                        |
| 388 | + 'obj_id' => $grp_id  | 
                                                        |
| 389 | + ),  | 
                                                        |
| 390 | + 'insert_message_template' => array(  | 
                                                        |
| 391 | + 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 392 | + 'capability' => 'ee_edit_messages',  | 
                                                        |
| 393 | +				'args'       => array('new_template' => true), | 
                                                        |
| 394 | + 'noheader' => true  | 
                                                        |
| 395 | + ),  | 
                                                        |
| 396 | + 'update_message_template' => array(  | 
                                                        |
| 397 | + 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 398 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 399 | + 'obj_id' => $grp_id,  | 
                                                        |
| 400 | +				'args'       => array('new_template' => false), | 
                                                        |
| 401 | + 'noheader' => true  | 
                                                        |
| 402 | + ),  | 
                                                        |
| 403 | + 'trash_message_template' => array(  | 
                                                        |
| 404 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 405 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 406 | + 'obj_id' => $grp_id,  | 
                                                        |
| 407 | +				'args'       => array('trash' => true, 'all' => true), | 
                                                        |
| 408 | + 'noheader' => true  | 
                                                        |
| 409 | + ),  | 
                                                        |
| 410 | + 'trash_message_template_context' => array(  | 
                                                        |
| 411 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 412 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 413 | + 'obj_id' => $grp_id,  | 
                                                        |
| 414 | +				'args'       => array('trash' => true), | 
                                                        |
| 415 | + 'noheader' => true  | 
                                                        |
| 416 | + ),  | 
                                                        |
| 417 | + 'restore_message_template' => array(  | 
                                                        |
| 418 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 419 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 420 | + 'obj_id' => $grp_id,  | 
                                                        |
| 421 | +				'args'       => array('trash' => false, 'all' => true), | 
                                                        |
| 422 | + 'noheader' => true  | 
                                                        |
| 423 | + ),  | 
                                                        |
| 424 | + 'restore_message_template_context' => array(  | 
                                                        |
| 425 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 426 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 427 | + 'obj_id' => $grp_id,  | 
                                                        |
| 428 | +				'args'       => array('trash' => false), | 
                                                        |
| 429 | + 'noheader' => true  | 
                                                        |
| 430 | + ),  | 
                                                        |
| 431 | + 'delete_message_template' => array(  | 
                                                        |
| 432 | + 'func' => '_delete_message_template',  | 
                                                        |
| 433 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 434 | + 'obj_id' => $grp_id,  | 
                                                        |
| 435 | + 'noheader' => true  | 
                                                        |
| 436 | + ),  | 
                                                        |
| 437 | + 'reset_to_default' => array(  | 
                                                        |
| 438 | + 'func' => '_reset_to_default_template',  | 
                                                        |
| 439 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 440 | + 'obj_id' => $grp_id,  | 
                                                        |
| 441 | + 'noheader' => true  | 
                                                        |
| 442 | + ),  | 
                                                        |
| 443 | + 'settings' => array(  | 
                                                        |
| 444 | + 'func' => '_settings',  | 
                                                        |
| 445 | + 'capability' => 'manage_options'  | 
                                                        |
| 446 | + ),  | 
                                                        |
| 447 | + 'update_global_settings' => array(  | 
                                                        |
| 448 | + 'func' => '_update_global_settings',  | 
                                                        |
| 449 | + 'capability' => 'manage_options',  | 
                                                        |
| 450 | + 'noheader' => true  | 
                                                        |
| 451 | + ),  | 
                                                        |
| 452 | + 'generate_now' => array(  | 
                                                        |
| 453 | + 'func' => '_generate_now',  | 
                                                        |
| 454 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 455 | + 'noheader' => true  | 
                                                        |
| 456 | + ),  | 
                                                        |
| 457 | + 'generate_and_send_now' => array(  | 
                                                        |
| 458 | + 'func' => '_generate_and_send_now',  | 
                                                        |
| 459 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 460 | + 'noheader' => true  | 
                                                        |
| 461 | + ),  | 
                                                        |
| 462 | + 'queue_for_resending' => array(  | 
                                                        |
| 463 | + 'func' => '_queue_for_resending',  | 
                                                        |
| 464 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 465 | + 'noheader' => true  | 
                                                        |
| 466 | + ),  | 
                                                        |
| 467 | + 'send_now' => array(  | 
                                                        |
| 468 | + 'func' => '_send_now',  | 
                                                        |
| 469 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 470 | + 'noheader' => true  | 
                                                        |
| 471 | + ),  | 
                                                        |
| 472 | + 'delete_ee_message' => array(  | 
                                                        |
| 473 | + 'func' => '_delete_ee_messages',  | 
                                                        |
| 474 | + 'capability' => 'ee_delete_messages',  | 
                                                        |
| 475 | + 'noheader' => true  | 
                                                        |
| 476 | + ),  | 
                                                        |
| 477 | + 'delete_ee_messages' => array(  | 
                                                        |
| 478 | + 'func' => '_delete_ee_messages',  | 
                                                        |
| 479 | + 'capability' => 'ee_delete_messages',  | 
                                                        |
| 480 | + 'noheader' => true,  | 
                                                        |
| 481 | + 'obj_id' => $msg_id  | 
                                                        |
| 482 | + )  | 
                                                        |
| 483 | + );  | 
                                                        |
| 484 | + }  | 
                                                        |
| 485 | +  | 
                                                        |
| 486 | +  | 
                                                        |
| 487 | + protected function _set_page_config()  | 
                                                        |
| 488 | +	{ | 
                                                        |
| 489 | + $this->_page_config = array(  | 
                                                        |
| 490 | + 'default' => array(  | 
                                                        |
| 491 | + 'nav' => array(  | 
                                                        |
| 492 | +					'label' => __('Message Activity', 'event_espresso'), | 
                                                        |
| 493 | + 'order' => 10  | 
                                                        |
| 494 | + ),  | 
                                                        |
| 495 | + 'list_table' => 'EE_Message_List_Table',  | 
                                                        |
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ),  | 
                                                        |
| 497 | + 'require_nonce' => false  | 
                                                        |
| 498 | + ),  | 
                                                        |
| 499 | + 'global_mtps' => array(  | 
                                                        |
| 500 | + 'nav' => array(  | 
                                                        |
| 501 | +					'label' => __('Default Message Templates', 'event_espresso'), | 
                                                        |
| 502 | + 'order' => 20  | 
                                                        |
| 503 | + ),  | 
                                                        |
| 504 | + 'list_table' => 'Messages_Template_List_Table',  | 
                                                        |
| 505 | + 'help_tabs' => array(  | 
                                                        |
| 506 | + 'messages_overview_help_tab' => array(  | 
                                                        |
| 507 | +						'title'    => __('Messages Overview', 'event_espresso'), | 
                                                        |
| 508 | + 'filename' => 'messages_overview'  | 
                                                        |
| 509 | + ),  | 
                                                        |
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array(  | 
                                                        |
| 511 | +						'title'    => __('Messages Table Column Headings', 'event_espresso'), | 
                                                        |
| 512 | + 'filename' => 'messages_overview_table_column_headings'  | 
                                                        |
| 513 | + ),  | 
                                                        |
| 514 | + 'messages_overview_messages_filters_help_tab' => array(  | 
                                                        |
| 515 | +						'title'    => __('Message Filters', 'event_espresso'), | 
                                                        |
| 516 | + 'filename' => 'messages_overview_filters'  | 
                                                        |
| 517 | + ),  | 
                                                        |
| 518 | + 'messages_overview_messages_views_help_tab' => array(  | 
                                                        |
| 519 | +						'title'    => __('Message Views', 'event_espresso'), | 
                                                        |
| 520 | + 'filename' => 'messages_overview_views'  | 
                                                        |
| 521 | + ),  | 
                                                        |
| 522 | + 'message_overview_message_types_help_tab' => array(  | 
                                                        |
| 523 | +						'title'    => __('Message Types', 'event_espresso'), | 
                                                        |
| 524 | + 'filename' => 'messages_overview_types'  | 
                                                        |
| 525 | + ),  | 
                                                        |
| 526 | + 'messages_overview_messengers_help_tab' => array(  | 
                                                        |
| 527 | +						'title'    => __('Messengers', 'event_espresso'), | 
                                                        |
| 528 | + 'filename' => 'messages_overview_messengers',  | 
                                                        |
| 529 | + ),  | 
                                                        |
| 530 | + ),  | 
                                                        |
| 531 | +				'help_tour'     => array('Messages_Overview_Help_Tour'), | 
                                                        |
| 532 | + 'require_nonce' => false  | 
                                                        |
| 533 | + ),  | 
                                                        |
| 534 | + 'custom_mtps' => array(  | 
                                                        |
| 535 | + 'nav' => array(  | 
                                                        |
| 536 | +					'label' => __('Custom Message Templates', 'event_espresso'), | 
                                                        |
| 537 | + 'order' => 30  | 
                                                        |
| 538 | + ),  | 
                                                        |
| 539 | + 'help_tabs' => array(),  | 
                                                        |
| 540 | + 'help_tour' => array(),  | 
                                                        |
| 541 | + 'require_nonce' => false  | 
                                                        |
| 542 | + ),  | 
                                                        |
| 543 | + 'add_new_message_template' => array(  | 
                                                        |
| 544 | + 'nav' => array(  | 
                                                        |
| 545 | +					'label'      => __('Add New Message Templates', 'event_espresso'), | 
                                                        |
| 546 | + 'order' => 5,  | 
                                                        |
| 547 | + 'persistent' => false  | 
                                                        |
| 548 | + ),  | 
                                                        |
| 549 | + 'require_nonce' => false  | 
                                                        |
| 550 | + ),  | 
                                                        |
| 551 | + 'edit_message_template' => array(  | 
                                                        |
| 552 | + 'labels' => array(  | 
                                                        |
| 553 | + 'buttons' => array(  | 
                                                        |
| 554 | +						'reset' => __('Reset Templates'), | 
                                                        |
| 555 | + ),  | 
                                                        |
| 556 | +					'publishbox' => __('Update Actions', 'event_espresso') | 
                                                        |
| 557 | + ),  | 
                                                        |
| 558 | + 'nav' => array(  | 
                                                        |
| 559 | +					'label'      => __('Edit Message Templates', 'event_espresso'), | 
                                                        |
| 560 | + 'order' => 5,  | 
                                                        |
| 561 | + 'persistent' => false,  | 
                                                        |
| 562 | + 'url' => ''  | 
                                                        |
| 563 | + ),  | 
                                                        |
| 564 | +				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'), | 
                                                        |
| 565 | + 'has_metaboxes' => true,  | 
                                                        |
| 566 | +				'help_tour'     => array('Message_Templates_Edit_Help_Tour'), | 
                                                        |
| 567 | + 'help_tabs' => array(  | 
                                                        |
| 568 | + 'edit_message_template' => array(  | 
                                                        |
| 569 | +						'title'    => __('Message Template Editor', 'event_espresso'), | 
                                                        |
| 570 | + 'callback' => 'edit_message_template_help_tab'  | 
                                                        |
| 571 | + ),  | 
                                                        |
| 572 | + 'message_templates_help_tab' => array(  | 
                                                        |
| 573 | +						'title'    => __('Message Templates', 'event_espresso'), | 
                                                        |
| 574 | + 'filename' => 'messages_templates'  | 
                                                        |
| 575 | + ),  | 
                                                        |
| 576 | + 'message_template_shortcodes' => array(  | 
                                                        |
| 577 | +						'title'    => __('Message Shortcodes', 'event_espresso'), | 
                                                        |
| 578 | + 'callback' => 'message_template_shortcodes_help_tab'  | 
                                                        |
| 579 | + ),  | 
                                                        |
| 580 | + 'message_preview_help_tab' => array(  | 
                                                        |
| 581 | +						'title'    => __('Message Preview', 'event_espresso'), | 
                                                        |
| 582 | + 'filename' => 'messages_preview'  | 
                                                        |
| 583 | + ),  | 
                                                        |
| 584 | + 'messages_overview_other_help_tab' => array(  | 
                                                        |
| 585 | +						'title'    => __('Messages Other', 'event_espresso'), | 
                                                        |
| 586 | + 'filename' => 'messages_overview_other',  | 
                                                        |
| 587 | + ),  | 
                                                        |
| 588 | + ),  | 
                                                        |
| 589 | + 'require_nonce' => false  | 
                                                        |
| 590 | + ),  | 
                                                        |
| 591 | + 'display_preview_message' => array(  | 
                                                        |
| 592 | + 'nav' => array(  | 
                                                        |
| 593 | +					'label'      => __('Message Preview', 'event_espresso'), | 
                                                        |
| 594 | + 'order' => 5,  | 
                                                        |
| 595 | + 'url' => '',  | 
                                                        |
| 596 | + 'persistent' => false  | 
                                                        |
| 597 | + ),  | 
                                                        |
| 598 | + 'help_tabs' => array(  | 
                                                        |
| 599 | + 'preview_message' => array(  | 
                                                        |
| 600 | +						'title'    => __('About Previews', 'event_espresso'), | 
                                                        |
| 601 | + 'callback' => 'preview_message_help_tab'  | 
                                                        |
| 602 | + )  | 
                                                        |
| 603 | + ),  | 
                                                        |
| 604 | + 'require_nonce' => false  | 
                                                        |
| 605 | + ),  | 
                                                        |
| 606 | + 'settings' => array(  | 
                                                        |
| 607 | + 'nav' => array(  | 
                                                        |
| 608 | +					'label' => __('Settings', 'event_espresso'), | 
                                                        |
| 609 | + 'order' => 40  | 
                                                        |
| 610 | + ),  | 
                                                        |
| 611 | +				'metaboxes'     => array('_messages_settings_metaboxes'), | 
                                                        |
| 612 | + 'help_tabs' => array(  | 
                                                        |
| 613 | + 'messages_settings_help_tab' => array(  | 
                                                        |
| 614 | +						'title'    => __('Messages Settings', 'event_espresso'), | 
                                                        |
| 615 | + 'filename' => 'messages_settings'  | 
                                                        |
| 616 | + ),  | 
                                                        |
| 617 | + 'messages_settings_message_types_help_tab' => array(  | 
                                                        |
| 618 | +						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'), | 
                                                        |
| 619 | + 'filename' => 'messages_settings_message_types'  | 
                                                        |
| 620 | + ),  | 
                                                        |
| 621 | + 'messages_settings_messengers_help_tab' => array(  | 
                                                        |
| 622 | +						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'), | 
                                                        |
| 623 | + 'filename' => 'messages_settings_messengers'  | 
                                                        |
| 624 | + ),  | 
                                                        |
| 625 | + ),  | 
                                                        |
| 626 | +				'help_tour'     => array('Messages_Settings_Help_Tour'), | 
                                                        |
| 627 | + 'require_nonce' => false  | 
                                                        |
| 628 | + )  | 
                                                        |
| 629 | + );  | 
                                                        |
| 630 | + }  | 
                                                        |
| 631 | +  | 
                                                        |
| 632 | +  | 
                                                        |
| 633 | + protected function _add_screen_options()  | 
                                                        |
| 634 | +	{ | 
                                                        |
| 635 | + //todo  | 
                                                        |
| 636 | + }  | 
                                                        |
| 637 | +  | 
                                                        |
| 638 | +  | 
                                                        |
| 639 | + protected function _add_screen_options_global_mtps()  | 
                                                        |
| 640 | +	{ | 
                                                        |
| 641 | + /**  | 
                                                        |
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options  | 
                                                        |
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots.  | 
                                                        |
| 644 | + */  | 
                                                        |
| 645 | + $page_title = $this->_admin_page_title;  | 
                                                        |
| 646 | +		$this->_admin_page_title = __('Global Message Templates', 'event_espresso'); | 
                                                        |
| 647 | + $this->_per_page_screen_option();  | 
                                                        |
| 648 | + $this->_admin_page_title = $page_title;  | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | +  | 
                                                        |
| 651 | +  | 
                                                        |
| 652 | + protected function _add_screen_options_default()  | 
                                                        |
| 653 | +	{ | 
                                                        |
| 654 | +		$this->_admin_page_title = __('Message Activity', 'event_espresso'); | 
                                                        |
| 655 | + $this->_per_page_screen_option();  | 
                                                        |
| 656 | + }  | 
                                                        |
| 657 | +  | 
                                                        |
| 658 | +  | 
                                                        |
| 659 | + //none of the below group are currently used for Messages  | 
                                                        |
| 660 | + protected function _add_feature_pointers()  | 
                                                        |
| 661 | +	{ | 
                                                        |
| 662 | + }  | 
                                                        |
| 663 | +  | 
                                                        |
| 664 | + public function admin_init()  | 
                                                        |
| 665 | +	{ | 
                                                        |
| 666 | + }  | 
                                                        |
| 667 | +  | 
                                                        |
| 668 | + public function admin_notices()  | 
                                                        |
| 669 | +	{ | 
                                                        |
| 670 | + }  | 
                                                        |
| 671 | +  | 
                                                        |
| 672 | + public function admin_footer_scripts()  | 
                                                        |
| 673 | +	{ | 
                                                        |
| 674 | + }  | 
                                                        |
| 675 | +  | 
                                                        |
| 676 | +  | 
                                                        |
| 677 | + public function messages_help_tab()  | 
                                                        |
| 678 | +	{ | 
                                                        |
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 680 | + }  | 
                                                        |
| 681 | +  | 
                                                        |
| 682 | +  | 
                                                        |
| 683 | + public function messengers_help_tab()  | 
                                                        |
| 684 | +	{ | 
                                                        |
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 686 | + }  | 
                                                        |
| 687 | +  | 
                                                        |
| 688 | +  | 
                                                        |
| 689 | + public function message_types_help_tab()  | 
                                                        |
| 690 | +	{ | 
                                                        |
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 692 | + }  | 
                                                        |
| 693 | +  | 
                                                        |
| 694 | +  | 
                                                        |
| 695 | + public function messages_overview_help_tab()  | 
                                                        |
| 696 | +	{ | 
                                                        |
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 698 | + }  | 
                                                        |
| 699 | +  | 
                                                        |
| 700 | +  | 
                                                        |
| 701 | + public function message_templates_help_tab()  | 
                                                        |
| 702 | +	{ | 
                                                        |
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 704 | + }  | 
                                                        |
| 705 | +  | 
                                                        |
| 706 | +  | 
                                                        |
| 707 | + public function edit_message_template_help_tab()  | 
                                                        |
| 708 | +	{ | 
                                                        |
| 709 | +		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', | 
                                                        |
| 710 | + 'event_espresso') . '" />';  | 
                                                        |
| 711 | +		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', | 
                                                        |
| 712 | + 'event_espresso') . '" />';  | 
                                                        |
| 713 | +		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', | 
                                                        |
| 714 | + 'event_espresso') . '" />';  | 
                                                        |
| 715 | +		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', | 
                                                        |
| 716 | + 'event_espresso') . '" />';  | 
                                                        |
| 717 | +		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', | 
                                                        |
| 718 | + 'event_espresso') . '" />';  | 
                                                        |
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 720 | + $args);  | 
                                                        |
| 721 | + }  | 
                                                        |
| 722 | +  | 
                                                        |
| 723 | +  | 
                                                        |
| 724 | + public function message_template_shortcodes_help_tab()  | 
                                                        |
| 725 | +	{ | 
                                                        |
| 726 | + $this->_set_shortcodes();  | 
                                                        |
| 727 | + $args['shortcodes'] = $this->_shortcodes;  | 
                                                        |
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 729 | + $args);  | 
                                                        |
| 730 | + }  | 
                                                        |
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab()  | 
                                                        |
| 734 | -    { | 
                                                        |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 736 | - }  | 
                                                        |
| 733 | + public function preview_message_help_tab()  | 
                                                        |
| 734 | +	{ | 
                                                        |
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 736 | + }  | 
                                                        |
| 737 | 737 | |
| 738 | -  | 
                                                        |
| 739 | - public function settings_help_tab()  | 
                                                        |
| 740 | -    { | 
                                                        |
| 741 | -        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', | 
                                                        |
| 742 | - 'event_espresso') . '" />';  | 
                                                        |
| 743 | -        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', | 
                                                        |
| 744 | - 'event_espresso') . '" />';  | 
                                                        |
| 745 | - $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        |
| 746 | - $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 748 | - }  | 
                                                        |
| 738 | +  | 
                                                        |
| 739 | + public function settings_help_tab()  | 
                                                        |
| 740 | +	{ | 
                                                        |
| 741 | +		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', | 
                                                        |
| 742 | + 'event_espresso') . '" />';  | 
                                                        |
| 743 | +		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', | 
                                                        |
| 744 | + 'event_espresso') . '" />';  | 
                                                        |
| 745 | + $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        |
| 746 | + $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        |
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 748 | + }  | 
                                                        |
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles()  | 
                                                        |
| 752 | -    { | 
                                                        |
| 753 | -        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 754 | -        wp_enqueue_style('espresso_ee_msg'); | 
                                                        |
| 751 | + public function load_scripts_styles()  | 
                                                        |
| 752 | +	{ | 
                                                        |
| 753 | +		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 754 | +		wp_enqueue_style('espresso_ee_msg'); | 
                                                        |
| 755 | 755 | |
| 756 | -        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', | 
                                                        |
| 757 | -            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 758 | -        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', | 
                                                        |
| 759 | -            array('ee-dialog'), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 760 | - }  | 
                                                        |
| 756 | +		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', | 
                                                        |
| 757 | +			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 758 | +		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', | 
                                                        |
| 759 | +			array('ee-dialog'), EVENT_ESPRESSO_VERSION); | 
                                                        |
| 760 | + }  | 
                                                        |
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default()  | 
                                                        |
| 764 | -    { | 
                                                        |
| 765 | -        wp_enqueue_script('ee-msg-list-table-js'); | 
                                                        |
| 766 | - }  | 
                                                        |
| 763 | + public function load_scripts_styles_default()  | 
                                                        |
| 764 | +	{ | 
                                                        |
| 765 | +		wp_enqueue_script('ee-msg-list-table-js'); | 
                                                        |
| 766 | + }  | 
                                                        |
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css)  | 
                                                        |
| 770 | -    { | 
                                                        |
| 771 | - //if we're on the edit_message_template route  | 
                                                        |
| 772 | -        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | 
                                                        |
| 773 | - $message_type_name = $this->_active_message_type_name;  | 
                                                        |
| 769 | + public function wp_editor_css($mce_css)  | 
                                                        |
| 770 | +	{ | 
                                                        |
| 771 | + //if we're on the edit_message_template route  | 
                                                        |
| 772 | +		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | 
                                                        |
| 773 | + $message_type_name = $this->_active_message_type_name;  | 
                                                        |
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css  | 
                                                        |
| 776 | - //we need to get the css file location from the active messenger  | 
                                                        |
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,  | 
                                                        |
| 778 | - 'wpeditor', $this->_variation);  | 
                                                        |
| 779 | - }  | 
                                                        |
| 775 | + //we're going to REPLACE the existing mce css  | 
                                                        |
| 776 | + //we need to get the css file location from the active messenger  | 
                                                        |
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,  | 
                                                        |
| 778 | + 'wpeditor', $this->_variation);  | 
                                                        |
| 779 | + }  | 
                                                        |
| 780 | 780 | |
| 781 | - return $mce_css;  | 
                                                        |
| 782 | - }  | 
                                                        |
| 781 | + return $mce_css;  | 
                                                        |
| 782 | + }  | 
                                                        |
| 783 | 783 | |
| 784 | 784 | |
| 785 | - public function load_scripts_styles_edit_message_template()  | 
                                                        |
| 786 | -    { | 
                                                        |
| 785 | + public function load_scripts_styles_edit_message_template()  | 
                                                        |
| 786 | +	{ | 
                                                        |
| 787 | 787 | |
| 788 | - $this->_set_shortcodes();  | 
                                                        |
| 788 | + $this->_set_shortcodes();  | 
                                                        |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 791 | -            __('Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.', | 
                                                        |
| 792 | - 'event_espresso'),  | 
                                                        |
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'],  | 
                                                        |
| 794 | - $this->_message_template_group->message_type_obj()->label['singular']  | 
                                                        |
| 795 | - );  | 
                                                        |
| 796 | -        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?', | 
                                                        |
| 797 | - 'event_espresso');  | 
                                                        |
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 791 | +			__('Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.', | 
                                                        |
| 792 | + 'event_espresso'),  | 
                                                        |
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'],  | 
                                                        |
| 794 | + $this->_message_template_group->message_type_obj()->label['singular']  | 
                                                        |
| 795 | + );  | 
                                                        |
| 796 | +		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?', | 
                                                        |
| 797 | + 'event_espresso');  | 
                                                        |
| 798 | 798 | |
| 799 | -        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), | 
                                                        |
| 800 | - EVENT_ESPRESSO_VERSION);  | 
                                                        |
| 799 | +		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), | 
                                                        |
| 800 | + EVENT_ESPRESSO_VERSION);  | 
                                                        |
| 801 | 801 | |
| 802 | -        wp_enqueue_script('ee_admin_js'); | 
                                                        |
| 803 | -        wp_enqueue_script('ee_msgs_edit_js'); | 
                                                        |
| 802 | +		wp_enqueue_script('ee_admin_js'); | 
                                                        |
| 803 | +		wp_enqueue_script('ee_msgs_edit_js'); | 
                                                        |
| 804 | 804 | |
| 805 | - //add in special css for tiny_mce  | 
                                                        |
| 806 | -        add_filter('mce_css', array($this, 'wp_editor_css')); | 
                                                        |
| 807 | - }  | 
                                                        |
| 805 | + //add in special css for tiny_mce  | 
                                                        |
| 806 | +		add_filter('mce_css', array($this, 'wp_editor_css')); | 
                                                        |
| 807 | + }  | 
                                                        |
| 808 | 808 | |
| 809 | 809 | |
| 810 | - public function load_scripts_styles_display_preview_message()  | 
                                                        |
| 811 | -    { | 
                                                        |
| 810 | + public function load_scripts_styles_display_preview_message()  | 
                                                        |
| 811 | +	{ | 
                                                        |
| 812 | 812 | |
| 813 | - $this->_set_message_template_group();  | 
                                                        |
| 813 | + $this->_set_message_template_group();  | 
                                                        |
| 814 | 814 | |
| 815 | -        if (isset($this->_req_data['messenger'])) { | 
                                                        |
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 817 | - }  | 
                                                        |
| 815 | +		if (isset($this->_req_data['messenger'])) { | 
                                                        |
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 817 | + }  | 
                                                        |
| 818 | 818 | |
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';  | 
                                                        |
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';  | 
                                                        |
| 820 | 820 | |
| 821 | 821 | |
| 822 | -        wp_enqueue_style('espresso_preview_css', | 
                                                        |
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',  | 
                                                        |
| 824 | - $this->_variation));  | 
                                                        |
| 825 | - }  | 
                                                        |
| 822 | +		wp_enqueue_style('espresso_preview_css', | 
                                                        |
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',  | 
                                                        |
| 824 | + $this->_variation));  | 
                                                        |
| 825 | + }  | 
                                                        |
| 826 | 826 | |
| 827 | 827 | |
| 828 | - public function load_scripts_styles_settings()  | 
                                                        |
| 829 | -    { | 
                                                        |
| 830 | -        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), | 
                                                        |
| 831 | - EVENT_ESPRESSO_VERSION);  | 
                                                        |
| 832 | -        wp_enqueue_style('ee-text-links'); | 
                                                        |
| 833 | -        wp_enqueue_style('ee-message-settings'); | 
                                                        |
| 828 | + public function load_scripts_styles_settings()  | 
                                                        |
| 829 | +	{ | 
                                                        |
| 830 | +		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), | 
                                                        |
| 831 | + EVENT_ESPRESSO_VERSION);  | 
                                                        |
| 832 | +		wp_enqueue_style('ee-text-links'); | 
                                                        |
| 833 | +		wp_enqueue_style('ee-message-settings'); | 
                                                        |
| 834 | 834 | |
| 835 | -        wp_enqueue_script('ee-messages-settings'); | 
                                                        |
| 836 | - }  | 
                                                        |
| 835 | +		wp_enqueue_script('ee-messages-settings'); | 
                                                        |
| 836 | + }  | 
                                                        |
| 837 | 837 | |
| 838 | 838 | |
| 839 | - /**  | 
                                                        |
| 840 | - * set views array for List Table  | 
                                                        |
| 841 | - */  | 
                                                        |
| 842 | - public function _set_list_table_views_global_mtps()  | 
                                                        |
| 843 | -    { | 
                                                        |
| 844 | - $this->_views = array(  | 
                                                        |
| 845 | - 'in_use' => array(  | 
                                                        |
| 846 | - 'slug' => 'in_use',  | 
                                                        |
| 847 | -                'label'       => __('In Use', 'event_espresso'), | 
                                                        |
| 848 | - 'count' => 0,  | 
                                                        |
| 849 | - )  | 
                                                        |
| 850 | - );  | 
                                                        |
| 851 | - }  | 
                                                        |
| 839 | + /**  | 
                                                        |
| 840 | + * set views array for List Table  | 
                                                        |
| 841 | + */  | 
                                                        |
| 842 | + public function _set_list_table_views_global_mtps()  | 
                                                        |
| 843 | +	{ | 
                                                        |
| 844 | + $this->_views = array(  | 
                                                        |
| 845 | + 'in_use' => array(  | 
                                                        |
| 846 | + 'slug' => 'in_use',  | 
                                                        |
| 847 | +				'label'       => __('In Use', 'event_espresso'), | 
                                                        |
| 848 | + 'count' => 0,  | 
                                                        |
| 849 | + )  | 
                                                        |
| 850 | + );  | 
                                                        |
| 851 | + }  | 
                                                        |
| 852 | 852 | |
| 853 | 853 | |
| 854 | - /**  | 
                                                        |
| 855 | - * Set views array for the Custom Template List Table  | 
                                                        |
| 856 | - */  | 
                                                        |
| 857 | - public function _set_list_table_views_custom_mtps()  | 
                                                        |
| 858 | -    { | 
                                                        |
| 859 | - $this->_set_list_table_views_global_mtps();  | 
                                                        |
| 860 | - $this->_views['in_use']['bulk_action'] = array(  | 
                                                        |
| 861 | -                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') | 
                                                        |
| 862 | - );  | 
                                                        |
| 863 | - }  | 
                                                        |
| 864 | -  | 
                                                        |
| 865 | -  | 
                                                        |
| 866 | - /**  | 
                                                        |
| 867 | - * set views array for message queue list table  | 
                                                        |
| 868 | - */  | 
                                                        |
| 869 | - public function _set_list_table_views_default()  | 
                                                        |
| 870 | -    { | 
                                                        |
| 871 | -        EE_Registry::instance()->load_helper('Template'); | 
                                                        |
| 872 | -  | 
                                                        |
| 873 | -        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', | 
                                                        |
| 874 | - 'message_list_table_bulk_actions')  | 
                                                        |
| 875 | - ? array(  | 
                                                        |
| 876 | -                'generate_now'          => __('Generate Now', 'event_espresso'), | 
                                                        |
| 877 | -                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), | 
                                                        |
| 878 | -                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'), | 
                                                        |
| 879 | -                'send_now'              => __('Send Now', 'event_espresso') | 
                                                        |
| 880 | - )  | 
                                                        |
| 881 | - : array();  | 
                                                        |
| 882 | -  | 
                                                        |
| 883 | -        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', | 
                                                        |
| 884 | - 'message_list_table_bulk_actions')  | 
                                                        |
| 885 | -            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) | 
                                                        |
| 886 | - : array();  | 
                                                        |
| 887 | -  | 
                                                        |
| 888 | -  | 
                                                        |
| 889 | - $this->_views = array(  | 
                                                        |
| 890 | - 'all' => array(  | 
                                                        |
| 891 | - 'slug' => 'all',  | 
                                                        |
| 892 | -                'label'       => __('All', 'event_espresso'), | 
                                                        |
| 893 | - 'count' => 0,  | 
                                                        |
| 894 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)  | 
                                                        |
| 895 | - )  | 
                                                        |
| 896 | - );  | 
                                                        |
| 897 | -  | 
                                                        |
| 898 | -  | 
                                                        |
| 899 | -        foreach (EEM_Message::instance()->all_statuses() as $status) { | 
                                                        |
| 900 | -            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | 
                                                        |
| 901 | - continue;  | 
                                                        |
| 902 | - }  | 
                                                        |
| 903 | - $status_bulk_actions = $common_bulk_actions;  | 
                                                        |
| 904 | - //unset bulk actions not applying to status  | 
                                                        |
| 905 | -            if (! empty($status_bulk_actions)) { | 
                                                        |
| 906 | -                switch ($status) { | 
                                                        |
| 907 | - case EEM_Message::status_idle:  | 
                                                        |
| 908 | - case EEM_Message::status_resend:  | 
                                                        |
| 909 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];  | 
                                                        |
| 910 | - break;  | 
                                                        |
| 854 | + /**  | 
                                                        |
| 855 | + * Set views array for the Custom Template List Table  | 
                                                        |
| 856 | + */  | 
                                                        |
| 857 | + public function _set_list_table_views_custom_mtps()  | 
                                                        |
| 858 | +	{ | 
                                                        |
| 859 | + $this->_set_list_table_views_global_mtps();  | 
                                                        |
| 860 | + $this->_views['in_use']['bulk_action'] = array(  | 
                                                        |
| 861 | +				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') | 
                                                        |
| 862 | + );  | 
                                                        |
| 863 | + }  | 
                                                        |
| 864 | +  | 
                                                        |
| 865 | +  | 
                                                        |
| 866 | + /**  | 
                                                        |
| 867 | + * set views array for message queue list table  | 
                                                        |
| 868 | + */  | 
                                                        |
| 869 | + public function _set_list_table_views_default()  | 
                                                        |
| 870 | +	{ | 
                                                        |
| 871 | +		EE_Registry::instance()->load_helper('Template'); | 
                                                        |
| 872 | +  | 
                                                        |
| 873 | +		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', | 
                                                        |
| 874 | + 'message_list_table_bulk_actions')  | 
                                                        |
| 875 | + ? array(  | 
                                                        |
| 876 | +				'generate_now'          => __('Generate Now', 'event_espresso'), | 
                                                        |
| 877 | +				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), | 
                                                        |
| 878 | +				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'), | 
                                                        |
| 879 | +				'send_now'              => __('Send Now', 'event_espresso') | 
                                                        |
| 880 | + )  | 
                                                        |
| 881 | + : array();  | 
                                                        |
| 882 | +  | 
                                                        |
| 883 | +		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', | 
                                                        |
| 884 | + 'message_list_table_bulk_actions')  | 
                                                        |
| 885 | +			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) | 
                                                        |
| 886 | + : array();  | 
                                                        |
| 887 | +  | 
                                                        |
| 888 | +  | 
                                                        |
| 889 | + $this->_views = array(  | 
                                                        |
| 890 | + 'all' => array(  | 
                                                        |
| 891 | + 'slug' => 'all',  | 
                                                        |
| 892 | +				'label'       => __('All', 'event_espresso'), | 
                                                        |
| 893 | + 'count' => 0,  | 
                                                        |
| 894 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)  | 
                                                        |
| 895 | + )  | 
                                                        |
| 896 | + );  | 
                                                        |
| 897 | +  | 
                                                        |
| 898 | +  | 
                                                        |
| 899 | +		foreach (EEM_Message::instance()->all_statuses() as $status) { | 
                                                        |
| 900 | +			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | 
                                                        |
| 901 | + continue;  | 
                                                        |
| 902 | + }  | 
                                                        |
| 903 | + $status_bulk_actions = $common_bulk_actions;  | 
                                                        |
| 904 | + //unset bulk actions not applying to status  | 
                                                        |
| 905 | +			if (! empty($status_bulk_actions)) { | 
                                                        |
| 906 | +				switch ($status) { | 
                                                        |
| 907 | + case EEM_Message::status_idle:  | 
                                                        |
| 908 | + case EEM_Message::status_resend:  | 
                                                        |
| 909 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];  | 
                                                        |
| 910 | + break;  | 
                                                        |
| 911 | 911 | |
| 912 | - case EEM_Message::status_failed:  | 
                                                        |
| 913 | - case EEM_Message::status_debug_only:  | 
                                                        |
| 914 | - case EEM_Message::status_messenger_executing:  | 
                                                        |
| 915 | - $status_bulk_actions = array();  | 
                                                        |
| 916 | - break;  | 
                                                        |
| 912 | + case EEM_Message::status_failed:  | 
                                                        |
| 913 | + case EEM_Message::status_debug_only:  | 
                                                        |
| 914 | + case EEM_Message::status_messenger_executing:  | 
                                                        |
| 915 | + $status_bulk_actions = array();  | 
                                                        |
| 916 | + break;  | 
                                                        |
| 917 | 917 | |
| 918 | - case EEM_Message::status_incomplete:  | 
                                                        |
| 919 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);  | 
                                                        |
| 920 | - break;  | 
                                                        |
| 918 | + case EEM_Message::status_incomplete:  | 
                                                        |
| 919 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);  | 
                                                        |
| 920 | + break;  | 
                                                        |
| 921 | 921 | |
| 922 | - case EEM_Message::status_retry:  | 
                                                        |
| 923 | - case EEM_Message::status_sent:  | 
                                                        |
| 924 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);  | 
                                                        |
| 925 | - break;  | 
                                                        |
| 926 | - }  | 
                                                        |
| 927 | - }  | 
                                                        |
| 922 | + case EEM_Message::status_retry:  | 
                                                        |
| 923 | + case EEM_Message::status_sent:  | 
                                                        |
| 924 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);  | 
                                                        |
| 925 | + break;  | 
                                                        |
| 926 | + }  | 
                                                        |
| 927 | + }  | 
                                                        |
| 928 | 928 | |
| 929 | - //skip adding messenger executing status to views because it will be included with the Failed view.  | 
                                                        |
| 930 | -            if ( $status === EEM_Message::status_messenger_executing ) { | 
                                                        |
| 931 | - continue;  | 
                                                        |
| 932 | - }  | 
                                                        |
| 929 | + //skip adding messenger executing status to views because it will be included with the Failed view.  | 
                                                        |
| 930 | +			if ( $status === EEM_Message::status_messenger_executing ) { | 
                                                        |
| 931 | + continue;  | 
                                                        |
| 932 | + }  | 
                                                        |
| 933 | 933 | |
| 934 | - $this->_views[strtolower($status)] = array(  | 
                                                        |
| 935 | - 'slug' => strtolower($status),  | 
                                                        |
| 936 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'),  | 
                                                        |
| 937 | - 'count' => 0,  | 
                                                        |
| 938 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)  | 
                                                        |
| 939 | - );  | 
                                                        |
| 940 | - }  | 
                                                        |
| 941 | - }  | 
                                                        |
| 942 | -  | 
                                                        |
| 943 | -  | 
                                                        |
| 944 | - protected function _ee_default_messages_overview_list_table()  | 
                                                        |
| 945 | -    { | 
                                                        |
| 946 | -        $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); | 
                                                        |
| 947 | - $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 948 | - }  | 
                                                        |
| 949 | -  | 
                                                        |
| 950 | -  | 
                                                        |
| 951 | - protected function _message_queue_list_table()  | 
                                                        |
| 952 | -    { | 
                                                        |
| 953 | -        $this->_search_btn_label                   = __('Message Activity', 'event_espresso'); | 
                                                        |
| 954 | - $this->_template_args['per_column'] = 6;  | 
                                                        |
| 955 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());  | 
                                                        |
| 956 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';  | 
                                                        |
| 957 | - $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 958 | - }  | 
                                                        |
| 959 | -  | 
                                                        |
| 960 | -  | 
                                                        |
| 961 | - protected function _message_legend_items()  | 
                                                        |
| 962 | -    { | 
                                                        |
| 963 | -  | 
                                                        |
| 964 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons();  | 
                                                        |
| 965 | - $action_items = array();  | 
                                                        |
| 966 | -  | 
                                                        |
| 967 | -        foreach ($action_css_classes as $action_item => $action_details) { | 
                                                        |
| 968 | -            if ($action_item === 'see_notifications_for') { | 
                                                        |
| 969 | - continue;  | 
                                                        |
| 970 | - }  | 
                                                        |
| 971 | - $action_items[$action_item] = array(  | 
                                                        |
| 972 | - 'class' => $action_details['css_class'],  | 
                                                        |
| 973 | - 'desc' => $action_details['label']  | 
                                                        |
| 974 | - );  | 
                                                        |
| 975 | - }  | 
                                                        |
| 976 | -  | 
                                                        |
| 977 | - /** @type array $status_items status legend setup */  | 
                                                        |
| 978 | - $status_items = array(  | 
                                                        |
| 979 | - 'sent_status' => array(  | 
                                                        |
| 980 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,  | 
                                                        |
| 981 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')  | 
                                                        |
| 982 | - ),  | 
                                                        |
| 983 | - 'idle_status' => array(  | 
                                                        |
| 984 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,  | 
                                                        |
| 985 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')  | 
                                                        |
| 986 | - ),  | 
                                                        |
| 987 | - 'failed_status' => array(  | 
                                                        |
| 988 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,  | 
                                                        |
| 989 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')  | 
                                                        |
| 990 | - ),  | 
                                                        |
| 991 | - 'messenger_executing_status' => array(  | 
                                                        |
| 992 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 993 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')  | 
                                                        |
| 994 | - ),  | 
                                                        |
| 995 | - 'resend_status' => array(  | 
                                                        |
| 996 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,  | 
                                                        |
| 997 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')  | 
                                                        |
| 998 | - ),  | 
                                                        |
| 999 | - 'incomplete_status' => array(  | 
                                                        |
| 1000 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,  | 
                                                        |
| 1001 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')  | 
                                                        |
| 1002 | - ),  | 
                                                        |
| 1003 | - 'retry_status' => array(  | 
                                                        |
| 1004 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,  | 
                                                        |
| 1005 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')  | 
                                                        |
| 1006 | - )  | 
                                                        |
| 1007 | - );  | 
                                                        |
| 1008 | -        if (EEM_Message::debug()) { | 
                                                        |
| 1009 | - $status_items['debug_only_status'] = array(  | 
                                                        |
| 1010 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,  | 
                                                        |
| 1011 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')  | 
                                                        |
| 1012 | - );  | 
                                                        |
| 1013 | - }  | 
                                                        |
| 1014 | -  | 
                                                        |
| 1015 | - return array_merge($action_items, $status_items);  | 
                                                        |
| 1016 | - }  | 
                                                        |
| 1017 | -  | 
                                                        |
| 1018 | -  | 
                                                        |
| 1019 | - protected function _custom_mtps_preview()  | 
                                                        |
| 1020 | -    { | 
                                                        |
| 1021 | -        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        |
| 1022 | -        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', | 
                                                        |
| 1023 | - 'event_espresso') . '" />';  | 
                                                        |
| 1024 | -        $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | 
                                                        |
| 1025 | - 'event_espresso') . '</strong>';  | 
                                                        |
| 1026 | -        $this->display_admin_caf_preview_page('custom_message_types', false); | 
                                                        |
| 1027 | - }  | 
                                                        |
| 1028 | -  | 
                                                        |
| 1029 | -  | 
                                                        |
| 1030 | - /**  | 
                                                        |
| 1031 | - * get_message_templates  | 
                                                        |
| 1032 | - * This gets all the message templates for listing on the overview list.  | 
                                                        |
| 1033 | - *  | 
                                                        |
| 1034 | - * @access public  | 
                                                        |
| 1035 | - *  | 
                                                        |
| 1036 | - * @param int $perpage the amount of templates groups to show per page  | 
                                                        |
| 1037 | - * @param string $type the current _view we're getting templates for  | 
                                                        |
| 1038 | - * @param bool $count return count?  | 
                                                        |
| 1039 | - * @param bool $all disregard any paging info (get all data);  | 
                                                        |
| 1040 | - * @param bool $global whether to return just global (true) or custom templates (false)  | 
                                                        |
| 1041 | - *  | 
                                                        |
| 1042 | - * @return array  | 
                                                        |
| 1043 | - */  | 
                                                        |
| 1044 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)  | 
                                                        |
| 1045 | -    { | 
                                                        |
| 1046 | -  | 
                                                        |
| 1047 | - $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 1048 | -  | 
                                                        |
| 1049 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];  | 
                                                        |
| 1050 | - $orderby = $this->_req_data['orderby'];  | 
                                                        |
| 1051 | -  | 
                                                        |
| 1052 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';  | 
                                                        |
| 1053 | -  | 
                                                        |
| 1054 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;  | 
                                                        |
| 1055 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;  | 
                                                        |
| 1056 | -  | 
                                                        |
| 1057 | - $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1058 | - $limit = $all ? null : array($offset, $per_page);  | 
                                                        |
| 1059 | -  | 
                                                        |
| 1060 | -  | 
                                                        |
| 1061 | - //options will match what is in the _views array property  | 
                                                        |
| 1062 | -        switch ($type) { | 
                                                        |
| 934 | + $this->_views[strtolower($status)] = array(  | 
                                                        |
| 935 | + 'slug' => strtolower($status),  | 
                                                        |
| 936 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'),  | 
                                                        |
| 937 | + 'count' => 0,  | 
                                                        |
| 938 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)  | 
                                                        |
| 939 | + );  | 
                                                        |
| 940 | + }  | 
                                                        |
| 941 | + }  | 
                                                        |
| 942 | +  | 
                                                        |
| 943 | +  | 
                                                        |
| 944 | + protected function _ee_default_messages_overview_list_table()  | 
                                                        |
| 945 | +	{ | 
                                                        |
| 946 | +		$this->_admin_page_title = __('Default Message Templates', 'event_espresso'); | 
                                                        |
| 947 | + $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 948 | + }  | 
                                                        |
| 949 | +  | 
                                                        |
| 950 | +  | 
                                                        |
| 951 | + protected function _message_queue_list_table()  | 
                                                        |
| 952 | +	{ | 
                                                        |
| 953 | +		$this->_search_btn_label                   = __('Message Activity', 'event_espresso'); | 
                                                        |
| 954 | + $this->_template_args['per_column'] = 6;  | 
                                                        |
| 955 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());  | 
                                                        |
| 956 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';  | 
                                                        |
| 957 | + $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 958 | + }  | 
                                                        |
| 959 | +  | 
                                                        |
| 960 | +  | 
                                                        |
| 961 | + protected function _message_legend_items()  | 
                                                        |
| 962 | +	{ | 
                                                        |
| 963 | +  | 
                                                        |
| 964 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons();  | 
                                                        |
| 965 | + $action_items = array();  | 
                                                        |
| 966 | +  | 
                                                        |
| 967 | +		foreach ($action_css_classes as $action_item => $action_details) { | 
                                                        |
| 968 | +			if ($action_item === 'see_notifications_for') { | 
                                                        |
| 969 | + continue;  | 
                                                        |
| 970 | + }  | 
                                                        |
| 971 | + $action_items[$action_item] = array(  | 
                                                        |
| 972 | + 'class' => $action_details['css_class'],  | 
                                                        |
| 973 | + 'desc' => $action_details['label']  | 
                                                        |
| 974 | + );  | 
                                                        |
| 975 | + }  | 
                                                        |
| 976 | +  | 
                                                        |
| 977 | + /** @type array $status_items status legend setup */  | 
                                                        |
| 978 | + $status_items = array(  | 
                                                        |
| 979 | + 'sent_status' => array(  | 
                                                        |
| 980 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,  | 
                                                        |
| 981 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')  | 
                                                        |
| 982 | + ),  | 
                                                        |
| 983 | + 'idle_status' => array(  | 
                                                        |
| 984 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,  | 
                                                        |
| 985 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')  | 
                                                        |
| 986 | + ),  | 
                                                        |
| 987 | + 'failed_status' => array(  | 
                                                        |
| 988 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,  | 
                                                        |
| 989 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')  | 
                                                        |
| 990 | + ),  | 
                                                        |
| 991 | + 'messenger_executing_status' => array(  | 
                                                        |
| 992 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 993 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')  | 
                                                        |
| 994 | + ),  | 
                                                        |
| 995 | + 'resend_status' => array(  | 
                                                        |
| 996 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,  | 
                                                        |
| 997 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')  | 
                                                        |
| 998 | + ),  | 
                                                        |
| 999 | + 'incomplete_status' => array(  | 
                                                        |
| 1000 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,  | 
                                                        |
| 1001 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')  | 
                                                        |
| 1002 | + ),  | 
                                                        |
| 1003 | + 'retry_status' => array(  | 
                                                        |
| 1004 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,  | 
                                                        |
| 1005 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')  | 
                                                        |
| 1006 | + )  | 
                                                        |
| 1007 | + );  | 
                                                        |
| 1008 | +		if (EEM_Message::debug()) { | 
                                                        |
| 1009 | + $status_items['debug_only_status'] = array(  | 
                                                        |
| 1010 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,  | 
                                                        |
| 1011 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')  | 
                                                        |
| 1012 | + );  | 
                                                        |
| 1013 | + }  | 
                                                        |
| 1014 | +  | 
                                                        |
| 1015 | + return array_merge($action_items, $status_items);  | 
                                                        |
| 1016 | + }  | 
                                                        |
| 1017 | +  | 
                                                        |
| 1018 | +  | 
                                                        |
| 1019 | + protected function _custom_mtps_preview()  | 
                                                        |
| 1020 | +	{ | 
                                                        |
| 1021 | +		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        |
| 1022 | +		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', | 
                                                        |
| 1023 | + 'event_espresso') . '" />';  | 
                                                        |
| 1024 | +		$this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | 
                                                        |
| 1025 | + 'event_espresso') . '</strong>';  | 
                                                        |
| 1026 | +		$this->display_admin_caf_preview_page('custom_message_types', false); | 
                                                        |
| 1027 | + }  | 
                                                        |
| 1028 | +  | 
                                                        |
| 1029 | +  | 
                                                        |
| 1030 | + /**  | 
                                                        |
| 1031 | + * get_message_templates  | 
                                                        |
| 1032 | + * This gets all the message templates for listing on the overview list.  | 
                                                        |
| 1033 | + *  | 
                                                        |
| 1034 | + * @access public  | 
                                                        |
| 1035 | + *  | 
                                                        |
| 1036 | + * @param int $perpage the amount of templates groups to show per page  | 
                                                        |
| 1037 | + * @param string $type the current _view we're getting templates for  | 
                                                        |
| 1038 | + * @param bool $count return count?  | 
                                                        |
| 1039 | + * @param bool $all disregard any paging info (get all data);  | 
                                                        |
| 1040 | + * @param bool $global whether to return just global (true) or custom templates (false)  | 
                                                        |
| 1041 | + *  | 
                                                        |
| 1042 | + * @return array  | 
                                                        |
| 1043 | + */  | 
                                                        |
| 1044 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)  | 
                                                        |
| 1045 | +	{ | 
                                                        |
| 1046 | +  | 
                                                        |
| 1047 | + $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 1048 | +  | 
                                                        |
| 1049 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];  | 
                                                        |
| 1050 | + $orderby = $this->_req_data['orderby'];  | 
                                                        |
| 1051 | +  | 
                                                        |
| 1052 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';  | 
                                                        |
| 1053 | +  | 
                                                        |
| 1054 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;  | 
                                                        |
| 1055 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;  | 
                                                        |
| 1056 | +  | 
                                                        |
| 1057 | + $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1058 | + $limit = $all ? null : array($offset, $per_page);  | 
                                                        |
| 1059 | +  | 
                                                        |
| 1060 | +  | 
                                                        |
| 1061 | + //options will match what is in the _views array property  | 
                                                        |
| 1062 | +		switch ($type) { | 
                                                        |
| 1063 | 1063 | |
| 1064 | - case 'in_use':  | 
                                                        |
| 1065 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);  | 
                                                        |
| 1066 | - break;  | 
                                                        |
| 1064 | + case 'in_use':  | 
                                                        |
| 1065 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);  | 
                                                        |
| 1066 | + break;  | 
                                                        |
| 1067 | 1067 | |
| 1068 | - default:  | 
                                                        |
| 1069 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);  | 
                                                        |
| 1068 | + default:  | 
                                                        |
| 1069 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);  | 
                                                        |
| 1070 | 1070 | |
| 1071 | - }  | 
                                                        |
| 1072 | -  | 
                                                        |
| 1073 | - return $templates;  | 
                                                        |
| 1074 | - }  | 
                                                        |
| 1075 | -  | 
                                                        |
| 1076 | -  | 
                                                        |
| 1077 | - /**  | 
                                                        |
| 1078 | - * filters etc might need a list of installed message_types  | 
                                                        |
| 1079 | - * @return array an array of message type objects  | 
                                                        |
| 1080 | - */  | 
                                                        |
| 1081 | - public function get_installed_message_types()  | 
                                                        |
| 1082 | -    { | 
                                                        |
| 1083 | - $installed_message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 1084 | - $installed = array();  | 
                                                        |
| 1085 | -  | 
                                                        |
| 1086 | -        foreach ($installed_message_types as $message_type) { | 
                                                        |
| 1087 | - $installed[$message_type->name] = $message_type;  | 
                                                        |
| 1088 | - }  | 
                                                        |
| 1089 | -  | 
                                                        |
| 1090 | - return $installed;  | 
                                                        |
| 1091 | - }  | 
                                                        |
| 1092 | -  | 
                                                        |
| 1093 | -  | 
                                                        |
| 1094 | - /**  | 
                                                        |
| 1095 | - * _add_message_template  | 
                                                        |
| 1096 | - *  | 
                                                        |
| 1097 | - * This is used when creating a custom template. All Custom Templates start based off another template.  | 
                                                        |
| 1098 | - *  | 
                                                        |
| 1099 | - * @param string $message_type  | 
                                                        |
| 1100 | - * @param string $messenger  | 
                                                        |
| 1101 | - * @param string $GRP_ID  | 
                                                        |
| 1102 | - *  | 
                                                        |
| 1103 | - * @throws EE_error  | 
                                                        |
| 1104 | - */  | 
                                                        |
| 1105 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')  | 
                                                        |
| 1106 | -    { | 
                                                        |
| 1107 | - //set values override any request data  | 
                                                        |
| 1108 | - $message_type = ! empty($message_type) ? $message_type : '';  | 
                                                        |
| 1109 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;  | 
                                                        |
| 1110 | -  | 
                                                        |
| 1111 | - $messenger = ! empty($messenger) ? $messenger : '';  | 
                                                        |
| 1112 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;  | 
                                                        |
| 1113 | -  | 
                                                        |
| 1114 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';  | 
                                                        |
| 1115 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;  | 
                                                        |
| 1116 | -  | 
                                                        |
| 1117 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error  | 
                                                        |
| 1118 | -        if (empty($message_type) || empty($messenger)) { | 
                                                        |
| 1119 | -            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', | 
                                                        |
| 1120 | - 'event_espresso'));  | 
                                                        |
| 1121 | - }  | 
                                                        |
| 1122 | -  | 
                                                        |
| 1123 | - //we need the GRP_ID for the template being used as the base for the new template  | 
                                                        |
| 1124 | -        if (empty($GRP_ID)) { | 
                                                        |
| 1125 | -            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', | 
                                                        |
| 1126 | - 'event_espresso'));  | 
                                                        |
| 1127 | - }  | 
                                                        |
| 1128 | -  | 
                                                        |
| 1129 | - //let's just make sure the template gets generated!  | 
                                                        |
| 1130 | -  | 
                                                        |
| 1131 | - //we need to reassign some variables for what the insert is expecting  | 
                                                        |
| 1132 | - $this->_req_data['MTP_messenger'] = $messenger;  | 
                                                        |
| 1133 | - $this->_req_data['MTP_message_type'] = $message_type;  | 
                                                        |
| 1134 | - $this->_req_data['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1135 | - $this->_insert_or_update_message_template(true);  | 
                                                        |
| 1136 | - }  | 
                                                        |
| 1137 | -  | 
                                                        |
| 1138 | -  | 
                                                        |
| 1139 | - /**  | 
                                                        |
| 1140 | - * public wrapper for the _add_message_template method  | 
                                                        |
| 1141 | - *  | 
                                                        |
| 1142 | - * @param string $message_type message type slug  | 
                                                        |
| 1143 | - * @param string $messenger messenger slug  | 
                                                        |
| 1144 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based  | 
                                                        |
| 1145 | - * off of.  | 
                                                        |
| 1146 | - */  | 
                                                        |
| 1147 | - public function add_message_template($message_type, $messenger, $GRP_ID)  | 
                                                        |
| 1148 | -    { | 
                                                        |
| 1149 | - $this->_add_message_template($message_type, $messenger, $GRP_ID);  | 
                                                        |
| 1150 | - }  | 
                                                        |
| 1151 | -  | 
                                                        |
| 1152 | -  | 
                                                        |
| 1153 | - /**  | 
                                                        |
| 1154 | - * _edit_message_template  | 
                                                        |
| 1155 | - *  | 
                                                        |
| 1156 | - * @access protected  | 
                                                        |
| 1157 | - * @return void  | 
                                                        |
| 1158 | - */  | 
                                                        |
| 1159 | - protected function _edit_message_template()  | 
                                                        |
| 1160 | -    { | 
                                                        |
| 1161 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1162 | - $template_fields = '';  | 
                                                        |
| 1163 | - $sidebar_fields = '';  | 
                                                        |
| 1164 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.  | 
                                                        |
| 1165 | -        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); | 
                                                        |
| 1166 | -  | 
                                                        |
| 1167 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])  | 
                                                        |
| 1168 | - ? absint($this->_req_data['id'])  | 
                                                        |
| 1169 | - : false;  | 
                                                        |
| 1170 | -  | 
                                                        |
| 1171 | - $this->_set_shortcodes(); //this also sets the _message_template property.  | 
                                                        |
| 1172 | - $message_template_group = $this->_message_template_group;  | 
                                                        |
| 1173 | - $c_label = $message_template_group->context_label();  | 
                                                        |
| 1174 | - $c_config = $message_template_group->contexts_config();  | 
                                                        |
| 1175 | -  | 
                                                        |
| 1176 | - reset($c_config);  | 
                                                        |
| 1177 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])  | 
                                                        |
| 1178 | - ? strtolower($this->_req_data['context'])  | 
                                                        |
| 1179 | - : key($c_config);  | 
                                                        |
| 1180 | -  | 
                                                        |
| 1181 | -  | 
                                                        |
| 1182 | -        if (empty($GRP_ID)) { | 
                                                        |
| 1183 | - $action = 'insert_message_template';  | 
                                                        |
| 1184 | - //$button_both = false;  | 
                                                        |
| 1185 | - //$button_text = array( __( 'Save','event_espresso') );  | 
                                                        |
| 1186 | -            //$button_actions = array('something_different'); | 
                                                        |
| 1187 | - //$referrer = false;  | 
                                                        |
| 1188 | - $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1189 | -                array('action' => $action, 'noheader' => true), | 
                                                        |
| 1190 | - EE_MSG_ADMIN_URL  | 
                                                        |
| 1191 | - );  | 
                                                        |
| 1192 | -        } else { | 
                                                        |
| 1193 | - $action = 'update_message_template';  | 
                                                        |
| 1194 | - //$button_both = true;  | 
                                                        |
| 1195 | - //$button_text = array();  | 
                                                        |
| 1196 | - //$button_actions = array();  | 
                                                        |
| 1197 | - //$referrer = $this->_admin_base_url;  | 
                                                        |
| 1198 | - $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1199 | -                array('action' => $action, 'noheader' => true), | 
                                                        |
| 1200 | - EE_MSG_ADMIN_URL  | 
                                                        |
| 1201 | - );  | 
                                                        |
| 1202 | - }  | 
                                                        |
| 1203 | -  | 
                                                        |
| 1204 | - //set active messenger for this view  | 
                                                        |
| 1205 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 1206 | - $message_template_group->messenger()  | 
                                                        |
| 1207 | - );  | 
                                                        |
| 1208 | - $this->_active_message_type_name = $message_template_group->message_type();  | 
                                                        |
| 1209 | -  | 
                                                        |
| 1210 | -  | 
                                                        |
| 1211 | - //Do we have any validation errors?  | 
                                                        |
| 1212 | - $validators = $this->_get_transient();  | 
                                                        |
| 1213 | - $v_fields = ! empty($validators) ? array_keys($validators) : array();  | 
                                                        |
| 1214 | -  | 
                                                        |
| 1215 | -  | 
                                                        |
| 1216 | - //we need to assemble the title from Various details  | 
                                                        |
| 1217 | - $context_label = sprintf(  | 
                                                        |
| 1218 | -            __('(%s %s)', 'event_espresso'), | 
                                                        |
| 1219 | - $c_config[$context]['label'],  | 
                                                        |
| 1220 | - ucwords($c_label['label'])  | 
                                                        |
| 1221 | - );  | 
                                                        |
| 1222 | -  | 
                                                        |
| 1223 | - $title = sprintf(  | 
                                                        |
| 1224 | -            __(' %s %s Template %s', 'event_espresso'), | 
                                                        |
| 1225 | - ucwords($message_template_group->messenger_obj()->label['singular']),  | 
                                                        |
| 1226 | - ucwords($message_template_group->message_type_obj()->label['singular']),  | 
                                                        |
| 1227 | - $context_label  | 
                                                        |
| 1228 | - );  | 
                                                        |
| 1229 | -  | 
                                                        |
| 1230 | - $this->_template_args['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1231 | - $this->_template_args['message_template'] = $message_template_group;  | 
                                                        |
| 1232 | - $this->_template_args['is_extra_fields'] = false;  | 
                                                        |
| 1233 | -  | 
                                                        |
| 1234 | -  | 
                                                        |
| 1235 | - //let's get EEH_MSG_Template so we can get template form fields  | 
                                                        |
| 1236 | - $template_field_structure = EEH_MSG_Template::get_fields(  | 
                                                        |
| 1237 | - $message_template_group->messenger(),  | 
                                                        |
| 1238 | - $message_template_group->message_type()  | 
                                                        |
| 1239 | - );  | 
                                                        |
| 1240 | -  | 
                                                        |
| 1241 | -        if ( ! $template_field_structure) { | 
                                                        |
| 1242 | - $template_field_structure = false;  | 
                                                        |
| 1243 | -            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)', | 
                                                        |
| 1244 | - 'event_espresso');  | 
                                                        |
| 1245 | - }  | 
                                                        |
| 1246 | -  | 
                                                        |
| 1247 | -  | 
                                                        |
| 1248 | - $message_templates = $message_template_group->context_templates();  | 
                                                        |
| 1249 | -  | 
                                                        |
| 1250 | -  | 
                                                        |
| 1251 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.  | 
                                                        |
| 1252 | -        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { | 
                                                        |
| 1253 | -            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1254 | - unset($template_field_structure[$context][$reference_field]);  | 
                                                        |
| 1255 | - }  | 
                                                        |
| 1256 | - }  | 
                                                        |
| 1257 | -  | 
                                                        |
| 1258 | - //let's loop through the template_field_structure and actually assemble the input fields!  | 
                                                        |
| 1259 | -        if ( ! empty($template_field_structure)) { | 
                                                        |
| 1260 | -            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { | 
                                                        |
| 1261 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.  | 
                                                        |
| 1262 | -                if ($template_field == 'extra') { | 
                                                        |
| 1263 | - $this->_template_args['is_extra_fields'] = true;  | 
                                                        |
| 1264 | -                    foreach ($field_setup_array as $reference_field => $new_fields_array) { | 
                                                        |
| 1265 | - $message_template = $message_templates[$context][$reference_field];  | 
                                                        |
| 1266 | - $content = $message_template instanceof EE_Message_Template  | 
                                                        |
| 1267 | -                            ? $message_template->get('MTP_content') | 
                                                        |
| 1268 | - : '';  | 
                                                        |
| 1269 | -                        foreach ($new_fields_array as $extra_field => $extra_array) { | 
                                                        |
| 1270 | - //let's verify if we need this extra field via the shortcodes parameter.  | 
                                                        |
| 1271 | - $continue = false;  | 
                                                        |
| 1272 | -                            if (isset($extra_array['shortcodes_required'])) { | 
                                                        |
| 1273 | -                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1274 | -                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1275 | - $continue = true;  | 
                                                        |
| 1276 | - }  | 
                                                        |
| 1277 | - }  | 
                                                        |
| 1278 | -                                if ($continue) { | 
                                                        |
| 1279 | - continue;  | 
                                                        |
| 1280 | - }  | 
                                                        |
| 1281 | - }  | 
                                                        |
| 1071 | + }  | 
                                                        |
| 1072 | +  | 
                                                        |
| 1073 | + return $templates;  | 
                                                        |
| 1074 | + }  | 
                                                        |
| 1075 | +  | 
                                                        |
| 1076 | +  | 
                                                        |
| 1077 | + /**  | 
                                                        |
| 1078 | + * filters etc might need a list of installed message_types  | 
                                                        |
| 1079 | + * @return array an array of message type objects  | 
                                                        |
| 1080 | + */  | 
                                                        |
| 1081 | + public function get_installed_message_types()  | 
                                                        |
| 1082 | +	{ | 
                                                        |
| 1083 | + $installed_message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 1084 | + $installed = array();  | 
                                                        |
| 1085 | +  | 
                                                        |
| 1086 | +		foreach ($installed_message_types as $message_type) { | 
                                                        |
| 1087 | + $installed[$message_type->name] = $message_type;  | 
                                                        |
| 1088 | + }  | 
                                                        |
| 1089 | +  | 
                                                        |
| 1090 | + return $installed;  | 
                                                        |
| 1091 | + }  | 
                                                        |
| 1092 | +  | 
                                                        |
| 1093 | +  | 
                                                        |
| 1094 | + /**  | 
                                                        |
| 1095 | + * _add_message_template  | 
                                                        |
| 1096 | + *  | 
                                                        |
| 1097 | + * This is used when creating a custom template. All Custom Templates start based off another template.  | 
                                                        |
| 1098 | + *  | 
                                                        |
| 1099 | + * @param string $message_type  | 
                                                        |
| 1100 | + * @param string $messenger  | 
                                                        |
| 1101 | + * @param string $GRP_ID  | 
                                                        |
| 1102 | + *  | 
                                                        |
| 1103 | + * @throws EE_error  | 
                                                        |
| 1104 | + */  | 
                                                        |
| 1105 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')  | 
                                                        |
| 1106 | +	{ | 
                                                        |
| 1107 | + //set values override any request data  | 
                                                        |
| 1108 | + $message_type = ! empty($message_type) ? $message_type : '';  | 
                                                        |
| 1109 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;  | 
                                                        |
| 1110 | +  | 
                                                        |
| 1111 | + $messenger = ! empty($messenger) ? $messenger : '';  | 
                                                        |
| 1112 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;  | 
                                                        |
| 1113 | +  | 
                                                        |
| 1114 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';  | 
                                                        |
| 1115 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;  | 
                                                        |
| 1116 | +  | 
                                                        |
| 1117 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error  | 
                                                        |
| 1118 | +		if (empty($message_type) || empty($messenger)) { | 
                                                        |
| 1119 | +			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', | 
                                                        |
| 1120 | + 'event_espresso'));  | 
                                                        |
| 1121 | + }  | 
                                                        |
| 1122 | +  | 
                                                        |
| 1123 | + //we need the GRP_ID for the template being used as the base for the new template  | 
                                                        |
| 1124 | +		if (empty($GRP_ID)) { | 
                                                        |
| 1125 | +			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', | 
                                                        |
| 1126 | + 'event_espresso'));  | 
                                                        |
| 1127 | + }  | 
                                                        |
| 1128 | +  | 
                                                        |
| 1129 | + //let's just make sure the template gets generated!  | 
                                                        |
| 1130 | +  | 
                                                        |
| 1131 | + //we need to reassign some variables for what the insert is expecting  | 
                                                        |
| 1132 | + $this->_req_data['MTP_messenger'] = $messenger;  | 
                                                        |
| 1133 | + $this->_req_data['MTP_message_type'] = $message_type;  | 
                                                        |
| 1134 | + $this->_req_data['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1135 | + $this->_insert_or_update_message_template(true);  | 
                                                        |
| 1136 | + }  | 
                                                        |
| 1137 | +  | 
                                                        |
| 1138 | +  | 
                                                        |
| 1139 | + /**  | 
                                                        |
| 1140 | + * public wrapper for the _add_message_template method  | 
                                                        |
| 1141 | + *  | 
                                                        |
| 1142 | + * @param string $message_type message type slug  | 
                                                        |
| 1143 | + * @param string $messenger messenger slug  | 
                                                        |
| 1144 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based  | 
                                                        |
| 1145 | + * off of.  | 
                                                        |
| 1146 | + */  | 
                                                        |
| 1147 | + public function add_message_template($message_type, $messenger, $GRP_ID)  | 
                                                        |
| 1148 | +	{ | 
                                                        |
| 1149 | + $this->_add_message_template($message_type, $messenger, $GRP_ID);  | 
                                                        |
| 1150 | + }  | 
                                                        |
| 1151 | +  | 
                                                        |
| 1152 | +  | 
                                                        |
| 1153 | + /**  | 
                                                        |
| 1154 | + * _edit_message_template  | 
                                                        |
| 1155 | + *  | 
                                                        |
| 1156 | + * @access protected  | 
                                                        |
| 1157 | + * @return void  | 
                                                        |
| 1158 | + */  | 
                                                        |
| 1159 | + protected function _edit_message_template()  | 
                                                        |
| 1160 | +	{ | 
                                                        |
| 1161 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1162 | + $template_fields = '';  | 
                                                        |
| 1163 | + $sidebar_fields = '';  | 
                                                        |
| 1164 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.  | 
                                                        |
| 1165 | +		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); | 
                                                        |
| 1166 | +  | 
                                                        |
| 1167 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])  | 
                                                        |
| 1168 | + ? absint($this->_req_data['id'])  | 
                                                        |
| 1169 | + : false;  | 
                                                        |
| 1170 | +  | 
                                                        |
| 1171 | + $this->_set_shortcodes(); //this also sets the _message_template property.  | 
                                                        |
| 1172 | + $message_template_group = $this->_message_template_group;  | 
                                                        |
| 1173 | + $c_label = $message_template_group->context_label();  | 
                                                        |
| 1174 | + $c_config = $message_template_group->contexts_config();  | 
                                                        |
| 1175 | +  | 
                                                        |
| 1176 | + reset($c_config);  | 
                                                        |
| 1177 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])  | 
                                                        |
| 1178 | + ? strtolower($this->_req_data['context'])  | 
                                                        |
| 1179 | + : key($c_config);  | 
                                                        |
| 1180 | +  | 
                                                        |
| 1181 | +  | 
                                                        |
| 1182 | +		if (empty($GRP_ID)) { | 
                                                        |
| 1183 | + $action = 'insert_message_template';  | 
                                                        |
| 1184 | + //$button_both = false;  | 
                                                        |
| 1185 | + //$button_text = array( __( 'Save','event_espresso') );  | 
                                                        |
| 1186 | +			//$button_actions = array('something_different'); | 
                                                        |
| 1187 | + //$referrer = false;  | 
                                                        |
| 1188 | + $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1189 | +				array('action' => $action, 'noheader' => true), | 
                                                        |
| 1190 | + EE_MSG_ADMIN_URL  | 
                                                        |
| 1191 | + );  | 
                                                        |
| 1192 | +		} else { | 
                                                        |
| 1193 | + $action = 'update_message_template';  | 
                                                        |
| 1194 | + //$button_both = true;  | 
                                                        |
| 1195 | + //$button_text = array();  | 
                                                        |
| 1196 | + //$button_actions = array();  | 
                                                        |
| 1197 | + //$referrer = $this->_admin_base_url;  | 
                                                        |
| 1198 | + $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1199 | +				array('action' => $action, 'noheader' => true), | 
                                                        |
| 1200 | + EE_MSG_ADMIN_URL  | 
                                                        |
| 1201 | + );  | 
                                                        |
| 1202 | + }  | 
                                                        |
| 1203 | +  | 
                                                        |
| 1204 | + //set active messenger for this view  | 
                                                        |
| 1205 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 1206 | + $message_template_group->messenger()  | 
                                                        |
| 1207 | + );  | 
                                                        |
| 1208 | + $this->_active_message_type_name = $message_template_group->message_type();  | 
                                                        |
| 1209 | +  | 
                                                        |
| 1210 | +  | 
                                                        |
| 1211 | + //Do we have any validation errors?  | 
                                                        |
| 1212 | + $validators = $this->_get_transient();  | 
                                                        |
| 1213 | + $v_fields = ! empty($validators) ? array_keys($validators) : array();  | 
                                                        |
| 1214 | +  | 
                                                        |
| 1215 | +  | 
                                                        |
| 1216 | + //we need to assemble the title from Various details  | 
                                                        |
| 1217 | + $context_label = sprintf(  | 
                                                        |
| 1218 | +			__('(%s %s)', 'event_espresso'), | 
                                                        |
| 1219 | + $c_config[$context]['label'],  | 
                                                        |
| 1220 | + ucwords($c_label['label'])  | 
                                                        |
| 1221 | + );  | 
                                                        |
| 1222 | +  | 
                                                        |
| 1223 | + $title = sprintf(  | 
                                                        |
| 1224 | +			__(' %s %s Template %s', 'event_espresso'), | 
                                                        |
| 1225 | + ucwords($message_template_group->messenger_obj()->label['singular']),  | 
                                                        |
| 1226 | + ucwords($message_template_group->message_type_obj()->label['singular']),  | 
                                                        |
| 1227 | + $context_label  | 
                                                        |
| 1228 | + );  | 
                                                        |
| 1229 | +  | 
                                                        |
| 1230 | + $this->_template_args['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1231 | + $this->_template_args['message_template'] = $message_template_group;  | 
                                                        |
| 1232 | + $this->_template_args['is_extra_fields'] = false;  | 
                                                        |
| 1233 | +  | 
                                                        |
| 1234 | +  | 
                                                        |
| 1235 | + //let's get EEH_MSG_Template so we can get template form fields  | 
                                                        |
| 1236 | + $template_field_structure = EEH_MSG_Template::get_fields(  | 
                                                        |
| 1237 | + $message_template_group->messenger(),  | 
                                                        |
| 1238 | + $message_template_group->message_type()  | 
                                                        |
| 1239 | + );  | 
                                                        |
| 1240 | +  | 
                                                        |
| 1241 | +		if ( ! $template_field_structure) { | 
                                                        |
| 1242 | + $template_field_structure = false;  | 
                                                        |
| 1243 | +			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)', | 
                                                        |
| 1244 | + 'event_espresso');  | 
                                                        |
| 1245 | + }  | 
                                                        |
| 1246 | +  | 
                                                        |
| 1247 | +  | 
                                                        |
| 1248 | + $message_templates = $message_template_group->context_templates();  | 
                                                        |
| 1249 | +  | 
                                                        |
| 1250 | +  | 
                                                        |
| 1251 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.  | 
                                                        |
| 1252 | +		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { | 
                                                        |
| 1253 | +			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1254 | + unset($template_field_structure[$context][$reference_field]);  | 
                                                        |
| 1255 | + }  | 
                                                        |
| 1256 | + }  | 
                                                        |
| 1257 | +  | 
                                                        |
| 1258 | + //let's loop through the template_field_structure and actually assemble the input fields!  | 
                                                        |
| 1259 | +		if ( ! empty($template_field_structure)) { | 
                                                        |
| 1260 | +			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { | 
                                                        |
| 1261 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.  | 
                                                        |
| 1262 | +				if ($template_field == 'extra') { | 
                                                        |
| 1263 | + $this->_template_args['is_extra_fields'] = true;  | 
                                                        |
| 1264 | +					foreach ($field_setup_array as $reference_field => $new_fields_array) { | 
                                                        |
| 1265 | + $message_template = $message_templates[$context][$reference_field];  | 
                                                        |
| 1266 | + $content = $message_template instanceof EE_Message_Template  | 
                                                        |
| 1267 | +							? $message_template->get('MTP_content') | 
                                                        |
| 1268 | + : '';  | 
                                                        |
| 1269 | +						foreach ($new_fields_array as $extra_field => $extra_array) { | 
                                                        |
| 1270 | + //let's verify if we need this extra field via the shortcodes parameter.  | 
                                                        |
| 1271 | + $continue = false;  | 
                                                        |
| 1272 | +							if (isset($extra_array['shortcodes_required'])) { | 
                                                        |
| 1273 | +								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1274 | +									if ( ! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1275 | + $continue = true;  | 
                                                        |
| 1276 | + }  | 
                                                        |
| 1277 | + }  | 
                                                        |
| 1278 | +								if ($continue) { | 
                                                        |
| 1279 | + continue;  | 
                                                        |
| 1280 | + }  | 
                                                        |
| 1281 | + }  | 
                                                        |
| 1282 | 1282 | |
| 1283 | - $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1284 | - $template_form_fields[$field_id] = $extra_array;  | 
                                                        |
| 1285 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';  | 
                                                        |
| 1286 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';  | 
                                                        |
| 1283 | + $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1284 | + $template_form_fields[$field_id] = $extra_array;  | 
                                                        |
| 1285 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';  | 
                                                        |
| 1286 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';  | 
                                                        |
| 1287 | 1287 | |
| 1288 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1289 | - && in_array($extra_field, $v_fields)  | 
                                                        |
| 1290 | - &&  | 
                                                        |
| 1291 | - (  | 
                                                        |
| 1292 | - is_array($validators[$extra_field])  | 
                                                        |
| 1293 | - && isset($validators[$extra_field]['msg'])  | 
                                                        |
| 1294 | - )  | 
                                                        |
| 1295 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1296 | - : $css_class;  | 
                                                        |
| 1288 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1289 | + && in_array($extra_field, $v_fields)  | 
                                                        |
| 1290 | + &&  | 
                                                        |
| 1291 | + (  | 
                                                        |
| 1292 | + is_array($validators[$extra_field])  | 
                                                        |
| 1293 | + && isset($validators[$extra_field]['msg'])  | 
                                                        |
| 1294 | + )  | 
                                                        |
| 1295 | + ? 'validate-error ' . $css_class  | 
                                                        |
| 1296 | + : $css_class;  | 
                                                        |
| 1297 | 1297 | |
| 1298 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])  | 
                                                        |
| 1299 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))  | 
                                                        |
| 1300 | - : '';  | 
                                                        |
| 1298 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])  | 
                                                        |
| 1299 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))  | 
                                                        |
| 1300 | + : '';  | 
                                                        |
| 1301 | 1301 | |
| 1302 | - //do we have a validation error? if we do then let's use that value instead  | 
                                                        |
| 1303 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1302 | + //do we have a validation error? if we do then let's use that value instead  | 
                                                        |
| 1303 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1306 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1307 | 1307 | |
| 1308 | - //shortcode selector  | 
                                                        |
| 1309 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field;  | 
                                                        |
| 1310 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1311 | - $field_name_to_use,  | 
                                                        |
| 1312 | - $field_id  | 
                                                        |
| 1313 | - );  | 
                                                        |
| 1308 | + //shortcode selector  | 
                                                        |
| 1309 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field;  | 
                                                        |
| 1310 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1311 | + $field_name_to_use,  | 
                                                        |
| 1312 | + $field_id  | 
                                                        |
| 1313 | + );  | 
                                                        |
| 1314 | 1314 | |
| 1315 | -                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { | 
                                                        |
| 1316 | - //we want to decode the entities  | 
                                                        |
| 1317 | - $template_form_fields[$field_id]['value'] = stripslashes(  | 
                                                        |
| 1318 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")  | 
                                                        |
| 1319 | - );  | 
                                                        |
| 1315 | +							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { | 
                                                        |
| 1316 | + //we want to decode the entities  | 
                                                        |
| 1317 | + $template_form_fields[$field_id]['value'] = stripslashes(  | 
                                                        |
| 1318 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")  | 
                                                        |
| 1319 | + );  | 
                                                        |
| 1320 | 1320 | |
| 1321 | - }/**/  | 
                                                        |
| 1322 | - }  | 
                                                        |
| 1323 | - $templatefield_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1324 | - $templatefield_templatename_id = $reference_field . '-name';  | 
                                                        |
| 1321 | + }/**/  | 
                                                        |
| 1322 | + }  | 
                                                        |
| 1323 | + $templatefield_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1324 | + $templatefield_templatename_id = $reference_field . '-name';  | 
                                                        |
| 1325 | 1325 | |
| 1326 | - $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        |
| 1327 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1328 | - 'label' => null,  | 
                                                        |
| 1329 | - 'input' => 'hidden',  | 
                                                        |
| 1330 | - 'type' => 'int',  | 
                                                        |
| 1331 | - 'required' => false,  | 
                                                        |
| 1332 | - 'validation' => false,  | 
                                                        |
| 1333 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '',  | 
                                                        |
| 1334 | - 'css_class' => '',  | 
                                                        |
| 1335 | - 'format' => '%d',  | 
                                                        |
| 1336 | - 'db-col' => 'MTP_ID'  | 
                                                        |
| 1337 | - );  | 
                                                        |
| 1326 | + $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        |
| 1327 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1328 | + 'label' => null,  | 
                                                        |
| 1329 | + 'input' => 'hidden',  | 
                                                        |
| 1330 | + 'type' => 'int',  | 
                                                        |
| 1331 | + 'required' => false,  | 
                                                        |
| 1332 | + 'validation' => false,  | 
                                                        |
| 1333 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '',  | 
                                                        |
| 1334 | + 'css_class' => '',  | 
                                                        |
| 1335 | + 'format' => '%d',  | 
                                                        |
| 1336 | + 'db-col' => 'MTP_ID'  | 
                                                        |
| 1337 | + );  | 
                                                        |
| 1338 | 1338 | |
| 1339 | - $template_form_fields[$templatefield_templatename_id] = array(  | 
                                                        |
| 1340 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1341 | - 'label' => null,  | 
                                                        |
| 1342 | - 'input' => 'hidden',  | 
                                                        |
| 1343 | - 'type' => 'string',  | 
                                                        |
| 1344 | - 'required' => false,  | 
                                                        |
| 1345 | - 'validation' => true,  | 
                                                        |
| 1346 | - 'value' => $reference_field,  | 
                                                        |
| 1347 | - 'css_class' => '',  | 
                                                        |
| 1348 | - 'format' => '%s',  | 
                                                        |
| 1349 | - 'db-col' => 'MTP_template_field'  | 
                                                        |
| 1350 | - );  | 
                                                        |
| 1351 | - }  | 
                                                        |
| 1352 | - continue; //skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        |
| 1353 | -                } else { | 
                                                        |
| 1354 | - $field_id = $template_field . '-content';  | 
                                                        |
| 1355 | - $template_form_fields[$field_id] = $field_setup_array;  | 
                                                        |
| 1356 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1357 | - $message_template = isset($message_templates[$context][$template_field])  | 
                                                        |
| 1358 | - ? $message_templates[$context][$template_field]  | 
                                                        |
| 1359 | - : null;  | 
                                                        |
| 1360 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates)  | 
                                                        |
| 1361 | - && is_array($message_templates[$context])  | 
                                                        |
| 1362 | - && $message_template instanceof EE_Message_Template  | 
                                                        |
| 1363 | -                        ? $message_template->get('MTP_content') | 
                                                        |
| 1364 | - : '';  | 
                                                        |
| 1339 | + $template_form_fields[$templatefield_templatename_id] = array(  | 
                                                        |
| 1340 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1341 | + 'label' => null,  | 
                                                        |
| 1342 | + 'input' => 'hidden',  | 
                                                        |
| 1343 | + 'type' => 'string',  | 
                                                        |
| 1344 | + 'required' => false,  | 
                                                        |
| 1345 | + 'validation' => true,  | 
                                                        |
| 1346 | + 'value' => $reference_field,  | 
                                                        |
| 1347 | + 'css_class' => '',  | 
                                                        |
| 1348 | + 'format' => '%s',  | 
                                                        |
| 1349 | + 'db-col' => 'MTP_template_field'  | 
                                                        |
| 1350 | + );  | 
                                                        |
| 1351 | + }  | 
                                                        |
| 1352 | + continue; //skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        |
| 1353 | +				} else { | 
                                                        |
| 1354 | + $field_id = $template_field . '-content';  | 
                                                        |
| 1355 | + $template_form_fields[$field_id] = $field_setup_array;  | 
                                                        |
| 1356 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1357 | + $message_template = isset($message_templates[$context][$template_field])  | 
                                                        |
| 1358 | + ? $message_templates[$context][$template_field]  | 
                                                        |
| 1359 | + : null;  | 
                                                        |
| 1360 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates)  | 
                                                        |
| 1361 | + && is_array($message_templates[$context])  | 
                                                        |
| 1362 | + && $message_template instanceof EE_Message_Template  | 
                                                        |
| 1363 | +						? $message_template->get('MTP_content') | 
                                                        |
| 1364 | + : '';  | 
                                                        |
| 1365 | 1365 | |
| 1366 | - //do we have a validator error for this field? if we do then we'll use that value instead  | 
                                                        |
| 1367 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field])  | 
                                                        |
| 1368 | - ? $validators[$template_field]['value']  | 
                                                        |
| 1369 | - : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1366 | + //do we have a validator error for this field? if we do then we'll use that value instead  | 
                                                        |
| 1367 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field])  | 
                                                        |
| 1368 | + ? $validators[$template_field]['value']  | 
                                                        |
| 1369 | + : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1370 | 1370 | |
| 1371 | 1371 | |
| 1372 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1373 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';  | 
                                                        |
| 1374 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1375 | - && in_array($template_field, $v_fields)  | 
                                                        |
| 1376 | - && isset($validators[$template_field]['msg'])  | 
                                                        |
| 1377 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1378 | - : $css_class;  | 
                                                        |
| 1372 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1373 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';  | 
                                                        |
| 1374 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1375 | + && in_array($template_field, $v_fields)  | 
                                                        |
| 1376 | + && isset($validators[$template_field]['msg'])  | 
                                                        |
| 1377 | + ? 'validate-error ' . $css_class  | 
                                                        |
| 1378 | + : $css_class;  | 
                                                        |
| 1379 | 1379 | |
| 1380 | - //shortcode selector  | 
                                                        |
| 1381 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1382 | - $template_field, $field_id  | 
                                                        |
| 1383 | - );  | 
                                                        |
| 1384 | - }  | 
                                                        |
| 1380 | + //shortcode selector  | 
                                                        |
| 1381 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1382 | + $template_field, $field_id  | 
                                                        |
| 1383 | + );  | 
                                                        |
| 1384 | + }  | 
                                                        |
| 1385 | 1385 | |
| 1386 | - //k took care of content field(s) now let's take care of others.  | 
                                                        |
| 1386 | + //k took care of content field(s) now let's take care of others.  | 
                                                        |
| 1387 | 1387 | |
| 1388 | - $templatefield_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1389 | - $templatefield_field_templatename_id = $template_field . '-name';  | 
                                                        |
| 1388 | + $templatefield_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1389 | + $templatefield_field_templatename_id = $template_field . '-name';  | 
                                                        |
| 1390 | 1390 | |
| 1391 | - //foreach template field there are actually two form fields created  | 
                                                        |
| 1392 | - $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        |
| 1393 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1394 | - 'label' => null,  | 
                                                        |
| 1395 | - 'input' => 'hidden',  | 
                                                        |
| 1396 | - 'type' => 'int',  | 
                                                        |
| 1397 | - 'required' => false,  | 
                                                        |
| 1398 | - 'validation' => true,  | 
                                                        |
| 1399 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',  | 
                                                        |
| 1400 | - 'css_class' => '',  | 
                                                        |
| 1401 | - 'format' => '%d',  | 
                                                        |
| 1402 | - 'db-col' => 'MTP_ID'  | 
                                                        |
| 1403 | - );  | 
                                                        |
| 1391 | + //foreach template field there are actually two form fields created  | 
                                                        |
| 1392 | + $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        |
| 1393 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1394 | + 'label' => null,  | 
                                                        |
| 1395 | + 'input' => 'hidden',  | 
                                                        |
| 1396 | + 'type' => 'int',  | 
                                                        |
| 1397 | + 'required' => false,  | 
                                                        |
| 1398 | + 'validation' => true,  | 
                                                        |
| 1399 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',  | 
                                                        |
| 1400 | + 'css_class' => '',  | 
                                                        |
| 1401 | + 'format' => '%d',  | 
                                                        |
| 1402 | + 'db-col' => 'MTP_ID'  | 
                                                        |
| 1403 | + );  | 
                                                        |
| 1404 | 1404 | |
| 1405 | - $template_form_fields[$templatefield_field_templatename_id] = array(  | 
                                                        |
| 1406 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1407 | - 'label' => null,  | 
                                                        |
| 1408 | - 'input' => 'hidden',  | 
                                                        |
| 1409 | - 'type' => 'string',  | 
                                                        |
| 1410 | - 'required' => false,  | 
                                                        |
| 1411 | - 'validation' => true,  | 
                                                        |
| 1412 | - 'value' => $template_field,  | 
                                                        |
| 1413 | - 'css_class' => '',  | 
                                                        |
| 1414 | - 'format' => '%s',  | 
                                                        |
| 1415 | - 'db-col' => 'MTP_template_field'  | 
                                                        |
| 1416 | - );  | 
                                                        |
| 1405 | + $template_form_fields[$templatefield_field_templatename_id] = array(  | 
                                                        |
| 1406 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1407 | + 'label' => null,  | 
                                                        |
| 1408 | + 'input' => 'hidden',  | 
                                                        |
| 1409 | + 'type' => 'string',  | 
                                                        |
| 1410 | + 'required' => false,  | 
                                                        |
| 1411 | + 'validation' => true,  | 
                                                        |
| 1412 | + 'value' => $template_field,  | 
                                                        |
| 1413 | + 'css_class' => '',  | 
                                                        |
| 1414 | + 'format' => '%s',  | 
                                                        |
| 1415 | + 'db-col' => 'MTP_template_field'  | 
                                                        |
| 1416 | + );  | 
                                                        |
| 1417 | 1417 | |
| 1418 | - }  | 
                                                        |
| 1418 | + }  | 
                                                        |
| 1419 | 1419 | |
| 1420 | - //add other fields  | 
                                                        |
| 1421 | - $template_form_fields['ee-msg-current-context'] = array(  | 
                                                        |
| 1422 | - 'name' => 'MTP_context',  | 
                                                        |
| 1423 | - 'label' => null,  | 
                                                        |
| 1424 | - 'input' => 'hidden',  | 
                                                        |
| 1425 | - 'type' => 'string',  | 
                                                        |
| 1426 | - 'required' => false,  | 
                                                        |
| 1427 | - 'validation' => true,  | 
                                                        |
| 1428 | - 'value' => $context,  | 
                                                        |
| 1429 | - 'css_class' => '',  | 
                                                        |
| 1430 | - 'format' => '%s',  | 
                                                        |
| 1431 | - 'db-col' => 'MTP_context'  | 
                                                        |
| 1432 | - );  | 
                                                        |
| 1420 | + //add other fields  | 
                                                        |
| 1421 | + $template_form_fields['ee-msg-current-context'] = array(  | 
                                                        |
| 1422 | + 'name' => 'MTP_context',  | 
                                                        |
| 1423 | + 'label' => null,  | 
                                                        |
| 1424 | + 'input' => 'hidden',  | 
                                                        |
| 1425 | + 'type' => 'string',  | 
                                                        |
| 1426 | + 'required' => false,  | 
                                                        |
| 1427 | + 'validation' => true,  | 
                                                        |
| 1428 | + 'value' => $context,  | 
                                                        |
| 1429 | + 'css_class' => '',  | 
                                                        |
| 1430 | + 'format' => '%s',  | 
                                                        |
| 1431 | + 'db-col' => 'MTP_context'  | 
                                                        |
| 1432 | + );  | 
                                                        |
| 1433 | 1433 | |
| 1434 | - $template_form_fields['ee-msg-grp-id'] = array(  | 
                                                        |
| 1435 | - 'name' => 'GRP_ID',  | 
                                                        |
| 1436 | - 'label' => null,  | 
                                                        |
| 1437 | - 'input' => 'hidden',  | 
                                                        |
| 1438 | - 'type' => 'int',  | 
                                                        |
| 1439 | - 'required' => false,  | 
                                                        |
| 1440 | - 'validation' => true,  | 
                                                        |
| 1441 | - 'value' => $GRP_ID,  | 
                                                        |
| 1442 | - 'css_class' => '',  | 
                                                        |
| 1443 | - 'format' => '%d',  | 
                                                        |
| 1444 | - 'db-col' => 'GRP_ID'  | 
                                                        |
| 1445 | - );  | 
                                                        |
| 1434 | + $template_form_fields['ee-msg-grp-id'] = array(  | 
                                                        |
| 1435 | + 'name' => 'GRP_ID',  | 
                                                        |
| 1436 | + 'label' => null,  | 
                                                        |
| 1437 | + 'input' => 'hidden',  | 
                                                        |
| 1438 | + 'type' => 'int',  | 
                                                        |
| 1439 | + 'required' => false,  | 
                                                        |
| 1440 | + 'validation' => true,  | 
                                                        |
| 1441 | + 'value' => $GRP_ID,  | 
                                                        |
| 1442 | + 'css_class' => '',  | 
                                                        |
| 1443 | + 'format' => '%d',  | 
                                                        |
| 1444 | + 'db-col' => 'GRP_ID'  | 
                                                        |
| 1445 | + );  | 
                                                        |
| 1446 | 1446 | |
| 1447 | - $template_form_fields['ee-msg-messenger'] = array(  | 
                                                        |
| 1448 | - 'name' => 'MTP_messenger',  | 
                                                        |
| 1449 | - 'label' => null,  | 
                                                        |
| 1450 | - 'input' => 'hidden',  | 
                                                        |
| 1451 | - 'type' => 'string',  | 
                                                        |
| 1452 | - 'required' => false,  | 
                                                        |
| 1453 | - 'validation' => true,  | 
                                                        |
| 1454 | - 'value' => $message_template_group->messenger(),  | 
                                                        |
| 1455 | - 'css_class' => '',  | 
                                                        |
| 1456 | - 'format' => '%s',  | 
                                                        |
| 1457 | - 'db-col' => 'MTP_messenger'  | 
                                                        |
| 1458 | - );  | 
                                                        |
| 1447 | + $template_form_fields['ee-msg-messenger'] = array(  | 
                                                        |
| 1448 | + 'name' => 'MTP_messenger',  | 
                                                        |
| 1449 | + 'label' => null,  | 
                                                        |
| 1450 | + 'input' => 'hidden',  | 
                                                        |
| 1451 | + 'type' => 'string',  | 
                                                        |
| 1452 | + 'required' => false,  | 
                                                        |
| 1453 | + 'validation' => true,  | 
                                                        |
| 1454 | + 'value' => $message_template_group->messenger(),  | 
                                                        |
| 1455 | + 'css_class' => '',  | 
                                                        |
| 1456 | + 'format' => '%s',  | 
                                                        |
| 1457 | + 'db-col' => 'MTP_messenger'  | 
                                                        |
| 1458 | + );  | 
                                                        |
| 1459 | 1459 | |
| 1460 | - $template_form_fields['ee-msg-message-type'] = array(  | 
                                                        |
| 1461 | - 'name' => 'MTP_message_type',  | 
                                                        |
| 1462 | - 'label' => null,  | 
                                                        |
| 1463 | - 'input' => 'hidden',  | 
                                                        |
| 1464 | - 'type' => 'string',  | 
                                                        |
| 1465 | - 'required' => false,  | 
                                                        |
| 1466 | - 'validation' => true,  | 
                                                        |
| 1467 | - 'value' => $message_template_group->message_type(),  | 
                                                        |
| 1468 | - 'css_class' => '',  | 
                                                        |
| 1469 | - 'format' => '%s',  | 
                                                        |
| 1470 | - 'db-col' => 'MTP_message_type'  | 
                                                        |
| 1471 | - );  | 
                                                        |
| 1460 | + $template_form_fields['ee-msg-message-type'] = array(  | 
                                                        |
| 1461 | + 'name' => 'MTP_message_type',  | 
                                                        |
| 1462 | + 'label' => null,  | 
                                                        |
| 1463 | + 'input' => 'hidden',  | 
                                                        |
| 1464 | + 'type' => 'string',  | 
                                                        |
| 1465 | + 'required' => false,  | 
                                                        |
| 1466 | + 'validation' => true,  | 
                                                        |
| 1467 | + 'value' => $message_template_group->message_type(),  | 
                                                        |
| 1468 | + 'css_class' => '',  | 
                                                        |
| 1469 | + 'format' => '%s',  | 
                                                        |
| 1470 | + 'db-col' => 'MTP_message_type'  | 
                                                        |
| 1471 | + );  | 
                                                        |
| 1472 | 1472 | |
| 1473 | - $sidebar_form_fields['ee-msg-is-global'] = array(  | 
                                                        |
| 1474 | - 'name' => 'MTP_is_global',  | 
                                                        |
| 1475 | -                'label'      => __('Global Template', 'event_espresso'), | 
                                                        |
| 1476 | - 'input' => 'hidden',  | 
                                                        |
| 1477 | - 'type' => 'int',  | 
                                                        |
| 1478 | - 'required' => false,  | 
                                                        |
| 1479 | - 'validation' => true,  | 
                                                        |
| 1480 | -                'value'      => $message_template_group->get('MTP_is_global'), | 
                                                        |
| 1481 | - 'css_class' => '',  | 
                                                        |
| 1482 | - 'format' => '%d',  | 
                                                        |
| 1483 | - 'db-col' => 'MTP_is_global'  | 
                                                        |
| 1484 | - );  | 
                                                        |
| 1473 | + $sidebar_form_fields['ee-msg-is-global'] = array(  | 
                                                        |
| 1474 | + 'name' => 'MTP_is_global',  | 
                                                        |
| 1475 | +				'label'      => __('Global Template', 'event_espresso'), | 
                                                        |
| 1476 | + 'input' => 'hidden',  | 
                                                        |
| 1477 | + 'type' => 'int',  | 
                                                        |
| 1478 | + 'required' => false,  | 
                                                        |
| 1479 | + 'validation' => true,  | 
                                                        |
| 1480 | +				'value'      => $message_template_group->get('MTP_is_global'), | 
                                                        |
| 1481 | + 'css_class' => '',  | 
                                                        |
| 1482 | + 'format' => '%d',  | 
                                                        |
| 1483 | + 'db-col' => 'MTP_is_global'  | 
                                                        |
| 1484 | + );  | 
                                                        |
| 1485 | 1485 | |
| 1486 | - $sidebar_form_fields['ee-msg-is-override'] = array(  | 
                                                        |
| 1487 | - 'name' => 'MTP_is_override',  | 
                                                        |
| 1488 | -                'label'      => __('Override all custom', 'event_espresso'), | 
                                                        |
| 1489 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden',  | 
                                                        |
| 1490 | - 'type' => 'int',  | 
                                                        |
| 1491 | - 'required' => false,  | 
                                                        |
| 1492 | - 'validation' => true,  | 
                                                        |
| 1493 | -                'value'      => $message_template_group->get('MTP_is_override'), | 
                                                        |
| 1494 | - 'css_class' => '',  | 
                                                        |
| 1495 | - 'format' => '%d',  | 
                                                        |
| 1496 | - 'db-col' => 'MTP_is_override'  | 
                                                        |
| 1497 | - );  | 
                                                        |
| 1486 | + $sidebar_form_fields['ee-msg-is-override'] = array(  | 
                                                        |
| 1487 | + 'name' => 'MTP_is_override',  | 
                                                        |
| 1488 | +				'label'      => __('Override all custom', 'event_espresso'), | 
                                                        |
| 1489 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden',  | 
                                                        |
| 1490 | + 'type' => 'int',  | 
                                                        |
| 1491 | + 'required' => false,  | 
                                                        |
| 1492 | + 'validation' => true,  | 
                                                        |
| 1493 | +				'value'      => $message_template_group->get('MTP_is_override'), | 
                                                        |
| 1494 | + 'css_class' => '',  | 
                                                        |
| 1495 | + 'format' => '%d',  | 
                                                        |
| 1496 | + 'db-col' => 'MTP_is_override'  | 
                                                        |
| 1497 | + );  | 
                                                        |
| 1498 | 1498 | |
| 1499 | - $sidebar_form_fields['ee-msg-is-active'] = array(  | 
                                                        |
| 1500 | - 'name' => 'MTP_is_active',  | 
                                                        |
| 1501 | -                'label'      => __('Active Template', 'event_espresso'), | 
                                                        |
| 1502 | - 'input' => 'hidden',  | 
                                                        |
| 1503 | - 'type' => 'int',  | 
                                                        |
| 1504 | - 'required' => false,  | 
                                                        |
| 1505 | - 'validation' => true,  | 
                                                        |
| 1506 | - 'value' => $message_template_group->is_active(),  | 
                                                        |
| 1507 | - 'css_class' => '',  | 
                                                        |
| 1508 | - 'format' => '%d',  | 
                                                        |
| 1509 | - 'db-col' => 'MTP_is_active'  | 
                                                        |
| 1510 | - );  | 
                                                        |
| 1499 | + $sidebar_form_fields['ee-msg-is-active'] = array(  | 
                                                        |
| 1500 | + 'name' => 'MTP_is_active',  | 
                                                        |
| 1501 | +				'label'      => __('Active Template', 'event_espresso'), | 
                                                        |
| 1502 | + 'input' => 'hidden',  | 
                                                        |
| 1503 | + 'type' => 'int',  | 
                                                        |
| 1504 | + 'required' => false,  | 
                                                        |
| 1505 | + 'validation' => true,  | 
                                                        |
| 1506 | + 'value' => $message_template_group->is_active(),  | 
                                                        |
| 1507 | + 'css_class' => '',  | 
                                                        |
| 1508 | + 'format' => '%d',  | 
                                                        |
| 1509 | + 'db-col' => 'MTP_is_active'  | 
                                                        |
| 1510 | + );  | 
                                                        |
| 1511 | 1511 | |
| 1512 | - $sidebar_form_fields['ee-msg-deleted'] = array(  | 
                                                        |
| 1513 | - 'name' => 'MTP_deleted',  | 
                                                        |
| 1514 | - 'label' => null,  | 
                                                        |
| 1515 | - 'input' => 'hidden',  | 
                                                        |
| 1516 | - 'type' => 'int',  | 
                                                        |
| 1517 | - 'required' => false,  | 
                                                        |
| 1518 | - 'validation' => true,  | 
                                                        |
| 1519 | -                'value'      => $message_template_group->get('MTP_deleted'), | 
                                                        |
| 1520 | - 'css_class' => '',  | 
                                                        |
| 1521 | - 'format' => '%d',  | 
                                                        |
| 1522 | - 'db-col' => 'MTP_deleted'  | 
                                                        |
| 1523 | - );  | 
                                                        |
| 1524 | - $sidebar_form_fields['ee-msg-author'] = array(  | 
                                                        |
| 1525 | - 'name' => 'MTP_user_id',  | 
                                                        |
| 1526 | -                'label'      => __('Author', 'event_espresso'), | 
                                                        |
| 1527 | - 'input' => 'hidden',  | 
                                                        |
| 1528 | - 'type' => 'int',  | 
                                                        |
| 1529 | - 'required' => false,  | 
                                                        |
| 1530 | - 'validation' => false,  | 
                                                        |
| 1531 | - 'value' => $message_template_group->user(),  | 
                                                        |
| 1532 | - 'format' => '%d',  | 
                                                        |
| 1533 | - 'db-col' => 'MTP_user_id'  | 
                                                        |
| 1534 | - );  | 
                                                        |
| 1512 | + $sidebar_form_fields['ee-msg-deleted'] = array(  | 
                                                        |
| 1513 | + 'name' => 'MTP_deleted',  | 
                                                        |
| 1514 | + 'label' => null,  | 
                                                        |
| 1515 | + 'input' => 'hidden',  | 
                                                        |
| 1516 | + 'type' => 'int',  | 
                                                        |
| 1517 | + 'required' => false,  | 
                                                        |
| 1518 | + 'validation' => true,  | 
                                                        |
| 1519 | +				'value'      => $message_template_group->get('MTP_deleted'), | 
                                                        |
| 1520 | + 'css_class' => '',  | 
                                                        |
| 1521 | + 'format' => '%d',  | 
                                                        |
| 1522 | + 'db-col' => 'MTP_deleted'  | 
                                                        |
| 1523 | + );  | 
                                                        |
| 1524 | + $sidebar_form_fields['ee-msg-author'] = array(  | 
                                                        |
| 1525 | + 'name' => 'MTP_user_id',  | 
                                                        |
| 1526 | +				'label'      => __('Author', 'event_espresso'), | 
                                                        |
| 1527 | + 'input' => 'hidden',  | 
                                                        |
| 1528 | + 'type' => 'int',  | 
                                                        |
| 1529 | + 'required' => false,  | 
                                                        |
| 1530 | + 'validation' => false,  | 
                                                        |
| 1531 | + 'value' => $message_template_group->user(),  | 
                                                        |
| 1532 | + 'format' => '%d',  | 
                                                        |
| 1533 | + 'db-col' => 'MTP_user_id'  | 
                                                        |
| 1534 | + );  | 
                                                        |
| 1535 | 1535 | |
| 1536 | - $sidebar_form_fields['ee-msg-route'] = array(  | 
                                                        |
| 1537 | - 'name' => 'action',  | 
                                                        |
| 1538 | - 'input' => 'hidden',  | 
                                                        |
| 1539 | - 'type' => 'string',  | 
                                                        |
| 1540 | - 'value' => $action  | 
                                                        |
| 1541 | - );  | 
                                                        |
| 1536 | + $sidebar_form_fields['ee-msg-route'] = array(  | 
                                                        |
| 1537 | + 'name' => 'action',  | 
                                                        |
| 1538 | + 'input' => 'hidden',  | 
                                                        |
| 1539 | + 'type' => 'string',  | 
                                                        |
| 1540 | + 'value' => $action  | 
                                                        |
| 1541 | + );  | 
                                                        |
| 1542 | 1542 | |
| 1543 | - $sidebar_form_fields['ee-msg-id'] = array(  | 
                                                        |
| 1544 | - 'name' => 'id',  | 
                                                        |
| 1545 | - 'input' => 'hidden',  | 
                                                        |
| 1546 | - 'type' => 'int',  | 
                                                        |
| 1547 | - 'value' => $GRP_ID  | 
                                                        |
| 1548 | - );  | 
                                                        |
| 1549 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array(  | 
                                                        |
| 1550 | - 'name' => $action . '_nonce',  | 
                                                        |
| 1551 | - 'input' => 'hidden',  | 
                                                        |
| 1552 | - 'type' => 'string',  | 
                                                        |
| 1553 | - 'value' => wp_create_nonce($action . '_nonce')  | 
                                                        |
| 1554 | - );  | 
                                                        |
| 1543 | + $sidebar_form_fields['ee-msg-id'] = array(  | 
                                                        |
| 1544 | + 'name' => 'id',  | 
                                                        |
| 1545 | + 'input' => 'hidden',  | 
                                                        |
| 1546 | + 'type' => 'int',  | 
                                                        |
| 1547 | + 'value' => $GRP_ID  | 
                                                        |
| 1548 | + );  | 
                                                        |
| 1549 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array(  | 
                                                        |
| 1550 | + 'name' => $action . '_nonce',  | 
                                                        |
| 1551 | + 'input' => 'hidden',  | 
                                                        |
| 1552 | + 'type' => 'string',  | 
                                                        |
| 1553 | + 'value' => wp_create_nonce($action . '_nonce')  | 
                                                        |
| 1554 | + );  | 
                                                        |
| 1555 | 1555 | |
| 1556 | -            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { | 
                                                        |
| 1557 | - $sidebar_form_fields['ee-msg-template-switch'] = array(  | 
                                                        |
| 1558 | - 'name' => 'template_switch',  | 
                                                        |
| 1559 | - 'input' => 'hidden',  | 
                                                        |
| 1560 | - 'type' => 'int',  | 
                                                        |
| 1561 | - 'value' => 1  | 
                                                        |
| 1562 | - );  | 
                                                        |
| 1563 | - }  | 
                                                        |
| 1556 | +			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { | 
                                                        |
| 1557 | + $sidebar_form_fields['ee-msg-template-switch'] = array(  | 
                                                        |
| 1558 | + 'name' => 'template_switch',  | 
                                                        |
| 1559 | + 'input' => 'hidden',  | 
                                                        |
| 1560 | + 'type' => 'int',  | 
                                                        |
| 1561 | + 'value' => 1  | 
                                                        |
| 1562 | + );  | 
                                                        |
| 1563 | + }  | 
                                                        |
| 1564 | 1564 | |
| 1565 | 1565 | |
| 1566 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields);  | 
                                                        |
| 1567 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);  | 
                                                        |
| 1566 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields);  | 
                                                        |
| 1567 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);  | 
                                                        |
| 1568 | 1568 | |
| 1569 | 1569 | |
| 1570 | - } //end if ( !empty($template_field_structure) )  | 
                                                        |
| 1570 | + } //end if ( !empty($template_field_structure) )  | 
                                                        |
| 1571 | 1571 | |
| 1572 | - //set extra content for publish box  | 
                                                        |
| 1573 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields;  | 
                                                        |
| 1574 | - $this->_set_publish_post_box_vars(  | 
                                                        |
| 1575 | - 'id',  | 
                                                        |
| 1576 | - $GRP_ID,  | 
                                                        |
| 1577 | - false,  | 
                                                        |
| 1578 | - add_query_arg(  | 
                                                        |
| 1579 | -                array('action' => 'global_mtps'), | 
                                                        |
| 1580 | - $this->_admin_base_url  | 
                                                        |
| 1581 | - )  | 
                                                        |
| 1582 | - );  | 
                                                        |
| 1583 | -  | 
                                                        |
| 1584 | - //add preview button  | 
                                                        |
| 1585 | - $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1586 | - array(  | 
                                                        |
| 1587 | - 'message_type' => $message_template_group->message_type(),  | 
                                                        |
| 1588 | - 'messenger' => $message_template_group->messenger(),  | 
                                                        |
| 1589 | - 'context' => $context,  | 
                                                        |
| 1590 | - 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 1591 | - 'action' => 'preview_message'  | 
                                                        |
| 1592 | - ),  | 
                                                        |
| 1593 | - $this->_admin_base_url  | 
                                                        |
| 1594 | - );  | 
                                                        |
| 1595 | -        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', | 
                                                        |
| 1596 | - 'event_espresso') . '</a>';  | 
                                                        |
| 1597 | -  | 
                                                        |
| 1598 | -  | 
                                                        |
| 1599 | - //setup context switcher  | 
                                                        |
| 1600 | - $context_switcher_args = array(  | 
                                                        |
| 1601 | - 'page' => 'espresso_messages',  | 
                                                        |
| 1602 | - 'action' => 'edit_message_template',  | 
                                                        |
| 1603 | - 'id' => $GRP_ID,  | 
                                                        |
| 1604 | - 'context' => $context,  | 
                                                        |
| 1605 | - 'extra' => $preview_button  | 
                                                        |
| 1606 | - );  | 
                                                        |
| 1607 | - $this->_set_context_switcher($message_template_group, $context_switcher_args);  | 
                                                        |
| 1608 | -  | 
                                                        |
| 1609 | -  | 
                                                        |
| 1610 | - //main box  | 
                                                        |
| 1611 | - $this->_template_args['template_fields'] = $template_fields;  | 
                                                        |
| 1612 | - $this->_template_args['sidebar_box_id'] = 'details';  | 
                                                        |
| 1613 | - $this->_template_args['action'] = $action;  | 
                                                        |
| 1614 | - $this->_template_args['context'] = $context;  | 
                                                        |
| 1615 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;  | 
                                                        |
| 1616 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();  | 
                                                        |
| 1617 | -  | 
                                                        |
| 1618 | -  | 
                                                        |
| 1619 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();  | 
                                                        |
| 1620 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();  | 
                                                        |
| 1621 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1622 | -  | 
                                                        |
| 1623 | - $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        |
| 1624 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        |
| 1625 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1626 | -  | 
                                                        |
| 1627 | - //send along EE_Message_Template_Group object for further template use.  | 
                                                        |
| 1628 | - $this->_template_args['MTP'] = $message_template_group;  | 
                                                        |
| 1629 | -  | 
                                                        |
| 1630 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,  | 
                                                        |
| 1631 | - $this->_template_args, true);  | 
                                                        |
| 1632 | -  | 
                                                        |
| 1633 | -  | 
                                                        |
| 1634 | - //finally, let's set the admin_page title  | 
                                                        |
| 1635 | -        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); | 
                                                        |
| 1636 | -  | 
                                                        |
| 1637 | -  | 
                                                        |
| 1638 | - //we need to take care of setting the shortcodes property for use elsewhere.  | 
                                                        |
| 1639 | - $this->_set_shortcodes();  | 
                                                        |
| 1640 | -  | 
                                                        |
| 1641 | -  | 
                                                        |
| 1642 | - //final template wrapper  | 
                                                        |
| 1643 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1644 | - }  | 
                                                        |
| 1645 | -  | 
                                                        |
| 1646 | -  | 
                                                        |
| 1647 | - public function filter_tinymce_init($mceInit, $editor_id)  | 
                                                        |
| 1648 | -    { | 
                                                        |
| 1649 | - return $mceInit;  | 
                                                        |
| 1650 | - }  | 
                                                        |
| 1651 | -  | 
                                                        |
| 1652 | -  | 
                                                        |
| 1653 | - public function add_context_switcher()  | 
                                                        |
| 1654 | -    { | 
                                                        |
| 1655 | - return $this->_context_switcher;  | 
                                                        |
| 1656 | - }  | 
                                                        |
| 1657 | -  | 
                                                        |
| 1658 | - public function _add_form_element_before()  | 
                                                        |
| 1659 | -    { | 
                                                        |
| 1660 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';  | 
                                                        |
| 1661 | - }  | 
                                                        |
| 1662 | -  | 
                                                        |
| 1663 | - public function _add_form_element_after()  | 
                                                        |
| 1664 | -    { | 
                                                        |
| 1665 | - return '</form>';  | 
                                                        |
| 1666 | - }  | 
                                                        |
| 1667 | -  | 
                                                        |
| 1668 | -  | 
                                                        |
| 1669 | - /**  | 
                                                        |
| 1670 | - * This executes switching the template pack for a message template.  | 
                                                        |
| 1671 | - *  | 
                                                        |
| 1672 | - * @since 4.5.0  | 
                                                        |
| 1673 | - *  | 
                                                        |
| 1674 | - */  | 
                                                        |
| 1675 | - public function switch_template_pack()  | 
                                                        |
| 1676 | -    { | 
                                                        |
| 1677 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 1678 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';  | 
                                                        |
| 1679 | -  | 
                                                        |
| 1680 | - //verify we have needed values.  | 
                                                        |
| 1681 | -        if (empty($GRP_ID) || empty($template_pack)) { | 
                                                        |
| 1682 | - $this->_template_args['error'] = true;  | 
                                                        |
| 1683 | -            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), | 
                                                        |
| 1684 | - __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1685 | -        } else { | 
                                                        |
| 1686 | - //get template, set the new template_pack and then reset to default  | 
                                                        |
| 1687 | - /** @type EE_Message_Template_Group $message_template_group */  | 
                                                        |
| 1688 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 1572 | + //set extra content for publish box  | 
                                                        |
| 1573 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields;  | 
                                                        |
| 1574 | + $this->_set_publish_post_box_vars(  | 
                                                        |
| 1575 | + 'id',  | 
                                                        |
| 1576 | + $GRP_ID,  | 
                                                        |
| 1577 | + false,  | 
                                                        |
| 1578 | + add_query_arg(  | 
                                                        |
| 1579 | +				array('action' => 'global_mtps'), | 
                                                        |
| 1580 | + $this->_admin_base_url  | 
                                                        |
| 1581 | + )  | 
                                                        |
| 1582 | + );  | 
                                                        |
| 1583 | +  | 
                                                        |
| 1584 | + //add preview button  | 
                                                        |
| 1585 | + $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1586 | + array(  | 
                                                        |
| 1587 | + 'message_type' => $message_template_group->message_type(),  | 
                                                        |
| 1588 | + 'messenger' => $message_template_group->messenger(),  | 
                                                        |
| 1589 | + 'context' => $context,  | 
                                                        |
| 1590 | + 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 1591 | + 'action' => 'preview_message'  | 
                                                        |
| 1592 | + ),  | 
                                                        |
| 1593 | + $this->_admin_base_url  | 
                                                        |
| 1594 | + );  | 
                                                        |
| 1595 | +		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', | 
                                                        |
| 1596 | + 'event_espresso') . '</a>';  | 
                                                        |
| 1597 | +  | 
                                                        |
| 1598 | +  | 
                                                        |
| 1599 | + //setup context switcher  | 
                                                        |
| 1600 | + $context_switcher_args = array(  | 
                                                        |
| 1601 | + 'page' => 'espresso_messages',  | 
                                                        |
| 1602 | + 'action' => 'edit_message_template',  | 
                                                        |
| 1603 | + 'id' => $GRP_ID,  | 
                                                        |
| 1604 | + 'context' => $context,  | 
                                                        |
| 1605 | + 'extra' => $preview_button  | 
                                                        |
| 1606 | + );  | 
                                                        |
| 1607 | + $this->_set_context_switcher($message_template_group, $context_switcher_args);  | 
                                                        |
| 1608 | +  | 
                                                        |
| 1609 | +  | 
                                                        |
| 1610 | + //main box  | 
                                                        |
| 1611 | + $this->_template_args['template_fields'] = $template_fields;  | 
                                                        |
| 1612 | + $this->_template_args['sidebar_box_id'] = 'details';  | 
                                                        |
| 1613 | + $this->_template_args['action'] = $action;  | 
                                                        |
| 1614 | + $this->_template_args['context'] = $context;  | 
                                                        |
| 1615 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;  | 
                                                        |
| 1616 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();  | 
                                                        |
| 1617 | +  | 
                                                        |
| 1618 | +  | 
                                                        |
| 1619 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();  | 
                                                        |
| 1620 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();  | 
                                                        |
| 1621 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1622 | +  | 
                                                        |
| 1623 | + $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        |
| 1624 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        |
| 1625 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1626 | +  | 
                                                        |
| 1627 | + //send along EE_Message_Template_Group object for further template use.  | 
                                                        |
| 1628 | + $this->_template_args['MTP'] = $message_template_group;  | 
                                                        |
| 1629 | +  | 
                                                        |
| 1630 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,  | 
                                                        |
| 1631 | + $this->_template_args, true);  | 
                                                        |
| 1632 | +  | 
                                                        |
| 1633 | +  | 
                                                        |
| 1634 | + //finally, let's set the admin_page title  | 
                                                        |
| 1635 | +		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); | 
                                                        |
| 1636 | +  | 
                                                        |
| 1637 | +  | 
                                                        |
| 1638 | + //we need to take care of setting the shortcodes property for use elsewhere.  | 
                                                        |
| 1639 | + $this->_set_shortcodes();  | 
                                                        |
| 1640 | +  | 
                                                        |
| 1641 | +  | 
                                                        |
| 1642 | + //final template wrapper  | 
                                                        |
| 1643 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1644 | + }  | 
                                                        |
| 1645 | +  | 
                                                        |
| 1646 | +  | 
                                                        |
| 1647 | + public function filter_tinymce_init($mceInit, $editor_id)  | 
                                                        |
| 1648 | +	{ | 
                                                        |
| 1649 | + return $mceInit;  | 
                                                        |
| 1650 | + }  | 
                                                        |
| 1651 | +  | 
                                                        |
| 1652 | +  | 
                                                        |
| 1653 | + public function add_context_switcher()  | 
                                                        |
| 1654 | +	{ | 
                                                        |
| 1655 | + return $this->_context_switcher;  | 
                                                        |
| 1656 | + }  | 
                                                        |
| 1657 | +  | 
                                                        |
| 1658 | + public function _add_form_element_before()  | 
                                                        |
| 1659 | +	{ | 
                                                        |
| 1660 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';  | 
                                                        |
| 1661 | + }  | 
                                                        |
| 1662 | +  | 
                                                        |
| 1663 | + public function _add_form_element_after()  | 
                                                        |
| 1664 | +	{ | 
                                                        |
| 1665 | + return '</form>';  | 
                                                        |
| 1666 | + }  | 
                                                        |
| 1667 | +  | 
                                                        |
| 1668 | +  | 
                                                        |
| 1669 | + /**  | 
                                                        |
| 1670 | + * This executes switching the template pack for a message template.  | 
                                                        |
| 1671 | + *  | 
                                                        |
| 1672 | + * @since 4.5.0  | 
                                                        |
| 1673 | + *  | 
                                                        |
| 1674 | + */  | 
                                                        |
| 1675 | + public function switch_template_pack()  | 
                                                        |
| 1676 | +	{ | 
                                                        |
| 1677 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 1678 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';  | 
                                                        |
| 1679 | +  | 
                                                        |
| 1680 | + //verify we have needed values.  | 
                                                        |
| 1681 | +		if (empty($GRP_ID) || empty($template_pack)) { | 
                                                        |
| 1682 | + $this->_template_args['error'] = true;  | 
                                                        |
| 1683 | +			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), | 
                                                        |
| 1684 | + __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 1685 | +		} else { | 
                                                        |
| 1686 | + //get template, set the new template_pack and then reset to default  | 
                                                        |
| 1687 | + /** @type EE_Message_Template_Group $message_template_group */  | 
                                                        |
| 1688 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 1689 | 1689 | |
| 1690 | - $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 1691 | - $this->_req_data['msgr'] = $message_template_group->messenger();  | 
                                                        |
| 1692 | - $this->_req_data['mt'] = $message_template_group->message_type();  | 
                                                        |
| 1690 | + $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 1691 | + $this->_req_data['msgr'] = $message_template_group->messenger();  | 
                                                        |
| 1692 | + $this->_req_data['mt'] = $message_template_group->message_type();  | 
                                                        |
| 1693 | 1693 | |
| 1694 | - $query_args = $this->_reset_to_default_template();  | 
                                                        |
| 1694 | + $query_args = $this->_reset_to_default_template();  | 
                                                        |
| 1695 | 1695 | |
| 1696 | -            if (empty($query_args['id'])) { | 
                                                        |
| 1697 | - EE_Error::add_error(  | 
                                                        |
| 1698 | - __(  | 
                                                        |
| 1699 | - 'Something went wrong with switching the template pack. Please try again or contact EE support',  | 
                                                        |
| 1700 | - 'event_espresso'  | 
                                                        |
| 1701 | - ),  | 
                                                        |
| 1702 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1703 | - );  | 
                                                        |
| 1704 | - $this->_template_args['error'] = true;  | 
                                                        |
| 1705 | -            } else { | 
                                                        |
| 1706 | - $template_label = $message_template_group->get_template_pack()->label;  | 
                                                        |
| 1707 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 1708 | - EE_Error::add_success(  | 
                                                        |
| 1709 | - sprintf(  | 
                                                        |
| 1710 | - __(  | 
                                                        |
| 1711 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.',  | 
                                                        |
| 1712 | - 'event_espresso'  | 
                                                        |
| 1713 | - ),  | 
                                                        |
| 1714 | - $template_label,  | 
                                                        |
| 1715 | - $template_pack_labels->template_pack  | 
                                                        |
| 1716 | - )  | 
                                                        |
| 1717 | - );  | 
                                                        |
| 1718 | - //generate the redirect url for js.  | 
                                                        |
| 1719 | - $url = self::add_query_args_and_nonce($query_args,  | 
                                                        |
| 1720 | - $this->_admin_base_url);  | 
                                                        |
| 1721 | - $this->_template_args['data']['redirect_url'] = $url;  | 
                                                        |
| 1722 | - $this->_template_args['success'] = true;  | 
                                                        |
| 1723 | - }  | 
                                                        |
| 1696 | +			if (empty($query_args['id'])) { | 
                                                        |
| 1697 | + EE_Error::add_error(  | 
                                                        |
| 1698 | + __(  | 
                                                        |
| 1699 | + 'Something went wrong with switching the template pack. Please try again or contact EE support',  | 
                                                        |
| 1700 | + 'event_espresso'  | 
                                                        |
| 1701 | + ),  | 
                                                        |
| 1702 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1703 | + );  | 
                                                        |
| 1704 | + $this->_template_args['error'] = true;  | 
                                                        |
| 1705 | +			} else { | 
                                                        |
| 1706 | + $template_label = $message_template_group->get_template_pack()->label;  | 
                                                        |
| 1707 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 1708 | + EE_Error::add_success(  | 
                                                        |
| 1709 | + sprintf(  | 
                                                        |
| 1710 | + __(  | 
                                                        |
| 1711 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.',  | 
                                                        |
| 1712 | + 'event_espresso'  | 
                                                        |
| 1713 | + ),  | 
                                                        |
| 1714 | + $template_label,  | 
                                                        |
| 1715 | + $template_pack_labels->template_pack  | 
                                                        |
| 1716 | + )  | 
                                                        |
| 1717 | + );  | 
                                                        |
| 1718 | + //generate the redirect url for js.  | 
                                                        |
| 1719 | + $url = self::add_query_args_and_nonce($query_args,  | 
                                                        |
| 1720 | + $this->_admin_base_url);  | 
                                                        |
| 1721 | + $this->_template_args['data']['redirect_url'] = $url;  | 
                                                        |
| 1722 | + $this->_template_args['success'] = true;  | 
                                                        |
| 1723 | + }  | 
                                                        |
| 1724 | 1724 | |
| 1725 | - $this->_return_json();  | 
                                                        |
| 1725 | + $this->_return_json();  | 
                                                        |
| 1726 | 1726 | |
| 1727 | - }  | 
                                                        |
| 1728 | - }  | 
                                                        |
| 1729 | -  | 
                                                        |
| 1730 | -  | 
                                                        |
| 1731 | - /**  | 
                                                        |
| 1732 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if  | 
                                                        |
| 1733 | - * they want.  | 
                                                        |
| 1734 | - *  | 
                                                        |
| 1735 | - * @access protected  | 
                                                        |
| 1736 | - * @return array|null  | 
                                                        |
| 1737 | - */  | 
                                                        |
| 1738 | - protected function _reset_to_default_template()  | 
                                                        |
| 1739 | -    { | 
                                                        |
| 1740 | -  | 
                                                        |
| 1741 | - $templates = array();  | 
                                                        |
| 1742 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 1743 | - //we need to make sure we've got the info we need.  | 
                                                        |
| 1744 | -        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { | 
                                                        |
| 1745 | - EE_Error::add_error(  | 
                                                        |
| 1746 | - __(  | 
                                                        |
| 1747 | - '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.',  | 
                                                        |
| 1748 | - 'event_espresso'  | 
                                                        |
| 1749 | - ),  | 
                                                        |
| 1750 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1751 | - );  | 
                                                        |
| 1752 | - }  | 
                                                        |
| 1753 | -  | 
                                                        |
| 1754 | - // all templates will be reset to whatever the defaults are  | 
                                                        |
| 1755 | - // for the global template matching the messenger and message type.  | 
                                                        |
| 1756 | - $success = ! empty($GRP_ID) ? true : false;  | 
                                                        |
| 1757 | -  | 
                                                        |
| 1758 | -        if ($success) { | 
                                                        |
| 1727 | + }  | 
                                                        |
| 1728 | + }  | 
                                                        |
| 1729 | +  | 
                                                        |
| 1730 | +  | 
                                                        |
| 1731 | + /**  | 
                                                        |
| 1732 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if  | 
                                                        |
| 1733 | + * they want.  | 
                                                        |
| 1734 | + *  | 
                                                        |
| 1735 | + * @access protected  | 
                                                        |
| 1736 | + * @return array|null  | 
                                                        |
| 1737 | + */  | 
                                                        |
| 1738 | + protected function _reset_to_default_template()  | 
                                                        |
| 1739 | +	{ | 
                                                        |
| 1740 | +  | 
                                                        |
| 1741 | + $templates = array();  | 
                                                        |
| 1742 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 1743 | + //we need to make sure we've got the info we need.  | 
                                                        |
| 1744 | +		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { | 
                                                        |
| 1745 | + EE_Error::add_error(  | 
                                                        |
| 1746 | + __(  | 
                                                        |
| 1747 | + '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.',  | 
                                                        |
| 1748 | + 'event_espresso'  | 
                                                        |
| 1749 | + ),  | 
                                                        |
| 1750 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1751 | + );  | 
                                                        |
| 1752 | + }  | 
                                                        |
| 1753 | +  | 
                                                        |
| 1754 | + // all templates will be reset to whatever the defaults are  | 
                                                        |
| 1755 | + // for the global template matching the messenger and message type.  | 
                                                        |
| 1756 | + $success = ! empty($GRP_ID) ? true : false;  | 
                                                        |
| 1757 | +  | 
                                                        |
| 1758 | +		if ($success) { | 
                                                        |
| 1759 | 1759 | |
| 1760 | - //let's first determine if the incoming template is a global template,  | 
                                                        |
| 1761 | - // if it isn't then we need to get the global template matching messenger and message type.  | 
                                                        |
| 1762 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );  | 
                                                        |
| 1760 | + //let's first determine if the incoming template is a global template,  | 
                                                        |
| 1761 | + // if it isn't then we need to get the global template matching messenger and message type.  | 
                                                        |
| 1762 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );  | 
                                                        |
| 1763 | 1763 | |
| 1764 | 1764 | |
| 1765 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.  | 
                                                        |
| 1766 | - $success = $this->_delete_mtp_permanently($GRP_ID, false);  | 
                                                        |
| 1765 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.  | 
                                                        |
| 1766 | + $success = $this->_delete_mtp_permanently($GRP_ID, false);  | 
                                                        |
| 1767 | 1767 | |
| 1768 | -            if ($success) { | 
                                                        |
| 1769 | - // if successfully deleted, lets generate the new ones.  | 
                                                        |
| 1770 | - // Note. We set GLOBAL to true, because resets on ANY template  | 
                                                        |
| 1771 | - // will use the related global template defaults for regeneration.  | 
                                                        |
| 1772 | - // This means that if a custom template is reset it resets to whatever the related global template is.  | 
                                                        |
| 1773 | - // HOWEVER, we DO keep the template pack and template variation set  | 
                                                        |
| 1774 | - // for the current custom template when resetting.  | 
                                                        |
| 1775 | - $templates = $this->_generate_new_templates(  | 
                                                        |
| 1776 | - $this->_req_data['msgr'],  | 
                                                        |
| 1777 | - $this->_req_data['mt'],  | 
                                                        |
| 1778 | - $GRP_ID,  | 
                                                        |
| 1779 | - true  | 
                                                        |
| 1780 | - );  | 
                                                        |
| 1781 | - }  | 
                                                        |
| 1768 | +			if ($success) { | 
                                                        |
| 1769 | + // if successfully deleted, lets generate the new ones.  | 
                                                        |
| 1770 | + // Note. We set GLOBAL to true, because resets on ANY template  | 
                                                        |
| 1771 | + // will use the related global template defaults for regeneration.  | 
                                                        |
| 1772 | + // This means that if a custom template is reset it resets to whatever the related global template is.  | 
                                                        |
| 1773 | + // HOWEVER, we DO keep the template pack and template variation set  | 
                                                        |
| 1774 | + // for the current custom template when resetting.  | 
                                                        |
| 1775 | + $templates = $this->_generate_new_templates(  | 
                                                        |
| 1776 | + $this->_req_data['msgr'],  | 
                                                        |
| 1777 | + $this->_req_data['mt'],  | 
                                                        |
| 1778 | + $GRP_ID,  | 
                                                        |
| 1779 | + true  | 
                                                        |
| 1780 | + );  | 
                                                        |
| 1781 | + }  | 
                                                        |
| 1782 | 1782 | |
| 1783 | - }  | 
                                                        |
| 1784 | -  | 
                                                        |
| 1785 | - //any error messages?  | 
                                                        |
| 1786 | -        if ( ! $success) { | 
                                                        |
| 1787 | - EE_Error::add_error(  | 
                                                        |
| 1788 | -                __('Something went wrong with deleting existing templates. Unable to reset to default', | 
                                                        |
| 1789 | - 'event_espresso'),  | 
                                                        |
| 1790 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1791 | - );  | 
                                                        |
| 1792 | - }  | 
                                                        |
| 1793 | -  | 
                                                        |
| 1794 | - //all good, let's add a success message!  | 
                                                        |
| 1795 | -        if ($success && ! empty($templates)) { | 
                                                        |
| 1796 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.  | 
                                                        |
| 1797 | - EE_Error::overwrite_success();  | 
                                                        |
| 1798 | -            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); | 
                                                        |
| 1799 | - }  | 
                                                        |
| 1800 | -  | 
                                                        |
| 1801 | -  | 
                                                        |
| 1802 | - $query_args = array(  | 
                                                        |
| 1803 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,  | 
                                                        |
| 1804 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,  | 
                                                        |
| 1805 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'  | 
                                                        |
| 1806 | - );  | 
                                                        |
| 1807 | -  | 
                                                        |
| 1808 | - //if called via ajax then we return query args otherwise redirect  | 
                                                        |
| 1809 | -        if (defined('DOING_AJAX') && DOING_AJAX) { | 
                                                        |
| 1810 | - return $query_args;  | 
                                                        |
| 1811 | -        } else { | 
                                                        |
| 1812 | - $this->_redirect_after_action(false, '', '', $query_args, true);  | 
                                                        |
| 1783 | + }  | 
                                                        |
| 1784 | +  | 
                                                        |
| 1785 | + //any error messages?  | 
                                                        |
| 1786 | +		if ( ! $success) { | 
                                                        |
| 1787 | + EE_Error::add_error(  | 
                                                        |
| 1788 | +				__('Something went wrong with deleting existing templates. Unable to reset to default', | 
                                                        |
| 1789 | + 'event_espresso'),  | 
                                                        |
| 1790 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1791 | + );  | 
                                                        |
| 1792 | + }  | 
                                                        |
| 1793 | +  | 
                                                        |
| 1794 | + //all good, let's add a success message!  | 
                                                        |
| 1795 | +		if ($success && ! empty($templates)) { | 
                                                        |
| 1796 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.  | 
                                                        |
| 1797 | + EE_Error::overwrite_success();  | 
                                                        |
| 1798 | +			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); | 
                                                        |
| 1799 | + }  | 
                                                        |
| 1800 | +  | 
                                                        |
| 1801 | +  | 
                                                        |
| 1802 | + $query_args = array(  | 
                                                        |
| 1803 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,  | 
                                                        |
| 1804 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,  | 
                                                        |
| 1805 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'  | 
                                                        |
| 1806 | + );  | 
                                                        |
| 1807 | +  | 
                                                        |
| 1808 | + //if called via ajax then we return query args otherwise redirect  | 
                                                        |
| 1809 | +		if (defined('DOING_AJAX') && DOING_AJAX) { | 
                                                        |
| 1810 | + return $query_args;  | 
                                                        |
| 1811 | +		} else { | 
                                                        |
| 1812 | + $this->_redirect_after_action(false, '', '', $query_args, true);  | 
                                                        |
| 1813 | 1813 | |
| 1814 | - return null;  | 
                                                        |
| 1815 | - }  | 
                                                        |
| 1816 | - }  | 
                                                        |
| 1814 | + return null;  | 
                                                        |
| 1815 | + }  | 
                                                        |
| 1816 | + }  | 
                                                        |
| 1817 | 1817 | |
| 1818 | 1818 | |
| 1819 | - /**  | 
                                                        |
| 1820 | - * Retrieve and set the message preview for display.  | 
                                                        |
| 1821 | - *  | 
                                                        |
| 1822 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.  | 
                                                        |
| 1823 | - * @return string  | 
                                                        |
| 1824 | - * @throws EE_Error  | 
                                                        |
| 1825 | - */  | 
                                                        |
| 1826 | - public function _preview_message($send = false)  | 
                                                        |
| 1827 | -    { | 
                                                        |
| 1828 | - //first make sure we've got the necessary parameters  | 
                                                        |
| 1829 | - if (  | 
                                                        |
| 1830 | - ! isset(  | 
                                                        |
| 1831 | - $this->_req_data['message_type'],  | 
                                                        |
| 1832 | - $this->_req_data['messenger'],  | 
                                                        |
| 1833 | - $this->_req_data['messenger'],  | 
                                                        |
| 1834 | - $this->_req_data['GRP_ID']  | 
                                                        |
| 1835 | - )  | 
                                                        |
| 1836 | -        ) { | 
                                                        |
| 1837 | - EE_Error::add_error(  | 
                                                        |
| 1838 | -                __('Missing necessary parameters for displaying preview', 'event_espresso'), | 
                                                        |
| 1839 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1840 | - );  | 
                                                        |
| 1841 | - }  | 
                                                        |
| 1842 | -  | 
                                                        |
| 1843 | -        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); | 
                                                        |
| 1844 | -  | 
                                                        |
| 1845 | -  | 
                                                        |
| 1846 | - //get the preview!  | 
                                                        |
| 1847 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],  | 
                                                        |
| 1848 | - $this->_req_data['messenger'], $send);  | 
                                                        |
| 1849 | -  | 
                                                        |
| 1850 | -        if ($send) { | 
                                                        |
| 1851 | - return $preview;  | 
                                                        |
| 1852 | - }  | 
                                                        |
| 1853 | -  | 
                                                        |
| 1854 | - //let's add a button to go back to the edit view  | 
                                                        |
| 1855 | - $query_args = array(  | 
                                                        |
| 1856 | - 'id' => $this->_req_data['GRP_ID'],  | 
                                                        |
| 1857 | - 'context' => $this->_req_data['context'],  | 
                                                        |
| 1858 | - 'action' => 'edit_message_template'  | 
                                                        |
| 1859 | - );  | 
                                                        |
| 1860 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 1861 | -        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', | 
                                                        |
| 1862 | - 'event_espresso') . '</a>';  | 
                                                        |
| 1863 | - $message_types = $this->get_installed_message_types();  | 
                                                        |
| 1864 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 1865 | - $active_messenger_label = $active_messenger instanceof EE_messenger  | 
                                                        |
| 1866 | - ? ucwords($active_messenger->label['singular'])  | 
                                                        |
| 1867 | -            : esc_html__('Unknown Messenger', 'event_espresso'); | 
                                                        |
| 1868 | - //let's provide a helpful title for context  | 
                                                        |
| 1869 | - $preview_title = sprintf(  | 
                                                        |
| 1870 | -            __('Viewing Preview for %s %s Message Template', 'event_espresso'), | 
                                                        |
| 1871 | - $active_messenger_label,  | 
                                                        |
| 1872 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular'])  | 
                                                        |
| 1873 | - );  | 
                                                        |
| 1874 | - //setup display of preview.  | 
                                                        |
| 1875 | - $this->_admin_page_title = $preview_title;  | 
                                                        |
| 1876 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);  | 
                                                        |
| 1877 | - $this->_template_args['data']['force_json'] = true;  | 
                                                        |
| 1878 | -  | 
                                                        |
| 1879 | - return '';  | 
                                                        |
| 1880 | - }  | 
                                                        |
| 1881 | -  | 
                                                        |
| 1882 | -  | 
                                                        |
| 1883 | - /**  | 
                                                        |
| 1884 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it  | 
                                                        |
| 1885 | - * gets called automatically.  | 
                                                        |
| 1886 | - *  | 
                                                        |
| 1887 | - * @since 4.5.0  | 
                                                        |
| 1888 | - *  | 
                                                        |
| 1889 | - * @return string  | 
                                                        |
| 1890 | - */  | 
                                                        |
| 1891 | - protected function _display_preview_message()  | 
                                                        |
| 1892 | -    { | 
                                                        |
| 1893 | - $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 1894 | - }  | 
                                                        |
| 1895 | -  | 
                                                        |
| 1896 | -  | 
                                                        |
| 1897 | - /**  | 
                                                        |
| 1898 | - * registers metaboxes that should show up on the "edit_message_template" page  | 
                                                        |
| 1899 | - *  | 
                                                        |
| 1900 | - * @access protected  | 
                                                        |
| 1901 | - * @return void  | 
                                                        |
| 1902 | - */  | 
                                                        |
| 1903 | - protected function _register_edit_meta_boxes()  | 
                                                        |
| 1904 | -    { | 
                                                        |
| 1905 | -        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), | 
                                                        |
| 1906 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');  | 
                                                        |
| 1907 | -        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), | 
                                                        |
| 1908 | - $this->_current_screen->id, 'side', 'high');  | 
                                                        |
| 1909 | -        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), | 
                                                        |
| 1910 | - $this->_current_screen->id, 'side', 'high');  | 
                                                        |
| 1911 | - }  | 
                                                        |
| 1912 | -  | 
                                                        |
| 1913 | -  | 
                                                        |
| 1914 | - /**  | 
                                                        |
| 1915 | - * metabox content for all template pack and variation selection.  | 
                                                        |
| 1916 | - *  | 
                                                        |
| 1917 | - * @since 4.5.0  | 
                                                        |
| 1918 | - *  | 
                                                        |
| 1919 | - * @return string  | 
                                                        |
| 1920 | - */  | 
                                                        |
| 1921 | - public function template_pack_meta_box()  | 
                                                        |
| 1922 | -    { | 
                                                        |
| 1923 | - $this->_set_message_template_group();  | 
                                                        |
| 1924 | -  | 
                                                        |
| 1925 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 1926 | -  | 
                                                        |
| 1927 | - $tp_select_values = array();  | 
                                                        |
| 1928 | -  | 
                                                        |
| 1929 | -        foreach ($tp_collection as $tp) { | 
                                                        |
| 1930 | - //only include template packs that support this messenger and message type!  | 
                                                        |
| 1931 | - $supports = $tp->get_supports();  | 
                                                        |
| 1932 | - if (  | 
                                                        |
| 1933 | - ! isset($supports[$this->_message_template_group->messenger()])  | 
                                                        |
| 1934 | - || ! in_array(  | 
                                                        |
| 1935 | - $this->_message_template_group->message_type(),  | 
                                                        |
| 1936 | - $supports[$this->_message_template_group->messenger()]  | 
                                                        |
| 1937 | - )  | 
                                                        |
| 1938 | -            ) { | 
                                                        |
| 1939 | - //not supported  | 
                                                        |
| 1940 | - continue;  | 
                                                        |
| 1941 | - }  | 
                                                        |
| 1819 | + /**  | 
                                                        |
| 1820 | + * Retrieve and set the message preview for display.  | 
                                                        |
| 1821 | + *  | 
                                                        |
| 1822 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.  | 
                                                        |
| 1823 | + * @return string  | 
                                                        |
| 1824 | + * @throws EE_Error  | 
                                                        |
| 1825 | + */  | 
                                                        |
| 1826 | + public function _preview_message($send = false)  | 
                                                        |
| 1827 | +	{ | 
                                                        |
| 1828 | + //first make sure we've got the necessary parameters  | 
                                                        |
| 1829 | + if (  | 
                                                        |
| 1830 | + ! isset(  | 
                                                        |
| 1831 | + $this->_req_data['message_type'],  | 
                                                        |
| 1832 | + $this->_req_data['messenger'],  | 
                                                        |
| 1833 | + $this->_req_data['messenger'],  | 
                                                        |
| 1834 | + $this->_req_data['GRP_ID']  | 
                                                        |
| 1835 | + )  | 
                                                        |
| 1836 | +		) { | 
                                                        |
| 1837 | + EE_Error::add_error(  | 
                                                        |
| 1838 | +				__('Missing necessary parameters for displaying preview', 'event_espresso'), | 
                                                        |
| 1839 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 1840 | + );  | 
                                                        |
| 1841 | + }  | 
                                                        |
| 1842 | +  | 
                                                        |
| 1843 | +		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); | 
                                                        |
| 1844 | +  | 
                                                        |
| 1845 | +  | 
                                                        |
| 1846 | + //get the preview!  | 
                                                        |
| 1847 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],  | 
                                                        |
| 1848 | + $this->_req_data['messenger'], $send);  | 
                                                        |
| 1849 | +  | 
                                                        |
| 1850 | +		if ($send) { | 
                                                        |
| 1851 | + return $preview;  | 
                                                        |
| 1852 | + }  | 
                                                        |
| 1853 | +  | 
                                                        |
| 1854 | + //let's add a button to go back to the edit view  | 
                                                        |
| 1855 | + $query_args = array(  | 
                                                        |
| 1856 | + 'id' => $this->_req_data['GRP_ID'],  | 
                                                        |
| 1857 | + 'context' => $this->_req_data['context'],  | 
                                                        |
| 1858 | + 'action' => 'edit_message_template'  | 
                                                        |
| 1859 | + );  | 
                                                        |
| 1860 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 1861 | +		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', | 
                                                        |
| 1862 | + 'event_espresso') . '</a>';  | 
                                                        |
| 1863 | + $message_types = $this->get_installed_message_types();  | 
                                                        |
| 1864 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 1865 | + $active_messenger_label = $active_messenger instanceof EE_messenger  | 
                                                        |
| 1866 | + ? ucwords($active_messenger->label['singular'])  | 
                                                        |
| 1867 | +			: esc_html__('Unknown Messenger', 'event_espresso'); | 
                                                        |
| 1868 | + //let's provide a helpful title for context  | 
                                                        |
| 1869 | + $preview_title = sprintf(  | 
                                                        |
| 1870 | +			__('Viewing Preview for %s %s Message Template', 'event_espresso'), | 
                                                        |
| 1871 | + $active_messenger_label,  | 
                                                        |
| 1872 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular'])  | 
                                                        |
| 1873 | + );  | 
                                                        |
| 1874 | + //setup display of preview.  | 
                                                        |
| 1875 | + $this->_admin_page_title = $preview_title;  | 
                                                        |
| 1876 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);  | 
                                                        |
| 1877 | + $this->_template_args['data']['force_json'] = true;  | 
                                                        |
| 1878 | +  | 
                                                        |
| 1879 | + return '';  | 
                                                        |
| 1880 | + }  | 
                                                        |
| 1881 | +  | 
                                                        |
| 1882 | +  | 
                                                        |
| 1883 | + /**  | 
                                                        |
| 1884 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it  | 
                                                        |
| 1885 | + * gets called automatically.  | 
                                                        |
| 1886 | + *  | 
                                                        |
| 1887 | + * @since 4.5.0  | 
                                                        |
| 1888 | + *  | 
                                                        |
| 1889 | + * @return string  | 
                                                        |
| 1890 | + */  | 
                                                        |
| 1891 | + protected function _display_preview_message()  | 
                                                        |
| 1892 | +	{ | 
                                                        |
| 1893 | + $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 1894 | + }  | 
                                                        |
| 1895 | +  | 
                                                        |
| 1896 | +  | 
                                                        |
| 1897 | + /**  | 
                                                        |
| 1898 | + * registers metaboxes that should show up on the "edit_message_template" page  | 
                                                        |
| 1899 | + *  | 
                                                        |
| 1900 | + * @access protected  | 
                                                        |
| 1901 | + * @return void  | 
                                                        |
| 1902 | + */  | 
                                                        |
| 1903 | + protected function _register_edit_meta_boxes()  | 
                                                        |
| 1904 | +	{ | 
                                                        |
| 1905 | +		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), | 
                                                        |
| 1906 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');  | 
                                                        |
| 1907 | +		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), | 
                                                        |
| 1908 | + $this->_current_screen->id, 'side', 'high');  | 
                                                        |
| 1909 | +		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), | 
                                                        |
| 1910 | + $this->_current_screen->id, 'side', 'high');  | 
                                                        |
| 1911 | + }  | 
                                                        |
| 1912 | +  | 
                                                        |
| 1913 | +  | 
                                                        |
| 1914 | + /**  | 
                                                        |
| 1915 | + * metabox content for all template pack and variation selection.  | 
                                                        |
| 1916 | + *  | 
                                                        |
| 1917 | + * @since 4.5.0  | 
                                                        |
| 1918 | + *  | 
                                                        |
| 1919 | + * @return string  | 
                                                        |
| 1920 | + */  | 
                                                        |
| 1921 | + public function template_pack_meta_box()  | 
                                                        |
| 1922 | +	{ | 
                                                        |
| 1923 | + $this->_set_message_template_group();  | 
                                                        |
| 1924 | +  | 
                                                        |
| 1925 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 1926 | +  | 
                                                        |
| 1927 | + $tp_select_values = array();  | 
                                                        |
| 1928 | +  | 
                                                        |
| 1929 | +		foreach ($tp_collection as $tp) { | 
                                                        |
| 1930 | + //only include template packs that support this messenger and message type!  | 
                                                        |
| 1931 | + $supports = $tp->get_supports();  | 
                                                        |
| 1932 | + if (  | 
                                                        |
| 1933 | + ! isset($supports[$this->_message_template_group->messenger()])  | 
                                                        |
| 1934 | + || ! in_array(  | 
                                                        |
| 1935 | + $this->_message_template_group->message_type(),  | 
                                                        |
| 1936 | + $supports[$this->_message_template_group->messenger()]  | 
                                                        |
| 1937 | + )  | 
                                                        |
| 1938 | +			) { | 
                                                        |
| 1939 | + //not supported  | 
                                                        |
| 1940 | + continue;  | 
                                                        |
| 1941 | + }  | 
                                                        |
| 1942 | 1942 | |
| 1943 | - $tp_select_values[] = array(  | 
                                                        |
| 1944 | - 'text' => $tp->label,  | 
                                                        |
| 1945 | - 'id' => $tp->dbref  | 
                                                        |
| 1946 | - );  | 
                                                        |
| 1947 | - }  | 
                                                        |
| 1948 | -  | 
                                                        |
| 1949 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override.  | 
                                                        |
| 1950 | -        if (empty($tp_select_values)) { | 
                                                        |
| 1951 | - $tp_select_values[] = array(  | 
                                                        |
| 1952 | -                'text' => __('Default', 'event_espresso'), | 
                                                        |
| 1953 | - 'id' => 'default'  | 
                                                        |
| 1954 | - );  | 
                                                        |
| 1955 | - }  | 
                                                        |
| 1956 | -  | 
                                                        |
| 1957 | - //setup variation select values for the currently selected template.  | 
                                                        |
| 1958 | - $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 1959 | - $this->_message_template_group->messenger(),  | 
                                                        |
| 1960 | - $this->_message_template_group->message_type()  | 
                                                        |
| 1961 | - );  | 
                                                        |
| 1962 | - $variations_select_values = array();  | 
                                                        |
| 1963 | -        foreach ($variations as $variation => $label) { | 
                                                        |
| 1964 | - $variations_select_values[] = array(  | 
                                                        |
| 1965 | - 'text' => $label,  | 
                                                        |
| 1966 | - 'id' => $variation  | 
                                                        |
| 1967 | - );  | 
                                                        |
| 1968 | - }  | 
                                                        |
| 1969 | -  | 
                                                        |
| 1970 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 1971 | -  | 
                                                        |
| 1972 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1973 | - 'MTP_template_pack',  | 
                                                        |
| 1974 | - $tp_select_values,  | 
                                                        |
| 1975 | - $this->_message_template_group->get_template_pack_name()  | 
                                                        |
| 1976 | - );  | 
                                                        |
| 1977 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1978 | - 'MTP_template_variation',  | 
                                                        |
| 1979 | - $variations_select_values,  | 
                                                        |
| 1980 | - $this->_message_template_group->get_template_pack_variation()  | 
                                                        |
| 1981 | - );  | 
                                                        |
| 1982 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack;  | 
                                                        |
| 1983 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation;  | 
                                                        |
| 1984 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        |
| 1985 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        |
| 1986 | -  | 
                                                        |
| 1987 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 1988 | -  | 
                                                        |
| 1989 | - EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 1990 | - }  | 
                                                        |
| 1991 | -  | 
                                                        |
| 1992 | -  | 
                                                        |
| 1993 | - /**  | 
                                                        |
| 1994 | - * This meta box holds any extra actions related to Message Templates  | 
                                                        |
| 1995 | - * For now, this includes Resetting templates to defaults and sending a test email.  | 
                                                        |
| 1996 | - *  | 
                                                        |
| 1997 | - * @access public  | 
                                                        |
| 1998 | - * @return void  | 
                                                        |
| 1999 | - * @throws \EE_Error  | 
                                                        |
| 2000 | - */  | 
                                                        |
| 2001 | - public function extra_actions_meta_box()  | 
                                                        |
| 2002 | -    { | 
                                                        |
| 2003 | - $template_form_fields = array();  | 
                                                        |
| 2004 | -  | 
                                                        |
| 2005 | - $extra_args = array(  | 
                                                        |
| 2006 | - 'msgr' => $this->_message_template_group->messenger(),  | 
                                                        |
| 2007 | - 'mt' => $this->_message_template_group->message_type(),  | 
                                                        |
| 2008 | - 'GRP_ID' => $this->_message_template_group->GRP_ID()  | 
                                                        |
| 2009 | - );  | 
                                                        |
| 2010 | - //first we need to see if there are any fields  | 
                                                        |
| 2011 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();  | 
                                                        |
| 2012 | -  | 
                                                        |
| 2013 | -        if ( ! empty($fields)) { | 
                                                        |
| 2014 | - //yup there be fields  | 
                                                        |
| 2015 | -            foreach ($fields as $field => $config) { | 
                                                        |
| 2016 | - $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2017 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        |
| 2018 | - $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        |
| 2019 | - $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        |
| 1943 | + $tp_select_values[] = array(  | 
                                                        |
| 1944 | + 'text' => $tp->label,  | 
                                                        |
| 1945 | + 'id' => $tp->dbref  | 
                                                        |
| 1946 | + );  | 
                                                        |
| 1947 | + }  | 
                                                        |
| 1948 | +  | 
                                                        |
| 1949 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override.  | 
                                                        |
| 1950 | +		if (empty($tp_select_values)) { | 
                                                        |
| 1951 | + $tp_select_values[] = array(  | 
                                                        |
| 1952 | +				'text' => __('Default', 'event_espresso'), | 
                                                        |
| 1953 | + 'id' => 'default'  | 
                                                        |
| 1954 | + );  | 
                                                        |
| 1955 | + }  | 
                                                        |
| 1956 | +  | 
                                                        |
| 1957 | + //setup variation select values for the currently selected template.  | 
                                                        |
| 1958 | + $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 1959 | + $this->_message_template_group->messenger(),  | 
                                                        |
| 1960 | + $this->_message_template_group->message_type()  | 
                                                        |
| 1961 | + );  | 
                                                        |
| 1962 | + $variations_select_values = array();  | 
                                                        |
| 1963 | +		foreach ($variations as $variation => $label) { | 
                                                        |
| 1964 | + $variations_select_values[] = array(  | 
                                                        |
| 1965 | + 'text' => $label,  | 
                                                        |
| 1966 | + 'id' => $variation  | 
                                                        |
| 1967 | + );  | 
                                                        |
| 1968 | + }  | 
                                                        |
| 1969 | +  | 
                                                        |
| 1970 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 1971 | +  | 
                                                        |
| 1972 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1973 | + 'MTP_template_pack',  | 
                                                        |
| 1974 | + $tp_select_values,  | 
                                                        |
| 1975 | + $this->_message_template_group->get_template_pack_name()  | 
                                                        |
| 1976 | + );  | 
                                                        |
| 1977 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1978 | + 'MTP_template_variation',  | 
                                                        |
| 1979 | + $variations_select_values,  | 
                                                        |
| 1980 | + $this->_message_template_group->get_template_pack_variation()  | 
                                                        |
| 1981 | + );  | 
                                                        |
| 1982 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack;  | 
                                                        |
| 1983 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation;  | 
                                                        |
| 1984 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        |
| 1985 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        |
| 1986 | +  | 
                                                        |
| 1987 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 1988 | +  | 
                                                        |
| 1989 | + EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 1990 | + }  | 
                                                        |
| 1991 | +  | 
                                                        |
| 1992 | +  | 
                                                        |
| 1993 | + /**  | 
                                                        |
| 1994 | + * This meta box holds any extra actions related to Message Templates  | 
                                                        |
| 1995 | + * For now, this includes Resetting templates to defaults and sending a test email.  | 
                                                        |
| 1996 | + *  | 
                                                        |
| 1997 | + * @access public  | 
                                                        |
| 1998 | + * @return void  | 
                                                        |
| 1999 | + * @throws \EE_Error  | 
                                                        |
| 2000 | + */  | 
                                                        |
| 2001 | + public function extra_actions_meta_box()  | 
                                                        |
| 2002 | +	{ | 
                                                        |
| 2003 | + $template_form_fields = array();  | 
                                                        |
| 2004 | +  | 
                                                        |
| 2005 | + $extra_args = array(  | 
                                                        |
| 2006 | + 'msgr' => $this->_message_template_group->messenger(),  | 
                                                        |
| 2007 | + 'mt' => $this->_message_template_group->message_type(),  | 
                                                        |
| 2008 | + 'GRP_ID' => $this->_message_template_group->GRP_ID()  | 
                                                        |
| 2009 | + );  | 
                                                        |
| 2010 | + //first we need to see if there are any fields  | 
                                                        |
| 2011 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();  | 
                                                        |
| 2012 | +  | 
                                                        |
| 2013 | +		if ( ! empty($fields)) { | 
                                                        |
| 2014 | + //yup there be fields  | 
                                                        |
| 2015 | +			foreach ($fields as $field => $config) { | 
                                                        |
| 2016 | + $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2017 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        |
| 2018 | + $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        |
| 2019 | + $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        |
| 2020 | 2020 | |
| 2021 | - // if type is hidden and the value is empty  | 
                                                        |
| 2022 | - // something may have gone wrong so let's correct with the defaults  | 
                                                        |
| 2023 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])  | 
                                                        |
| 2024 | - ? $default  | 
                                                        |
| 2025 | - : '';  | 
                                                        |
| 2026 | - $existing[$field] = isset($existing[$field]) && empty($fix)  | 
                                                        |
| 2027 | - ? $existing[$field]  | 
                                                        |
| 2028 | - : $fix;  | 
                                                        |
| 2021 | + // if type is hidden and the value is empty  | 
                                                        |
| 2022 | + // something may have gone wrong so let's correct with the defaults  | 
                                                        |
| 2023 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])  | 
                                                        |
| 2024 | + ? $default  | 
                                                        |
| 2025 | + : '';  | 
                                                        |
| 2026 | + $existing[$field] = isset($existing[$field]) && empty($fix)  | 
                                                        |
| 2027 | + ? $existing[$field]  | 
                                                        |
| 2028 | + : $fix;  | 
                                                        |
| 2029 | 2029 | |
| 2030 | - $template_form_fields[$field_id] = array(  | 
                                                        |
| 2031 | - 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2032 | - 'label' => $config['label'],  | 
                                                        |
| 2033 | - 'input' => $config['input'],  | 
                                                        |
| 2034 | - 'type' => $config['type'],  | 
                                                        |
| 2035 | - 'required' => $config['required'],  | 
                                                        |
| 2036 | - 'validation' => $config['validation'],  | 
                                                        |
| 2037 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default,  | 
                                                        |
| 2038 | - 'css_class' => $config['css_class'],  | 
                                                        |
| 2039 | - 'options' => isset($config['options']) ? $config['options'] : array(),  | 
                                                        |
| 2040 | - 'default' => $default,  | 
                                                        |
| 2041 | - 'format' => $config['format']  | 
                                                        |
| 2042 | - );  | 
                                                        |
| 2043 | - }  | 
                                                        |
| 2044 | - }  | 
                                                        |
| 2045 | -  | 
                                                        |
| 2046 | - $test_settings_fields = ! empty($template_form_fields)  | 
                                                        |
| 2047 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')  | 
                                                        |
| 2048 | - : '';  | 
                                                        |
| 2049 | -  | 
                                                        |
| 2050 | - $test_settings_html = '';  | 
                                                        |
| 2051 | - //print out $test_settings_fields  | 
                                                        |
| 2052 | -        if ( ! empty($test_settings_fields)) { | 
                                                        |
| 2053 | - echo $test_settings_fields;  | 
                                                        |
| 2054 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';  | 
                                                        |
| 2055 | - $test_settings_html .= 'name="test_button" value="';  | 
                                                        |
| 2056 | -            $test_settings_html .= __('Test Send', 'event_espresso'); | 
                                                        |
| 2057 | - $test_settings_html .= '" /><div style="clear:both"></div>';  | 
                                                        |
| 2058 | - }  | 
                                                        |
| 2059 | -  | 
                                                        |
| 2060 | - //and button  | 
                                                        |
| 2061 | -        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; | 
                                                        |
| 2062 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">';  | 
                                                        |
| 2063 | - $test_settings_html .= $this->get_action_link_or_button(  | 
                                                        |
| 2064 | - 'reset_to_default',  | 
                                                        |
| 2065 | - 'reset',  | 
                                                        |
| 2066 | - $extra_args,  | 
                                                        |
| 2067 | - 'button-primary reset-default-button'  | 
                                                        |
| 2068 | - );  | 
                                                        |
| 2069 | - $test_settings_html .= '</div><div style="clear:both"></div>';  | 
                                                        |
| 2070 | - echo $test_settings_html;  | 
                                                        |
| 2071 | - }  | 
                                                        |
| 2072 | -  | 
                                                        |
| 2073 | -  | 
                                                        |
| 2074 | - /**  | 
                                                        |
| 2075 | - * This returns the shortcode selector skeleton for a given context and field.  | 
                                                        |
| 2076 | - *  | 
                                                        |
| 2077 | - * @since 4.9.rc.000  | 
                                                        |
| 2078 | - *  | 
                                                        |
| 2079 | - * @param string $field The name of the field retrieving shortcodes for.  | 
                                                        |
| 2080 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to.  | 
                                                        |
| 2081 | - *  | 
                                                        |
| 2082 | - * @return string  | 
                                                        |
| 2083 | - */  | 
                                                        |
| 2084 | - protected function _get_shortcode_selector($field, $linked_input_id)  | 
                                                        |
| 2085 | -    { | 
                                                        |
| 2086 | - $template_args = array(  | 
                                                        |
| 2087 | - 'shortcodes' => $this->_get_shortcodes(array($field), true),  | 
                                                        |
| 2088 | - 'fieldname' => $field,  | 
                                                        |
| 2089 | - 'linked_input_id' => $linked_input_id  | 
                                                        |
| 2090 | - );  | 
                                                        |
| 2091 | -  | 
                                                        |
| 2092 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2093 | - $template_args, true);  | 
                                                        |
| 2094 | - }  | 
                                                        |
| 2095 | -  | 
                                                        |
| 2096 | -  | 
                                                        |
| 2097 | - /**  | 
                                                        |
| 2098 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template  | 
                                                        |
| 2099 | - * page)  | 
                                                        |
| 2100 | - *  | 
                                                        |
| 2101 | - * @access public  | 
                                                        |
| 2102 | - * @return void  | 
                                                        |
| 2103 | - */  | 
                                                        |
| 2104 | - public function shortcode_meta_box()  | 
                                                        |
| 2105 | -    { | 
                                                        |
| 2106 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set  | 
                                                        |
| 2107 | - //$messenger = $this->_message_template_group->messenger_obj();  | 
                                                        |
| 2108 | - //now let's set the content depending on the status of the shortcodes array  | 
                                                        |
| 2109 | -        if (empty($shortcodes)) { | 
                                                        |
| 2110 | -            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2111 | - echo $content;  | 
                                                        |
| 2112 | -        } else { | 
                                                        |
| 2113 | - //$alt = 0;  | 
                                                        |
| 2114 | - ?>  | 
                                                        |
| 2030 | + $template_form_fields[$field_id] = array(  | 
                                                        |
| 2031 | + 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2032 | + 'label' => $config['label'],  | 
                                                        |
| 2033 | + 'input' => $config['input'],  | 
                                                        |
| 2034 | + 'type' => $config['type'],  | 
                                                        |
| 2035 | + 'required' => $config['required'],  | 
                                                        |
| 2036 | + 'validation' => $config['validation'],  | 
                                                        |
| 2037 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default,  | 
                                                        |
| 2038 | + 'css_class' => $config['css_class'],  | 
                                                        |
| 2039 | + 'options' => isset($config['options']) ? $config['options'] : array(),  | 
                                                        |
| 2040 | + 'default' => $default,  | 
                                                        |
| 2041 | + 'format' => $config['format']  | 
                                                        |
| 2042 | + );  | 
                                                        |
| 2043 | + }  | 
                                                        |
| 2044 | + }  | 
                                                        |
| 2045 | +  | 
                                                        |
| 2046 | + $test_settings_fields = ! empty($template_form_fields)  | 
                                                        |
| 2047 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')  | 
                                                        |
| 2048 | + : '';  | 
                                                        |
| 2049 | +  | 
                                                        |
| 2050 | + $test_settings_html = '';  | 
                                                        |
| 2051 | + //print out $test_settings_fields  | 
                                                        |
| 2052 | +		if ( ! empty($test_settings_fields)) { | 
                                                        |
| 2053 | + echo $test_settings_fields;  | 
                                                        |
| 2054 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';  | 
                                                        |
| 2055 | + $test_settings_html .= 'name="test_button" value="';  | 
                                                        |
| 2056 | +			$test_settings_html .= __('Test Send', 'event_espresso'); | 
                                                        |
| 2057 | + $test_settings_html .= '" /><div style="clear:both"></div>';  | 
                                                        |
| 2058 | + }  | 
                                                        |
| 2059 | +  | 
                                                        |
| 2060 | + //and button  | 
                                                        |
| 2061 | +		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; | 
                                                        |
| 2062 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">';  | 
                                                        |
| 2063 | + $test_settings_html .= $this->get_action_link_or_button(  | 
                                                        |
| 2064 | + 'reset_to_default',  | 
                                                        |
| 2065 | + 'reset',  | 
                                                        |
| 2066 | + $extra_args,  | 
                                                        |
| 2067 | + 'button-primary reset-default-button'  | 
                                                        |
| 2068 | + );  | 
                                                        |
| 2069 | + $test_settings_html .= '</div><div style="clear:both"></div>';  | 
                                                        |
| 2070 | + echo $test_settings_html;  | 
                                                        |
| 2071 | + }  | 
                                                        |
| 2072 | +  | 
                                                        |
| 2073 | +  | 
                                                        |
| 2074 | + /**  | 
                                                        |
| 2075 | + * This returns the shortcode selector skeleton for a given context and field.  | 
                                                        |
| 2076 | + *  | 
                                                        |
| 2077 | + * @since 4.9.rc.000  | 
                                                        |
| 2078 | + *  | 
                                                        |
| 2079 | + * @param string $field The name of the field retrieving shortcodes for.  | 
                                                        |
| 2080 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to.  | 
                                                        |
| 2081 | + *  | 
                                                        |
| 2082 | + * @return string  | 
                                                        |
| 2083 | + */  | 
                                                        |
| 2084 | + protected function _get_shortcode_selector($field, $linked_input_id)  | 
                                                        |
| 2085 | +	{ | 
                                                        |
| 2086 | + $template_args = array(  | 
                                                        |
| 2087 | + 'shortcodes' => $this->_get_shortcodes(array($field), true),  | 
                                                        |
| 2088 | + 'fieldname' => $field,  | 
                                                        |
| 2089 | + 'linked_input_id' => $linked_input_id  | 
                                                        |
| 2090 | + );  | 
                                                        |
| 2091 | +  | 
                                                        |
| 2092 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2093 | + $template_args, true);  | 
                                                        |
| 2094 | + }  | 
                                                        |
| 2095 | +  | 
                                                        |
| 2096 | +  | 
                                                        |
| 2097 | + /**  | 
                                                        |
| 2098 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template  | 
                                                        |
| 2099 | + * page)  | 
                                                        |
| 2100 | + *  | 
                                                        |
| 2101 | + * @access public  | 
                                                        |
| 2102 | + * @return void  | 
                                                        |
| 2103 | + */  | 
                                                        |
| 2104 | + public function shortcode_meta_box()  | 
                                                        |
| 2105 | +	{ | 
                                                        |
| 2106 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set  | 
                                                        |
| 2107 | + //$messenger = $this->_message_template_group->messenger_obj();  | 
                                                        |
| 2108 | + //now let's set the content depending on the status of the shortcodes array  | 
                                                        |
| 2109 | +		if (empty($shortcodes)) { | 
                                                        |
| 2110 | +			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2111 | + echo $content;  | 
                                                        |
| 2112 | +		} else { | 
                                                        |
| 2113 | + //$alt = 0;  | 
                                                        |
| 2114 | + ?>  | 
                                                        |
| 2115 | 2115 | <div  | 
                                                        
| 2116 | 2116 |                  style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> | 
                                                        
| 2117 | 2117 |              <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', | 
                                                        
| 2118 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>  | 
                                                        |
| 2118 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>  | 
                                                        |
| 2119 | 2119 | <?php  | 
                                                        
| 2120 | - }  | 
                                                        |
| 2121 | -  | 
                                                        |
| 2122 | -  | 
                                                        |
| 2123 | - }  | 
                                                        |
| 2124 | -  | 
                                                        |
| 2125 | -  | 
                                                        |
| 2126 | - /**  | 
                                                        |
| 2127 | - * used to set the $_shortcodes property for when its needed elsewhere.  | 
                                                        |
| 2128 | - *  | 
                                                        |
| 2129 | - * @access protected  | 
                                                        |
| 2130 | - * @return void  | 
                                                        |
| 2131 | - */  | 
                                                        |
| 2132 | - protected function _set_shortcodes()  | 
                                                        |
| 2133 | -    { | 
                                                        |
| 2134 | -  | 
                                                        |
| 2135 | - //no need to run this if the property is already set  | 
                                                        |
| 2136 | -        if ( ! empty($this->_shortcodes)) { | 
                                                        |
| 2137 | - return;  | 
                                                        |
| 2138 | - }  | 
                                                        |
| 2139 | -  | 
                                                        |
| 2140 | - $this->_shortcodes = $this->_get_shortcodes();  | 
                                                        |
| 2141 | - }  | 
                                                        |
| 2142 | -  | 
                                                        |
| 2143 | -  | 
                                                        |
| 2144 | - /**  | 
                                                        |
| 2145 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes  | 
                                                        |
| 2146 | - * property)  | 
                                                        |
| 2147 | - *  | 
                                                        |
| 2148 | - * @access protected  | 
                                                        |
| 2149 | - *  | 
                                                        |
| 2150 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes  | 
                                                        |
| 2151 | - * for. Defaults to all (for the given context)  | 
                                                        |
| 2152 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes  | 
                                                        |
| 2153 | - *  | 
                                                        |
| 2154 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is  | 
                                                        |
| 2155 | - * true just an array of shortcode/label pairs.  | 
                                                        |
| 2156 | - */  | 
                                                        |
| 2157 | - protected function _get_shortcodes($fields = array(), $merged = true)  | 
                                                        |
| 2158 | -    { | 
                                                        |
| 2159 | - $this->_set_message_template_group();  | 
                                                        |
| 2160 | -  | 
                                                        |
| 2161 | - //we need the messenger and message template to retrieve the valid shortcodes array.  | 
                                                        |
| 2162 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;  | 
                                                        |
| 2163 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());  | 
                                                        |
| 2164 | -  | 
                                                        |
| 2165 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();  | 
                                                        |
| 2166 | - }  | 
                                                        |
| 2167 | -  | 
                                                        |
| 2168 | -  | 
                                                        |
| 2169 | - /**  | 
                                                        |
| 2170 | - * This sets the _message_template property (containing the called message_template object)  | 
                                                        |
| 2171 | - *  | 
                                                        |
| 2172 | - * @access protected  | 
                                                        |
| 2173 | - * @return void  | 
                                                        |
| 2174 | - */  | 
                                                        |
| 2175 | - protected function _set_message_template_group()  | 
                                                        |
| 2176 | -    { | 
                                                        |
| 2177 | -  | 
                                                        |
| 2178 | -        if ( ! empty($this->_message_template_group)) { | 
                                                        |
| 2179 | - return;  | 
                                                        |
| 2180 | - } //get out if this is already set.  | 
                                                        |
| 2181 | -  | 
                                                        |
| 2182 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;  | 
                                                        |
| 2183 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;  | 
                                                        |
| 2184 | -  | 
                                                        |
| 2185 | - //let's get the message templates  | 
                                                        |
| 2186 | - $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2187 | -  | 
                                                        |
| 2188 | -        if (empty($GRP_ID)) { | 
                                                        |
| 2189 | - $this->_message_template_group = $MTP->create_default_object();  | 
                                                        |
| 2190 | -        } else { | 
                                                        |
| 2191 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2192 | - }  | 
                                                        |
| 2193 | -  | 
                                                        |
| 2194 | - $this->_template_pack = $this->_message_template_group->get_template_pack();  | 
                                                        |
| 2195 | - $this->_variation = $this->_message_template_group->get_template_pack_variation();  | 
                                                        |
| 2196 | -  | 
                                                        |
| 2197 | - }  | 
                                                        |
| 2198 | -  | 
                                                        |
| 2199 | -  | 
                                                        |
| 2200 | - /**  | 
                                                        |
| 2201 | - * sets up a context switcher for edit forms  | 
                                                        |
| 2202 | - *  | 
                                                        |
| 2203 | - * @access protected  | 
                                                        |
| 2204 | - *  | 
                                                        |
| 2205 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form  | 
                                                        |
| 2206 | - * @param array $args various things the context switcher needs.  | 
                                                        |
| 2207 | - *  | 
                                                        |
| 2208 | - */  | 
                                                        |
| 2209 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)  | 
                                                        |
| 2210 | -    { | 
                                                        |
| 2211 | - $context_details = $template_group_object->contexts_config();  | 
                                                        |
| 2212 | - $context_label = $template_group_object->context_label();  | 
                                                        |
| 2213 | - ob_start();  | 
                                                        |
| 2214 | - ?>  | 
                                                        |
| 2120 | + }  | 
                                                        |
| 2121 | +  | 
                                                        |
| 2122 | +  | 
                                                        |
| 2123 | + }  | 
                                                        |
| 2124 | +  | 
                                                        |
| 2125 | +  | 
                                                        |
| 2126 | + /**  | 
                                                        |
| 2127 | + * used to set the $_shortcodes property for when its needed elsewhere.  | 
                                                        |
| 2128 | + *  | 
                                                        |
| 2129 | + * @access protected  | 
                                                        |
| 2130 | + * @return void  | 
                                                        |
| 2131 | + */  | 
                                                        |
| 2132 | + protected function _set_shortcodes()  | 
                                                        |
| 2133 | +	{ | 
                                                        |
| 2134 | +  | 
                                                        |
| 2135 | + //no need to run this if the property is already set  | 
                                                        |
| 2136 | +		if ( ! empty($this->_shortcodes)) { | 
                                                        |
| 2137 | + return;  | 
                                                        |
| 2138 | + }  | 
                                                        |
| 2139 | +  | 
                                                        |
| 2140 | + $this->_shortcodes = $this->_get_shortcodes();  | 
                                                        |
| 2141 | + }  | 
                                                        |
| 2142 | +  | 
                                                        |
| 2143 | +  | 
                                                        |
| 2144 | + /**  | 
                                                        |
| 2145 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes  | 
                                                        |
| 2146 | + * property)  | 
                                                        |
| 2147 | + *  | 
                                                        |
| 2148 | + * @access protected  | 
                                                        |
| 2149 | + *  | 
                                                        |
| 2150 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes  | 
                                                        |
| 2151 | + * for. Defaults to all (for the given context)  | 
                                                        |
| 2152 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes  | 
                                                        |
| 2153 | + *  | 
                                                        |
| 2154 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is  | 
                                                        |
| 2155 | + * true just an array of shortcode/label pairs.  | 
                                                        |
| 2156 | + */  | 
                                                        |
| 2157 | + protected function _get_shortcodes($fields = array(), $merged = true)  | 
                                                        |
| 2158 | +	{ | 
                                                        |
| 2159 | + $this->_set_message_template_group();  | 
                                                        |
| 2160 | +  | 
                                                        |
| 2161 | + //we need the messenger and message template to retrieve the valid shortcodes array.  | 
                                                        |
| 2162 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;  | 
                                                        |
| 2163 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());  | 
                                                        |
| 2164 | +  | 
                                                        |
| 2165 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();  | 
                                                        |
| 2166 | + }  | 
                                                        |
| 2167 | +  | 
                                                        |
| 2168 | +  | 
                                                        |
| 2169 | + /**  | 
                                                        |
| 2170 | + * This sets the _message_template property (containing the called message_template object)  | 
                                                        |
| 2171 | + *  | 
                                                        |
| 2172 | + * @access protected  | 
                                                        |
| 2173 | + * @return void  | 
                                                        |
| 2174 | + */  | 
                                                        |
| 2175 | + protected function _set_message_template_group()  | 
                                                        |
| 2176 | +	{ | 
                                                        |
| 2177 | +  | 
                                                        |
| 2178 | +		if ( ! empty($this->_message_template_group)) { | 
                                                        |
| 2179 | + return;  | 
                                                        |
| 2180 | + } //get out if this is already set.  | 
                                                        |
| 2181 | +  | 
                                                        |
| 2182 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;  | 
                                                        |
| 2183 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;  | 
                                                        |
| 2184 | +  | 
                                                        |
| 2185 | + //let's get the message templates  | 
                                                        |
| 2186 | + $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2187 | +  | 
                                                        |
| 2188 | +		if (empty($GRP_ID)) { | 
                                                        |
| 2189 | + $this->_message_template_group = $MTP->create_default_object();  | 
                                                        |
| 2190 | +		} else { | 
                                                        |
| 2191 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2192 | + }  | 
                                                        |
| 2193 | +  | 
                                                        |
| 2194 | + $this->_template_pack = $this->_message_template_group->get_template_pack();  | 
                                                        |
| 2195 | + $this->_variation = $this->_message_template_group->get_template_pack_variation();  | 
                                                        |
| 2196 | +  | 
                                                        |
| 2197 | + }  | 
                                                        |
| 2198 | +  | 
                                                        |
| 2199 | +  | 
                                                        |
| 2200 | + /**  | 
                                                        |
| 2201 | + * sets up a context switcher for edit forms  | 
                                                        |
| 2202 | + *  | 
                                                        |
| 2203 | + * @access protected  | 
                                                        |
| 2204 | + *  | 
                                                        |
| 2205 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form  | 
                                                        |
| 2206 | + * @param array $args various things the context switcher needs.  | 
                                                        |
| 2207 | + *  | 
                                                        |
| 2208 | + */  | 
                                                        |
| 2209 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)  | 
                                                        |
| 2210 | +	{ | 
                                                        |
| 2211 | + $context_details = $template_group_object->contexts_config();  | 
                                                        |
| 2212 | + $context_label = $template_group_object->context_label();  | 
                                                        |
| 2213 | + ob_start();  | 
                                                        |
| 2214 | + ?>  | 
                                                        |
| 2215 | 2215 | <div class="ee-msg-switcher-container">  | 
                                                        
| 2216 | 2216 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">  | 
                                                        
| 2217 | 2217 | <?php  | 
                                                        
| 2218 | -                foreach ($args as $name => $value) { | 
                                                        |
| 2219 | -                    if ($name == 'context' || empty($value) || $name == 'extra') { | 
                                                        |
| 2220 | - continue;  | 
                                                        |
| 2221 | - }  | 
                                                        |
| 2222 | - ?>  | 
                                                        |
| 2218 | +				foreach ($args as $name => $value) { | 
                                                        |
| 2219 | +					if ($name == 'context' || empty($value) || $name == 'extra') { | 
                                                        |
| 2220 | + continue;  | 
                                                        |
| 2221 | + }  | 
                                                        |
| 2222 | + ?>  | 
                                                        |
| 2223 | 2223 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>  | 
                                                        
| 2224 | 2224 | <?php  | 
                                                        
| 2225 | - }  | 
                                                        |
| 2226 | - //setup nonce_url  | 
                                                        |
| 2227 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2228 | - ?>  | 
                                                        |
| 2225 | + }  | 
                                                        |
| 2226 | + //setup nonce_url  | 
                                                        |
| 2227 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2228 | + ?>  | 
                                                        |
| 2229 | 2229 | <select name="context">  | 
                                                        
| 2230 | 2230 | <?php  | 
                                                        
| 2231 | - $context_templates = $template_group_object->context_templates();  | 
                                                        |
| 2232 | - if (is_array($context_templates)) :  | 
                                                        |
| 2233 | - foreach ($context_templates as $context => $template_fields) :  | 
                                                        |
| 2234 | - $checked = ($context == $args['context']) ? 'selected="selected"' : '';  | 
                                                        |
| 2235 | - ?>  | 
                                                        |
| 2231 | + $context_templates = $template_group_object->context_templates();  | 
                                                        |
| 2232 | + if (is_array($context_templates)) :  | 
                                                        |
| 2233 | + foreach ($context_templates as $context => $template_fields) :  | 
                                                        |
| 2234 | + $checked = ($context == $args['context']) ? 'selected="selected"' : '';  | 
                                                        |
| 2235 | + ?>  | 
                                                        |
| 2236 | 2236 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>>  | 
                                                        
| 2237 | 2237 | <?php echo $context_details[$context]['label']; ?>  | 
                                                        
| 2238 | 2238 | </option>  | 
                                                        
@@ -2245,1608 +2245,1608 @@ discard block  | 
                                                    ||
| 2245 | 2245 | <?php echo $args['extra']; ?>  | 
                                                        
| 2246 | 2246 | </div> <!-- end .ee-msg-switcher-container -->  | 
                                                        
| 2247 | 2247 | <?php  | 
                                                        
| 2248 | - $output = ob_get_contents();  | 
                                                        |
| 2249 | - ob_clean();  | 
                                                        |
| 2250 | - $this->_context_switcher = $output;  | 
                                                        |
| 2251 | - }  | 
                                                        |
| 2252 | -  | 
                                                        |
| 2253 | -  | 
                                                        |
| 2254 | - /**  | 
                                                        |
| 2255 | - * utility for sanitizing new values coming in.  | 
                                                        |
| 2256 | - * Note: this is only used when updating a context.  | 
                                                        |
| 2257 | - *  | 
                                                        |
| 2258 | - * @access protected  | 
                                                        |
| 2259 | - *  | 
                                                        |
| 2260 | - * @param int $index This helps us know which template field to select from the request array.  | 
                                                        |
| 2261 | - *  | 
                                                        |
| 2262 | - * @return array  | 
                                                        |
| 2263 | - */  | 
                                                        |
| 2264 | - protected function _set_message_template_column_values($index)  | 
                                                        |
| 2265 | -    { | 
                                                        |
| 2266 | -        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { | 
                                                        |
| 2267 | -            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { | 
                                                        |
| 2268 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;  | 
                                                        |
| 2269 | - }  | 
                                                        |
| 2270 | -        } /*else { | 
                                                        |
| 2248 | + $output = ob_get_contents();  | 
                                                        |
| 2249 | + ob_clean();  | 
                                                        |
| 2250 | + $this->_context_switcher = $output;  | 
                                                        |
| 2251 | + }  | 
                                                        |
| 2252 | +  | 
                                                        |
| 2253 | +  | 
                                                        |
| 2254 | + /**  | 
                                                        |
| 2255 | + * utility for sanitizing new values coming in.  | 
                                                        |
| 2256 | + * Note: this is only used when updating a context.  | 
                                                        |
| 2257 | + *  | 
                                                        |
| 2258 | + * @access protected  | 
                                                        |
| 2259 | + *  | 
                                                        |
| 2260 | + * @param int $index This helps us know which template field to select from the request array.  | 
                                                        |
| 2261 | + *  | 
                                                        |
| 2262 | + * @return array  | 
                                                        |
| 2263 | + */  | 
                                                        |
| 2264 | + protected function _set_message_template_column_values($index)  | 
                                                        |
| 2265 | +	{ | 
                                                        |
| 2266 | +		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { | 
                                                        |
| 2267 | +			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { | 
                                                        |
| 2268 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;  | 
                                                        |
| 2269 | + }  | 
                                                        |
| 2270 | +		} /*else { | 
                                                        |
| 2271 | 2271 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];  | 
                                                        
| 2272 | 2272 | }*/  | 
                                                        
| 2273 | 2273 | |
| 2274 | 2274 | |
| 2275 | - $set_column_values = array(  | 
                                                        |
| 2276 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),  | 
                                                        |
| 2277 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']),  | 
                                                        |
| 2278 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']),  | 
                                                        |
| 2279 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']),  | 
                                                        |
| 2280 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']),  | 
                                                        |
| 2281 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),  | 
                                                        |
| 2282 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']),  | 
                                                        |
| 2283 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'],  | 
                                                        |
| 2284 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global'])  | 
                                                        |
| 2285 | - ? absint($this->_req_data['MTP_is_global'])  | 
                                                        |
| 2286 | - : 0,  | 
                                                        |
| 2287 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override'])  | 
                                                        |
| 2288 | - ? absint($this->_req_data['MTP_is_override'])  | 
                                                        |
| 2289 | - : 0,  | 
                                                        |
| 2290 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']),  | 
                                                        |
| 2291 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active'])  | 
                                                        |
| 2292 | - );  | 
                                                        |
| 2293 | -  | 
                                                        |
| 2294 | -  | 
                                                        |
| 2295 | - return $set_column_values;  | 
                                                        |
| 2296 | - }  | 
                                                        |
| 2297 | -  | 
                                                        |
| 2298 | -  | 
                                                        |
| 2299 | - protected function _insert_or_update_message_template($new = false)  | 
                                                        |
| 2300 | -    { | 
                                                        |
| 2301 | -  | 
                                                        |
| 2302 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2303 | - $success = 0;  | 
                                                        |
| 2304 | - $override = false;  | 
                                                        |
| 2305 | -  | 
                                                        |
| 2306 | - //setup notices description  | 
                                                        |
| 2307 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';  | 
                                                        |
| 2308 | -  | 
                                                        |
| 2309 | - //need the message type and messenger objects to be able to use the labels for the notices  | 
                                                        |
| 2310 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);  | 
                                                        |
| 2311 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';  | 
                                                        |
| 2312 | -  | 
                                                        |
| 2313 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';  | 
                                                        |
| 2314 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);  | 
                                                        |
| 2315 | -  | 
                                                        |
| 2316 | - $message_type_label = $message_type_object instanceof EE_message_type  | 
                                                        |
| 2317 | - ? ucwords($message_type_object->label['singular'])  | 
                                                        |
| 2318 | - : '';  | 
                                                        |
| 2319 | -  | 
                                                        |
| 2320 | - $context_slug = ! empty($this->_req_data['MTP_context'])  | 
                                                        |
| 2321 | - ? $this->_req_data['MTP_context']  | 
                                                        |
| 2322 | - : '';  | 
                                                        |
| 2323 | -        $context      = ucwords(str_replace('_', ' ', $context_slug)); | 
                                                        |
| 2324 | -  | 
                                                        |
| 2325 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';  | 
                                                        |
| 2326 | - $item_desc .= 'Message Template';  | 
                                                        |
| 2327 | - $query_args = array();  | 
                                                        |
| 2328 | - $edit_array = array();  | 
                                                        |
| 2329 | - $action_desc = '';  | 
                                                        |
| 2330 | -  | 
                                                        |
| 2331 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.  | 
                                                        |
| 2332 | -        if ($new) { | 
                                                        |
| 2333 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 2334 | -            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { | 
                                                        |
| 2335 | -                if (empty($edit_array)) { | 
                                                        |
| 2336 | - $success = 0;  | 
                                                        |
| 2337 | -                } else { | 
                                                        |
| 2338 | - $success = 1;  | 
                                                        |
| 2339 | - $edit_array = $edit_array[0];  | 
                                                        |
| 2340 | - $query_args = array(  | 
                                                        |
| 2341 | - 'id' => $edit_array['GRP_ID'],  | 
                                                        |
| 2342 | - 'context' => $edit_array['MTP_context'],  | 
                                                        |
| 2343 | - 'action' => 'edit_message_template'  | 
                                                        |
| 2344 | - );  | 
                                                        |
| 2345 | - }  | 
                                                        |
| 2346 | - }  | 
                                                        |
| 2347 | - $action_desc = 'created';  | 
                                                        |
| 2348 | -        } else { | 
                                                        |
| 2349 | - $MTPG = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2350 | - $MTP = EEM_Message_Template::instance();  | 
                                                        |
| 2275 | + $set_column_values = array(  | 
                                                        |
| 2276 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),  | 
                                                        |
| 2277 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']),  | 
                                                        |
| 2278 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']),  | 
                                                        |
| 2279 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']),  | 
                                                        |
| 2280 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']),  | 
                                                        |
| 2281 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),  | 
                                                        |
| 2282 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']),  | 
                                                        |
| 2283 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'],  | 
                                                        |
| 2284 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global'])  | 
                                                        |
| 2285 | + ? absint($this->_req_data['MTP_is_global'])  | 
                                                        |
| 2286 | + : 0,  | 
                                                        |
| 2287 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override'])  | 
                                                        |
| 2288 | + ? absint($this->_req_data['MTP_is_override'])  | 
                                                        |
| 2289 | + : 0,  | 
                                                        |
| 2290 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']),  | 
                                                        |
| 2291 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active'])  | 
                                                        |
| 2292 | + );  | 
                                                        |
| 2293 | +  | 
                                                        |
| 2294 | +  | 
                                                        |
| 2295 | + return $set_column_values;  | 
                                                        |
| 2296 | + }  | 
                                                        |
| 2297 | +  | 
                                                        |
| 2298 | +  | 
                                                        |
| 2299 | + protected function _insert_or_update_message_template($new = false)  | 
                                                        |
| 2300 | +	{ | 
                                                        |
| 2301 | +  | 
                                                        |
| 2302 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2303 | + $success = 0;  | 
                                                        |
| 2304 | + $override = false;  | 
                                                        |
| 2305 | +  | 
                                                        |
| 2306 | + //setup notices description  | 
                                                        |
| 2307 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';  | 
                                                        |
| 2308 | +  | 
                                                        |
| 2309 | + //need the message type and messenger objects to be able to use the labels for the notices  | 
                                                        |
| 2310 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);  | 
                                                        |
| 2311 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';  | 
                                                        |
| 2312 | +  | 
                                                        |
| 2313 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';  | 
                                                        |
| 2314 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);  | 
                                                        |
| 2315 | +  | 
                                                        |
| 2316 | + $message_type_label = $message_type_object instanceof EE_message_type  | 
                                                        |
| 2317 | + ? ucwords($message_type_object->label['singular'])  | 
                                                        |
| 2318 | + : '';  | 
                                                        |
| 2319 | +  | 
                                                        |
| 2320 | + $context_slug = ! empty($this->_req_data['MTP_context'])  | 
                                                        |
| 2321 | + ? $this->_req_data['MTP_context']  | 
                                                        |
| 2322 | + : '';  | 
                                                        |
| 2323 | +		$context      = ucwords(str_replace('_', ' ', $context_slug)); | 
                                                        |
| 2324 | +  | 
                                                        |
| 2325 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';  | 
                                                        |
| 2326 | + $item_desc .= 'Message Template';  | 
                                                        |
| 2327 | + $query_args = array();  | 
                                                        |
| 2328 | + $edit_array = array();  | 
                                                        |
| 2329 | + $action_desc = '';  | 
                                                        |
| 2330 | +  | 
                                                        |
| 2331 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.  | 
                                                        |
| 2332 | +		if ($new) { | 
                                                        |
| 2333 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;  | 
                                                        |
| 2334 | +			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { | 
                                                        |
| 2335 | +				if (empty($edit_array)) { | 
                                                        |
| 2336 | + $success = 0;  | 
                                                        |
| 2337 | +				} else { | 
                                                        |
| 2338 | + $success = 1;  | 
                                                        |
| 2339 | + $edit_array = $edit_array[0];  | 
                                                        |
| 2340 | + $query_args = array(  | 
                                                        |
| 2341 | + 'id' => $edit_array['GRP_ID'],  | 
                                                        |
| 2342 | + 'context' => $edit_array['MTP_context'],  | 
                                                        |
| 2343 | + 'action' => 'edit_message_template'  | 
                                                        |
| 2344 | + );  | 
                                                        |
| 2345 | + }  | 
                                                        |
| 2346 | + }  | 
                                                        |
| 2347 | + $action_desc = 'created';  | 
                                                        |
| 2348 | +		} else { | 
                                                        |
| 2349 | + $MTPG = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2350 | + $MTP = EEM_Message_Template::instance();  | 
                                                        |
| 2351 | 2351 | |
| 2352 | 2352 | |
| 2353 | - //run update for each template field in displayed context  | 
                                                        |
| 2354 | -            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { | 
                                                        |
| 2355 | - EE_Error::add_error(  | 
                                                        |
| 2356 | -                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', | 
                                                        |
| 2357 | - 'event_espresso'),  | 
                                                        |
| 2358 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2359 | - );  | 
                                                        |
| 2360 | - $success = 0;  | 
                                                        |
| 2353 | + //run update for each template field in displayed context  | 
                                                        |
| 2354 | +			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { | 
                                                        |
| 2355 | + EE_Error::add_error(  | 
                                                        |
| 2356 | +					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', | 
                                                        |
| 2357 | + 'event_espresso'),  | 
                                                        |
| 2358 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2359 | + );  | 
                                                        |
| 2360 | + $success = 0;  | 
                                                        |
| 2361 | 2361 | |
| 2362 | -            } else { | 
                                                        |
| 2363 | - //first validate all fields!  | 
                                                        |
| 2364 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,  | 
                                                        |
| 2365 | - $message_type_slug);  | 
                                                        |
| 2362 | +			} else { | 
                                                        |
| 2363 | + //first validate all fields!  | 
                                                        |
| 2364 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,  | 
                                                        |
| 2365 | + $message_type_slug);  | 
                                                        |
| 2366 | 2366 | |
| 2367 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates.  | 
                                                        |
| 2368 | -                if (is_array($validates) && ! empty($validates)) { | 
                                                        |
| 2369 | - //add the transient so when the form loads we know which fields to highlight  | 
                                                        |
| 2370 | -                    $this->_add_transient('edit_message_template', $validates); | 
                                                        |
| 2367 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates.  | 
                                                        |
| 2368 | +				if (is_array($validates) && ! empty($validates)) { | 
                                                        |
| 2369 | + //add the transient so when the form loads we know which fields to highlight  | 
                                                        |
| 2370 | +					$this->_add_transient('edit_message_template', $validates); | 
                                                        |
| 2371 | 2371 | |
| 2372 | - $success = 0;  | 
                                                        |
| 2372 | + $success = 0;  | 
                                                        |
| 2373 | 2373 | |
| 2374 | - //setup notices  | 
                                                        |
| 2375 | -                    foreach ($validates as $field => $error) { | 
                                                        |
| 2376 | -                        if (isset($error['msg'])) { | 
                                                        |
| 2377 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2378 | - }  | 
                                                        |
| 2379 | - }  | 
                                                        |
| 2374 | + //setup notices  | 
                                                        |
| 2375 | +					foreach ($validates as $field => $error) { | 
                                                        |
| 2376 | +						if (isset($error['msg'])) { | 
                                                        |
| 2377 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2378 | + }  | 
                                                        |
| 2379 | + }  | 
                                                        |
| 2380 | 2380 | |
| 2381 | -                } else { | 
                                                        |
| 2382 | - $set_column_values = array();  | 
                                                        |
| 2383 | -                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { | 
                                                        |
| 2384 | - $set_column_values = $this->_set_message_template_column_values($template_field);  | 
                                                        |
| 2381 | +				} else { | 
                                                        |
| 2382 | + $set_column_values = array();  | 
                                                        |
| 2383 | +					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { | 
                                                        |
| 2384 | + $set_column_values = $this->_set_message_template_column_values($template_field);  | 
                                                        |
| 2385 | 2385 | |
| 2386 | - $where_cols_n_values = array(  | 
                                                        |
| 2387 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']  | 
                                                        |
| 2388 | - );  | 
                                                        |
| 2386 | + $where_cols_n_values = array(  | 
                                                        |
| 2387 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']  | 
                                                        |
| 2388 | + );  | 
                                                        |
| 2389 | 2389 | |
| 2390 | - $message_template_fields = array(  | 
                                                        |
| 2391 | - 'GRP_ID' => $set_column_values['GRP_ID'],  | 
                                                        |
| 2392 | - 'MTP_template_field' => $set_column_values['MTP_template_field'],  | 
                                                        |
| 2393 | - 'MTP_context' => $set_column_values['MTP_context'],  | 
                                                        |
| 2394 | - 'MTP_content' => $set_column_values['MTP_content']  | 
                                                        |
| 2395 | - );  | 
                                                        |
| 2396 | -                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { | 
                                                        |
| 2397 | -                            if ($updated === false) { | 
                                                        |
| 2398 | - EE_Error::add_error(  | 
                                                        |
| 2399 | - sprintf(  | 
                                                        |
| 2400 | -                                        __('%s field was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2401 | - $template_field  | 
                                                        |
| 2402 | - ),  | 
                                                        |
| 2403 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2404 | - );  | 
                                                        |
| 2405 | -                            } else { | 
                                                        |
| 2406 | - $success = 1;  | 
                                                        |
| 2407 | - }  | 
                                                        |
| 2408 | -                        } else { | 
                                                        |
| 2409 | - //only do this logic if we don't have a MTP_ID for this field  | 
                                                        |
| 2410 | -                            if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { | 
                                                        |
| 2411 | - //this has already been through the template field validator and sanitized, so it will be  | 
                                                        |
| 2412 | - //safe to insert this field. Why insert? This typically happens when we introduce a new  | 
                                                        |
| 2413 | - //message template field in a messenger/message type and existing users don't have the  | 
                                                        |
| 2414 | - //default setup for it.  | 
                                                        |
| 2415 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465  | 
                                                        |
| 2416 | - $updated = $MTP->insert($message_template_fields);  | 
                                                        |
| 2417 | -                                if (is_wp_error($updated) || ! $updated) { | 
                                                        |
| 2418 | - EE_Error::add_error(  | 
                                                        |
| 2419 | - sprintf(  | 
                                                        |
| 2420 | -                                            esc_html__('%s field could not be updated.', 'event_espresso'), | 
                                                        |
| 2421 | - $template_field  | 
                                                        |
| 2422 | - ),  | 
                                                        |
| 2423 | - __FILE__,  | 
                                                        |
| 2424 | - __FUNCTION__,  | 
                                                        |
| 2425 | - __LINE__  | 
                                                        |
| 2426 | - );  | 
                                                        |
| 2427 | - $success = 0;  | 
                                                        |
| 2428 | -                                } else { | 
                                                        |
| 2429 | - $success = 1;  | 
                                                        |
| 2430 | - }  | 
                                                        |
| 2431 | - }  | 
                                                        |
| 2432 | - }  | 
                                                        |
| 2433 | - $action_desc = 'updated';  | 
                                                        |
| 2434 | - }  | 
                                                        |
| 2390 | + $message_template_fields = array(  | 
                                                        |
| 2391 | + 'GRP_ID' => $set_column_values['GRP_ID'],  | 
                                                        |
| 2392 | + 'MTP_template_field' => $set_column_values['MTP_template_field'],  | 
                                                        |
| 2393 | + 'MTP_context' => $set_column_values['MTP_context'],  | 
                                                        |
| 2394 | + 'MTP_content' => $set_column_values['MTP_content']  | 
                                                        |
| 2395 | + );  | 
                                                        |
| 2396 | +						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { | 
                                                        |
| 2397 | +							if ($updated === false) { | 
                                                        |
| 2398 | + EE_Error::add_error(  | 
                                                        |
| 2399 | + sprintf(  | 
                                                        |
| 2400 | +										__('%s field was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2401 | + $template_field  | 
                                                        |
| 2402 | + ),  | 
                                                        |
| 2403 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2404 | + );  | 
                                                        |
| 2405 | +							} else { | 
                                                        |
| 2406 | + $success = 1;  | 
                                                        |
| 2407 | + }  | 
                                                        |
| 2408 | +						} else { | 
                                                        |
| 2409 | + //only do this logic if we don't have a MTP_ID for this field  | 
                                                        |
| 2410 | +							if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { | 
                                                        |
| 2411 | + //this has already been through the template field validator and sanitized, so it will be  | 
                                                        |
| 2412 | + //safe to insert this field. Why insert? This typically happens when we introduce a new  | 
                                                        |
| 2413 | + //message template field in a messenger/message type and existing users don't have the  | 
                                                        |
| 2414 | + //default setup for it.  | 
                                                        |
| 2415 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465  | 
                                                        |
| 2416 | + $updated = $MTP->insert($message_template_fields);  | 
                                                        |
| 2417 | +								if (is_wp_error($updated) || ! $updated) { | 
                                                        |
| 2418 | + EE_Error::add_error(  | 
                                                        |
| 2419 | + sprintf(  | 
                                                        |
| 2420 | +											esc_html__('%s field could not be updated.', 'event_espresso'), | 
                                                        |
| 2421 | + $template_field  | 
                                                        |
| 2422 | + ),  | 
                                                        |
| 2423 | + __FILE__,  | 
                                                        |
| 2424 | + __FUNCTION__,  | 
                                                        |
| 2425 | + __LINE__  | 
                                                        |
| 2426 | + );  | 
                                                        |
| 2427 | + $success = 0;  | 
                                                        |
| 2428 | +								} else { | 
                                                        |
| 2429 | + $success = 1;  | 
                                                        |
| 2430 | + }  | 
                                                        |
| 2431 | + }  | 
                                                        |
| 2432 | + }  | 
                                                        |
| 2433 | + $action_desc = 'updated';  | 
                                                        |
| 2434 | + }  | 
                                                        |
| 2435 | 2435 | |
| 2436 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)  | 
                                                        |
| 2437 | - $mtpg_fields = array(  | 
                                                        |
| 2438 | - 'MTP_user_id' => $set_column_values['MTP_user_id'],  | 
                                                        |
| 2439 | - 'MTP_messenger' => $set_column_values['MTP_messenger'],  | 
                                                        |
| 2440 | - 'MTP_message_type' => $set_column_values['MTP_message_type'],  | 
                                                        |
| 2441 | - 'MTP_is_global' => $set_column_values['MTP_is_global'],  | 
                                                        |
| 2442 | - 'MTP_is_override' => $set_column_values['MTP_is_override'],  | 
                                                        |
| 2443 | - 'MTP_deleted' => $set_column_values['MTP_deleted'],  | 
                                                        |
| 2444 | - 'MTP_is_active' => $set_column_values['MTP_is_active'],  | 
                                                        |
| 2445 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])  | 
                                                        |
| 2446 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']  | 
                                                        |
| 2447 | - : '',  | 
                                                        |
| 2448 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])  | 
                                                        |
| 2449 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']  | 
                                                        |
| 2450 | - : ''  | 
                                                        |
| 2451 | - );  | 
                                                        |
| 2436 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)  | 
                                                        |
| 2437 | + $mtpg_fields = array(  | 
                                                        |
| 2438 | + 'MTP_user_id' => $set_column_values['MTP_user_id'],  | 
                                                        |
| 2439 | + 'MTP_messenger' => $set_column_values['MTP_messenger'],  | 
                                                        |
| 2440 | + 'MTP_message_type' => $set_column_values['MTP_message_type'],  | 
                                                        |
| 2441 | + 'MTP_is_global' => $set_column_values['MTP_is_global'],  | 
                                                        |
| 2442 | + 'MTP_is_override' => $set_column_values['MTP_is_override'],  | 
                                                        |
| 2443 | + 'MTP_deleted' => $set_column_values['MTP_deleted'],  | 
                                                        |
| 2444 | + 'MTP_is_active' => $set_column_values['MTP_is_active'],  | 
                                                        |
| 2445 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])  | 
                                                        |
| 2446 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']  | 
                                                        |
| 2447 | + : '',  | 
                                                        |
| 2448 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])  | 
                                                        |
| 2449 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']  | 
                                                        |
| 2450 | + : ''  | 
                                                        |
| 2451 | + );  | 
                                                        |
| 2452 | 2452 | |
| 2453 | -                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); | 
                                                        |
| 2454 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where));  | 
                                                        |
| 2453 | +					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); | 
                                                        |
| 2454 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where));  | 
                                                        |
| 2455 | 2455 | |
| 2456 | -                    if ($updated === false) { | 
                                                        |
| 2457 | - EE_Error::add_error(  | 
                                                        |
| 2458 | - sprintf(  | 
                                                        |
| 2459 | -                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2460 | - $set_column_values['GRP_ID']  | 
                                                        |
| 2461 | - ),  | 
                                                        |
| 2462 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2463 | - );  | 
                                                        |
| 2464 | -                    } else { | 
                                                        |
| 2465 | - //k now we need to ensure the template_pack and template_variation fields are set.  | 
                                                        |
| 2466 | - $template_pack = ! empty($this->_req_data['MTP_template_pack'])  | 
                                                        |
| 2467 | - ? $this->_req_data['MTP_template_pack']  | 
                                                        |
| 2468 | - : 'default';  | 
                                                        |
| 2456 | +					if ($updated === false) { | 
                                                        |
| 2457 | + EE_Error::add_error(  | 
                                                        |
| 2458 | + sprintf(  | 
                                                        |
| 2459 | +								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2460 | + $set_column_values['GRP_ID']  | 
                                                        |
| 2461 | + ),  | 
                                                        |
| 2462 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 2463 | + );  | 
                                                        |
| 2464 | +					} else { | 
                                                        |
| 2465 | + //k now we need to ensure the template_pack and template_variation fields are set.  | 
                                                        |
| 2466 | + $template_pack = ! empty($this->_req_data['MTP_template_pack'])  | 
                                                        |
| 2467 | + ? $this->_req_data['MTP_template_pack']  | 
                                                        |
| 2468 | + : 'default';  | 
                                                        |
| 2469 | 2469 | |
| 2470 | - $template_variation = ! empty($this->_req_data['MTP_template_variation'])  | 
                                                        |
| 2471 | - ? $this->_req_data['MTP_template_variation']  | 
                                                        |
| 2472 | - : 'default';  | 
                                                        |
| 2470 | + $template_variation = ! empty($this->_req_data['MTP_template_variation'])  | 
                                                        |
| 2471 | + ? $this->_req_data['MTP_template_variation']  | 
                                                        |
| 2472 | + : 'default';  | 
                                                        |
| 2473 | 2473 | |
| 2474 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);  | 
                                                        |
| 2475 | -                        if ($mtpg_obj instanceof EE_Message_Template_Group) { | 
                                                        |
| 2476 | - $mtpg_obj->set_template_pack_name($template_pack);  | 
                                                        |
| 2477 | - $mtpg_obj->set_template_pack_variation($template_variation);  | 
                                                        |
| 2478 | - }  | 
                                                        |
| 2479 | - $success = 1;  | 
                                                        |
| 2480 | - }  | 
                                                        |
| 2481 | - }  | 
                                                        |
| 2482 | - }  | 
                                                        |
| 2474 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);  | 
                                                        |
| 2475 | +						if ($mtpg_obj instanceof EE_Message_Template_Group) { | 
                                                        |
| 2476 | + $mtpg_obj->set_template_pack_name($template_pack);  | 
                                                        |
| 2477 | + $mtpg_obj->set_template_pack_variation($template_variation);  | 
                                                        |
| 2478 | + }  | 
                                                        |
| 2479 | + $success = 1;  | 
                                                        |
| 2480 | + }  | 
                                                        |
| 2481 | + }  | 
                                                        |
| 2482 | + }  | 
                                                        |
| 2483 | 2483 | |
| 2484 | - }  | 
                                                        |
| 2485 | -  | 
                                                        |
| 2486 | - //we return things differently if doing ajax  | 
                                                        |
| 2487 | -        if (defined('DOING_AJAX') && DOING_AJAX) { | 
                                                        |
| 2488 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 2489 | - $this->_template_args['error'] = ! $success ? true : false;  | 
                                                        |
| 2490 | - $this->_template_args['content'] = '';  | 
                                                        |
| 2491 | - $this->_template_args['data'] = array(  | 
                                                        |
| 2492 | - 'grpID' => $edit_array['GRP_ID'],  | 
                                                        |
| 2493 | - 'templateName' => $edit_array['template_name']  | 
                                                        |
| 2494 | - );  | 
                                                        |
| 2495 | -            if ($success) { | 
                                                        |
| 2496 | - EE_Error::overwrite_success();  | 
                                                        |
| 2497 | -                EE_Error::add_success(__('The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.', | 
                                                        |
| 2498 | - 'event_espresso'));  | 
                                                        |
| 2499 | - }  | 
                                                        |
| 2484 | + }  | 
                                                        |
| 2485 | +  | 
                                                        |
| 2486 | + //we return things differently if doing ajax  | 
                                                        |
| 2487 | +		if (defined('DOING_AJAX') && DOING_AJAX) { | 
                                                        |
| 2488 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 2489 | + $this->_template_args['error'] = ! $success ? true : false;  | 
                                                        |
| 2490 | + $this->_template_args['content'] = '';  | 
                                                        |
| 2491 | + $this->_template_args['data'] = array(  | 
                                                        |
| 2492 | + 'grpID' => $edit_array['GRP_ID'],  | 
                                                        |
| 2493 | + 'templateName' => $edit_array['template_name']  | 
                                                        |
| 2494 | + );  | 
                                                        |
| 2495 | +			if ($success) { | 
                                                        |
| 2496 | + EE_Error::overwrite_success();  | 
                                                        |
| 2497 | +				EE_Error::add_success(__('The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.', | 
                                                        |
| 2498 | + 'event_espresso'));  | 
                                                        |
| 2499 | + }  | 
                                                        |
| 2500 | 2500 | |
| 2501 | - $this->_return_json();  | 
                                                        |
| 2502 | - }  | 
                                                        |
| 2503 | -  | 
                                                        |
| 2504 | -  | 
                                                        |
| 2505 | - //was a test send triggered?  | 
                                                        |
| 2506 | -        if (isset($this->_req_data['test_button'])) { | 
                                                        |
| 2507 | - EE_Error::overwrite_success();  | 
                                                        |
| 2508 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);  | 
                                                        |
| 2509 | - $override = true;  | 
                                                        |
| 2510 | - }  | 
                                                        |
| 2511 | -  | 
                                                        |
| 2512 | -        if (empty($query_args)) { | 
                                                        |
| 2513 | - $query_args = array(  | 
                                                        |
| 2514 | - 'id' => $this->_req_data['GRP_ID'],  | 
                                                        |
| 2515 | - 'context' => $context_slug,  | 
                                                        |
| 2516 | - 'action' => 'edit_message_template'  | 
                                                        |
| 2517 | - );  | 
                                                        |
| 2518 | - }  | 
                                                        |
| 2519 | -  | 
                                                        |
| 2520 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);  | 
                                                        |
| 2521 | - }  | 
                                                        |
| 2522 | -  | 
                                                        |
| 2523 | -  | 
                                                        |
| 2524 | - /**  | 
                                                        |
| 2525 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested  | 
                                                        |
| 2526 | - *  | 
                                                        |
| 2527 | - * @param string $context what context being tested  | 
                                                        |
| 2528 | - * @param string $messenger messenger being tested  | 
                                                        |
| 2529 | - * @param string $message_type message type being tested  | 
                                                        |
| 2530 | - *  | 
                                                        |
| 2531 | - */  | 
                                                        |
| 2532 | - protected function _do_test_send($context, $messenger, $message_type)  | 
                                                        |
| 2533 | -    { | 
                                                        |
| 2534 | - //set things up for preview  | 
                                                        |
| 2535 | - $this->_req_data['messenger'] = $messenger;  | 
                                                        |
| 2536 | - $this->_req_data['message_type'] = $message_type;  | 
                                                        |
| 2537 | - $this->_req_data['context'] = $context;  | 
                                                        |
| 2538 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';  | 
                                                        |
| 2539 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);  | 
                                                        |
| 2540 | -  | 
                                                        |
| 2541 | - //let's save any existing fields that might be required by the messenger  | 
                                                        |
| 2542 | - if (  | 
                                                        |
| 2543 | - isset($this->_req_data['test_settings_fld'])  | 
                                                        |
| 2544 | - && $active_messenger instanceof EE_messenger  | 
                                                        |
| 2545 | - && apply_filters(  | 
                                                        |
| 2546 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',  | 
                                                        |
| 2547 | - true,  | 
                                                        |
| 2548 | - $this->_req_data['test_settings_fld'],  | 
                                                        |
| 2549 | - $active_messenger  | 
                                                        |
| 2550 | - )  | 
                                                        |
| 2551 | -        ) { | 
                                                        |
| 2552 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);  | 
                                                        |
| 2553 | - }  | 
                                                        |
| 2554 | -  | 
                                                        |
| 2555 | - $success = $this->_preview_message(true);  | 
                                                        |
| 2556 | -  | 
                                                        |
| 2557 | -        if ($success) { | 
                                                        |
| 2558 | -            EE_Error::add_success(__('Test message sent', 'event_espresso')); | 
                                                        |
| 2559 | -        } else { | 
                                                        |
| 2560 | -            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, | 
                                                        |
| 2561 | - __LINE__);  | 
                                                        |
| 2562 | - }  | 
                                                        |
| 2563 | - }  | 
                                                        |
| 2564 | -  | 
                                                        |
| 2565 | -  | 
                                                        |
| 2566 | - /**  | 
                                                        |
| 2567 | - * _generate_new_templates  | 
                                                        |
| 2568 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 2569 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 2570 | - * for the event.  | 
                                                        |
| 2571 | - *  | 
                                                        |
| 2572 | - *  | 
                                                        |
| 2573 | - * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 2574 | - * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 2575 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to  | 
                                                        |
| 2576 | - * indicate the message_template_group being used as the base.  | 
                                                        |
| 2577 | - *  | 
                                                        |
| 2578 | - * @param bool $global  | 
                                                        |
| 2579 | - *  | 
                                                        |
| 2580 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if  | 
                                                        |
| 2581 | - * encountering problems.  | 
                                                        |
| 2582 | - * @throws \EE_Error  | 
                                                        |
| 2583 | - */  | 
                                                        |
| 2584 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 2585 | -    { | 
                                                        |
| 2586 | -  | 
                                                        |
| 2587 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.  | 
                                                        |
| 2588 | -        if (empty($message_types)) { | 
                                                        |
| 2589 | - return true;  | 
                                                        |
| 2590 | - }  | 
                                                        |
| 2591 | -  | 
                                                        |
| 2592 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);  | 
                                                        |
| 2593 | - }  | 
                                                        |
| 2594 | -  | 
                                                        |
| 2595 | -  | 
                                                        |
| 2596 | - /**  | 
                                                        |
| 2597 | - * [_trash_or_restore_message_template]  | 
                                                        |
| 2598 | - *  | 
                                                        |
| 2599 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)  | 
                                                        |
| 2600 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just  | 
                                                        |
| 2601 | - * an individual context (FALSE).  | 
                                                        |
| 2602 | - *  | 
                                                        |
| 2603 | - * @return void  | 
                                                        |
| 2604 | - */  | 
                                                        |
| 2605 | - protected function _trash_or_restore_message_template($trash = true, $all = false)  | 
                                                        |
| 2606 | -    { | 
                                                        |
| 2607 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2608 | - $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2609 | -  | 
                                                        |
| 2610 | - $success = 1;  | 
                                                        |
| 2611 | -  | 
                                                        |
| 2612 | - //incoming GRP_IDs  | 
                                                        |
| 2613 | -        if ($all) { | 
                                                        |
| 2614 | - //Checkboxes  | 
                                                        |
| 2615 | -            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 2616 | - //if array has more than one element then success message should be plural.  | 
                                                        |
| 2617 | - //todo: what about nonce?  | 
                                                        |
| 2618 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 2501 | + $this->_return_json();  | 
                                                        |
| 2502 | + }  | 
                                                        |
| 2503 | +  | 
                                                        |
| 2504 | +  | 
                                                        |
| 2505 | + //was a test send triggered?  | 
                                                        |
| 2506 | +		if (isset($this->_req_data['test_button'])) { | 
                                                        |
| 2507 | + EE_Error::overwrite_success();  | 
                                                        |
| 2508 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);  | 
                                                        |
| 2509 | + $override = true;  | 
                                                        |
| 2510 | + }  | 
                                                        |
| 2511 | +  | 
                                                        |
| 2512 | +		if (empty($query_args)) { | 
                                                        |
| 2513 | + $query_args = array(  | 
                                                        |
| 2514 | + 'id' => $this->_req_data['GRP_ID'],  | 
                                                        |
| 2515 | + 'context' => $context_slug,  | 
                                                        |
| 2516 | + 'action' => 'edit_message_template'  | 
                                                        |
| 2517 | + );  | 
                                                        |
| 2518 | + }  | 
                                                        |
| 2519 | +  | 
                                                        |
| 2520 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);  | 
                                                        |
| 2521 | + }  | 
                                                        |
| 2522 | +  | 
                                                        |
| 2523 | +  | 
                                                        |
| 2524 | + /**  | 
                                                        |
| 2525 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested  | 
                                                        |
| 2526 | + *  | 
                                                        |
| 2527 | + * @param string $context what context being tested  | 
                                                        |
| 2528 | + * @param string $messenger messenger being tested  | 
                                                        |
| 2529 | + * @param string $message_type message type being tested  | 
                                                        |
| 2530 | + *  | 
                                                        |
| 2531 | + */  | 
                                                        |
| 2532 | + protected function _do_test_send($context, $messenger, $message_type)  | 
                                                        |
| 2533 | +	{ | 
                                                        |
| 2534 | + //set things up for preview  | 
                                                        |
| 2535 | + $this->_req_data['messenger'] = $messenger;  | 
                                                        |
| 2536 | + $this->_req_data['message_type'] = $message_type;  | 
                                                        |
| 2537 | + $this->_req_data['context'] = $context;  | 
                                                        |
| 2538 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';  | 
                                                        |
| 2539 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);  | 
                                                        |
| 2540 | +  | 
                                                        |
| 2541 | + //let's save any existing fields that might be required by the messenger  | 
                                                        |
| 2542 | + if (  | 
                                                        |
| 2543 | + isset($this->_req_data['test_settings_fld'])  | 
                                                        |
| 2544 | + && $active_messenger instanceof EE_messenger  | 
                                                        |
| 2545 | + && apply_filters(  | 
                                                        |
| 2546 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',  | 
                                                        |
| 2547 | + true,  | 
                                                        |
| 2548 | + $this->_req_data['test_settings_fld'],  | 
                                                        |
| 2549 | + $active_messenger  | 
                                                        |
| 2550 | + )  | 
                                                        |
| 2551 | +		) { | 
                                                        |
| 2552 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);  | 
                                                        |
| 2553 | + }  | 
                                                        |
| 2554 | +  | 
                                                        |
| 2555 | + $success = $this->_preview_message(true);  | 
                                                        |
| 2556 | +  | 
                                                        |
| 2557 | +		if ($success) { | 
                                                        |
| 2558 | +			EE_Error::add_success(__('Test message sent', 'event_espresso')); | 
                                                        |
| 2559 | +		} else { | 
                                                        |
| 2560 | +			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, | 
                                                        |
| 2561 | + __LINE__);  | 
                                                        |
| 2562 | + }  | 
                                                        |
| 2563 | + }  | 
                                                        |
| 2564 | +  | 
                                                        |
| 2565 | +  | 
                                                        |
| 2566 | + /**  | 
                                                        |
| 2567 | + * _generate_new_templates  | 
                                                        |
| 2568 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 2569 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 2570 | + * for the event.  | 
                                                        |
| 2571 | + *  | 
                                                        |
| 2572 | + *  | 
                                                        |
| 2573 | + * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 2574 | + * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 2575 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to  | 
                                                        |
| 2576 | + * indicate the message_template_group being used as the base.  | 
                                                        |
| 2577 | + *  | 
                                                        |
| 2578 | + * @param bool $global  | 
                                                        |
| 2579 | + *  | 
                                                        |
| 2580 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if  | 
                                                        |
| 2581 | + * encountering problems.  | 
                                                        |
| 2582 | + * @throws \EE_Error  | 
                                                        |
| 2583 | + */  | 
                                                        |
| 2584 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 2585 | +	{ | 
                                                        |
| 2586 | +  | 
                                                        |
| 2587 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.  | 
                                                        |
| 2588 | +		if (empty($message_types)) { | 
                                                        |
| 2589 | + return true;  | 
                                                        |
| 2590 | + }  | 
                                                        |
| 2591 | +  | 
                                                        |
| 2592 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);  | 
                                                        |
| 2593 | + }  | 
                                                        |
| 2594 | +  | 
                                                        |
| 2595 | +  | 
                                                        |
| 2596 | + /**  | 
                                                        |
| 2597 | + * [_trash_or_restore_message_template]  | 
                                                        |
| 2598 | + *  | 
                                                        |
| 2599 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)  | 
                                                        |
| 2600 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just  | 
                                                        |
| 2601 | + * an individual context (FALSE).  | 
                                                        |
| 2602 | + *  | 
                                                        |
| 2603 | + * @return void  | 
                                                        |
| 2604 | + */  | 
                                                        |
| 2605 | + protected function _trash_or_restore_message_template($trash = true, $all = false)  | 
                                                        |
| 2606 | +	{ | 
                                                        |
| 2607 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2608 | + $MTP = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2609 | +  | 
                                                        |
| 2610 | + $success = 1;  | 
                                                        |
| 2611 | +  | 
                                                        |
| 2612 | + //incoming GRP_IDs  | 
                                                        |
| 2613 | +		if ($all) { | 
                                                        |
| 2614 | + //Checkboxes  | 
                                                        |
| 2615 | +			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 2616 | + //if array has more than one element then success message should be plural.  | 
                                                        |
| 2617 | + //todo: what about nonce?  | 
                                                        |
| 2618 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 2619 | 2619 | |
| 2620 | - //cycle through checkboxes  | 
                                                        |
| 2621 | -                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 2622 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);  | 
                                                        |
| 2623 | -                    if ( ! $trashed_or_restored) { | 
                                                        |
| 2624 | - $success = 0;  | 
                                                        |
| 2625 | - }  | 
                                                        |
| 2626 | - }  | 
                                                        |
| 2627 | -            } else { | 
                                                        |
| 2628 | - //grab single GRP_ID and handle  | 
                                                        |
| 2629 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;  | 
                                                        |
| 2630 | -                if ( ! empty($GRP_ID)) { | 
                                                        |
| 2631 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);  | 
                                                        |
| 2632 | -                    if ( ! $trashed_or_restored) { | 
                                                        |
| 2633 | - $success = 0;  | 
                                                        |
| 2634 | - }  | 
                                                        |
| 2635 | -                } else { | 
                                                        |
| 2636 | - $success = 0;  | 
                                                        |
| 2637 | - }  | 
                                                        |
| 2638 | - }  | 
                                                        |
| 2620 | + //cycle through checkboxes  | 
                                                        |
| 2621 | +				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 2622 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);  | 
                                                        |
| 2623 | +					if ( ! $trashed_or_restored) { | 
                                                        |
| 2624 | + $success = 0;  | 
                                                        |
| 2625 | + }  | 
                                                        |
| 2626 | + }  | 
                                                        |
| 2627 | +			} else { | 
                                                        |
| 2628 | + //grab single GRP_ID and handle  | 
                                                        |
| 2629 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;  | 
                                                        |
| 2630 | +				if ( ! empty($GRP_ID)) { | 
                                                        |
| 2631 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);  | 
                                                        |
| 2632 | +					if ( ! $trashed_or_restored) { | 
                                                        |
| 2633 | + $success = 0;  | 
                                                        |
| 2634 | + }  | 
                                                        |
| 2635 | +				} else { | 
                                                        |
| 2636 | + $success = 0;  | 
                                                        |
| 2637 | + }  | 
                                                        |
| 2638 | + }  | 
                                                        |
| 2639 | 2639 | |
| 2640 | - }  | 
                                                        |
| 2640 | + }  | 
                                                        |
| 2641 | 2641 | |
| 2642 | -        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); | 
                                                        |
| 2642 | +		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); | 
                                                        |
| 2643 | 2643 | |
| 2644 | -        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; | 
                                                        |
| 2644 | +		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; | 
                                                        |
| 2645 | 2645 | |
| 2646 | -        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, | 
                                                        |
| 2647 | -            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | 
                                                        |
| 2646 | +		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, | 
                                                        |
| 2647 | +			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | 
                                                        |
| 2648 | 2648 | |
| 2649 | -        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, | 
                                                        |
| 2650 | - 'event_espresso') : $item_desc;  | 
                                                        |
| 2649 | +		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, | 
                                                        |
| 2650 | + 'event_espresso') : $item_desc;  | 
                                                        |
| 2651 | 2651 | |
| 2652 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array());  | 
                                                        |
| 2652 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array());  | 
                                                        |
| 2653 | 2653 | |
| 2654 | - }  | 
                                                        |
| 2654 | + }  | 
                                                        |
| 2655 | 2655 | |
| 2656 | 2656 | |
| 2657 | - /**  | 
                                                        |
| 2658 | - * [_delete_message_template]  | 
                                                        |
| 2659 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.  | 
                                                        |
| 2660 | - * @return void  | 
                                                        |
| 2661 | - */  | 
                                                        |
| 2662 | - protected function _delete_message_template()  | 
                                                        |
| 2663 | -    { | 
                                                        |
| 2664 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2657 | + /**  | 
                                                        |
| 2658 | + * [_delete_message_template]  | 
                                                        |
| 2659 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.  | 
                                                        |
| 2660 | + * @return void  | 
                                                        |
| 2661 | + */  | 
                                                        |
| 2662 | + protected function _delete_message_template()  | 
                                                        |
| 2663 | +	{ | 
                                                        |
| 2664 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 2665 | 2665 | |
| 2666 | - //checkboxes  | 
                                                        |
| 2667 | -        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 2668 | - //if array has more than one element then success message should be plural  | 
                                                        |
| 2669 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 2666 | + //checkboxes  | 
                                                        |
| 2667 | +		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | 
                                                        |
| 2668 | + //if array has more than one element then success message should be plural  | 
                                                        |
| 2669 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;  | 
                                                        |
| 2670 | 2670 | |
| 2671 | - //cycle through bulk action checkboxes  | 
                                                        |
| 2672 | -            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 2673 | - $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 2674 | - }  | 
                                                        |
| 2675 | -        } else { | 
                                                        |
| 2676 | - //grab single grp_id and delete  | 
                                                        |
| 2677 | - $GRP_ID = absint($this->_req_data['id']);  | 
                                                        |
| 2678 | - $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 2679 | - }  | 
                                                        |
| 2680 | -  | 
                                                        |
| 2681 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());  | 
                                                        |
| 2682 | -  | 
                                                        |
| 2683 | - }  | 
                                                        |
| 2684 | -  | 
                                                        |
| 2685 | -  | 
                                                        |
| 2686 | - /**  | 
                                                        |
| 2687 | - * helper for permanently deleting a mtP group and all related message_templates  | 
                                                        |
| 2688 | - *  | 
                                                        |
| 2689 | - * @param int $GRP_ID The group being deleted  | 
                                                        |
| 2690 | - * @param bool $include_group whether to delete the Message Template Group as well.  | 
                                                        |
| 2691 | - *  | 
                                                        |
| 2692 | - * @return bool boolean to indicate the success of the deletes or not.  | 
                                                        |
| 2693 | - */  | 
                                                        |
| 2694 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true)  | 
                                                        |
| 2695 | -    { | 
                                                        |
| 2696 | - $success = 1;  | 
                                                        |
| 2697 | - $MTPG = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2698 | - //first let's GET this group  | 
                                                        |
| 2699 | - $MTG = $MTPG->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2700 | - //then delete permanently all the related Message Templates  | 
                                                        |
| 2701 | -        $deleted = $MTG->delete_related_permanently('Message_Template'); | 
                                                        |
| 2702 | -  | 
                                                        |
| 2703 | -        if ($deleted === 0) { | 
                                                        |
| 2704 | - $success = 0;  | 
                                                        |
| 2705 | - }  | 
                                                        |
| 2706 | -  | 
                                                        |
| 2707 | - //now delete permanently this particular group  | 
                                                        |
| 2708 | -  | 
                                                        |
| 2709 | -        if ($include_group && ! $MTG->delete_permanently()) { | 
                                                        |
| 2710 | - $success = 0;  | 
                                                        |
| 2711 | - }  | 
                                                        |
| 2712 | -  | 
                                                        |
| 2713 | - return $success;  | 
                                                        |
| 2714 | - }  | 
                                                        |
| 2715 | -  | 
                                                        |
| 2716 | -  | 
                                                        |
| 2717 | - /**  | 
                                                        |
| 2718 | - * _learn_more_about_message_templates_link  | 
                                                        |
| 2719 | - * @access protected  | 
                                                        |
| 2720 | - * @return string  | 
                                                        |
| 2721 | - */  | 
                                                        |
| 2722 | - protected function _learn_more_about_message_templates_link()  | 
                                                        |
| 2723 | -    { | 
                                                        |
| 2724 | -        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', | 
                                                        |
| 2725 | - 'event_espresso') . '</a>';  | 
                                                        |
| 2726 | - }  | 
                                                        |
| 2727 | -  | 
                                                        |
| 2728 | -  | 
                                                        |
| 2729 | - /**  | 
                                                        |
| 2730 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by  | 
                                                        |
| 2731 | - * ajax and other routes.  | 
                                                        |
| 2732 | - * @return void  | 
                                                        |
| 2733 | - */  | 
                                                        |
| 2734 | - protected function _settings()  | 
                                                        |
| 2735 | -    { | 
                                                        |
| 2736 | -  | 
                                                        |
| 2737 | -  | 
                                                        |
| 2738 | - $this->_set_m_mt_settings();  | 
                                                        |
| 2739 | -  | 
                                                        |
| 2740 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2741 | -  | 
                                                        |
| 2742 | - //let's setup the messenger tabs  | 
                                                        |
| 2743 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],  | 
                                                        |
| 2744 | - 'messenger_links', '|', $selected_messenger);  | 
                                                        |
| 2745 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';  | 
                                                        |
| 2746 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';  | 
                                                        |
| 2747 | -  | 
                                                        |
| 2748 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2749 | -  | 
                                                        |
| 2750 | - }  | 
                                                        |
| 2751 | -  | 
                                                        |
| 2752 | -  | 
                                                        |
| 2753 | - /**  | 
                                                        |
| 2754 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)  | 
                                                        |
| 2755 | - *  | 
                                                        |
| 2756 | - * @access protected  | 
                                                        |
| 2757 | - * @return void  | 
                                                        |
| 2758 | - */  | 
                                                        |
| 2759 | - protected function _set_m_mt_settings()  | 
                                                        |
| 2760 | -    { | 
                                                        |
| 2761 | - //first if this is already set then lets get out no need to regenerate data.  | 
                                                        |
| 2762 | -        if ( ! empty($this->_m_mt_settings)) { | 
                                                        |
| 2763 | - return;  | 
                                                        |
| 2764 | - }  | 
                                                        |
| 2765 | -  | 
                                                        |
| 2766 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2767 | -  | 
                                                        |
| 2768 | - //get all installed messengers and message_types  | 
                                                        |
| 2769 | - /** @type EE_messenger[] $messengers */  | 
                                                        |
| 2770 | - $messengers = $this->_message_resource_manager->installed_messengers();  | 
                                                        |
| 2771 | - /** @type EE_message_type[] $message_types */  | 
                                                        |
| 2772 | - $message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 2773 | -  | 
                                                        |
| 2774 | -  | 
                                                        |
| 2775 | - //assemble the array for the _tab_text_links helper  | 
                                                        |
| 2776 | -  | 
                                                        |
| 2777 | -        foreach ($messengers as $messenger) { | 
                                                        |
| 2778 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(  | 
                                                        |
| 2779 | - 'label' => ucwords($messenger->label['singular']),  | 
                                                        |
| 2780 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',  | 
                                                        |
| 2781 | - 'href' => $messenger->name,  | 
                                                        |
| 2782 | -                'title' => __('Modify this Messenger', 'event_espresso'), | 
                                                        |
| 2783 | - 'slug' => $messenger->name,  | 
                                                        |
| 2784 | - 'obj' => $messenger  | 
                                                        |
| 2785 | - );  | 
                                                        |
| 2671 | + //cycle through bulk action checkboxes  | 
                                                        |
| 2672 | +			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | 
                                                        |
| 2673 | + $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 2674 | + }  | 
                                                        |
| 2675 | +		} else { | 
                                                        |
| 2676 | + //grab single grp_id and delete  | 
                                                        |
| 2677 | + $GRP_ID = absint($this->_req_data['id']);  | 
                                                        |
| 2678 | + $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 2679 | + }  | 
                                                        |
| 2680 | +  | 
                                                        |
| 2681 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());  | 
                                                        |
| 2682 | +  | 
                                                        |
| 2683 | + }  | 
                                                        |
| 2684 | +  | 
                                                        |
| 2685 | +  | 
                                                        |
| 2686 | + /**  | 
                                                        |
| 2687 | + * helper for permanently deleting a mtP group and all related message_templates  | 
                                                        |
| 2688 | + *  | 
                                                        |
| 2689 | + * @param int $GRP_ID The group being deleted  | 
                                                        |
| 2690 | + * @param bool $include_group whether to delete the Message Template Group as well.  | 
                                                        |
| 2691 | + *  | 
                                                        |
| 2692 | + * @return bool boolean to indicate the success of the deletes or not.  | 
                                                        |
| 2693 | + */  | 
                                                        |
| 2694 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true)  | 
                                                        |
| 2695 | +	{ | 
                                                        |
| 2696 | + $success = 1;  | 
                                                        |
| 2697 | + $MTPG = EEM_Message_Template_Group::instance();  | 
                                                        |
| 2698 | + //first let's GET this group  | 
                                                        |
| 2699 | + $MTG = $MTPG->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2700 | + //then delete permanently all the related Message Templates  | 
                                                        |
| 2701 | +		$deleted = $MTG->delete_related_permanently('Message_Template'); | 
                                                        |
| 2702 | +  | 
                                                        |
| 2703 | +		if ($deleted === 0) { | 
                                                        |
| 2704 | + $success = 0;  | 
                                                        |
| 2705 | + }  | 
                                                        |
| 2706 | +  | 
                                                        |
| 2707 | + //now delete permanently this particular group  | 
                                                        |
| 2708 | +  | 
                                                        |
| 2709 | +		if ($include_group && ! $MTG->delete_permanently()) { | 
                                                        |
| 2710 | + $success = 0;  | 
                                                        |
| 2711 | + }  | 
                                                        |
| 2712 | +  | 
                                                        |
| 2713 | + return $success;  | 
                                                        |
| 2714 | + }  | 
                                                        |
| 2715 | +  | 
                                                        |
| 2716 | +  | 
                                                        |
| 2717 | + /**  | 
                                                        |
| 2718 | + * _learn_more_about_message_templates_link  | 
                                                        |
| 2719 | + * @access protected  | 
                                                        |
| 2720 | + * @return string  | 
                                                        |
| 2721 | + */  | 
                                                        |
| 2722 | + protected function _learn_more_about_message_templates_link()  | 
                                                        |
| 2723 | +	{ | 
                                                        |
| 2724 | +		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', | 
                                                        |
| 2725 | + 'event_espresso') . '</a>';  | 
                                                        |
| 2726 | + }  | 
                                                        |
| 2727 | +  | 
                                                        |
| 2728 | +  | 
                                                        |
| 2729 | + /**  | 
                                                        |
| 2730 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by  | 
                                                        |
| 2731 | + * ajax and other routes.  | 
                                                        |
| 2732 | + * @return void  | 
                                                        |
| 2733 | + */  | 
                                                        |
| 2734 | + protected function _settings()  | 
                                                        |
| 2735 | +	{ | 
                                                        |
| 2736 | +  | 
                                                        |
| 2737 | +  | 
                                                        |
| 2738 | + $this->_set_m_mt_settings();  | 
                                                        |
| 2739 | +  | 
                                                        |
| 2740 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2741 | +  | 
                                                        |
| 2742 | + //let's setup the messenger tabs  | 
                                                        |
| 2743 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],  | 
                                                        |
| 2744 | + 'messenger_links', '|', $selected_messenger);  | 
                                                        |
| 2745 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';  | 
                                                        |
| 2746 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';  | 
                                                        |
| 2747 | +  | 
                                                        |
| 2748 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 2749 | +  | 
                                                        |
| 2750 | + }  | 
                                                        |
| 2751 | +  | 
                                                        |
| 2752 | +  | 
                                                        |
| 2753 | + /**  | 
                                                        |
| 2754 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)  | 
                                                        |
| 2755 | + *  | 
                                                        |
| 2756 | + * @access protected  | 
                                                        |
| 2757 | + * @return void  | 
                                                        |
| 2758 | + */  | 
                                                        |
| 2759 | + protected function _set_m_mt_settings()  | 
                                                        |
| 2760 | +	{ | 
                                                        |
| 2761 | + //first if this is already set then lets get out no need to regenerate data.  | 
                                                        |
| 2762 | +		if ( ! empty($this->_m_mt_settings)) { | 
                                                        |
| 2763 | + return;  | 
                                                        |
| 2764 | + }  | 
                                                        |
| 2765 | +  | 
                                                        |
| 2766 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2767 | +  | 
                                                        |
| 2768 | + //get all installed messengers and message_types  | 
                                                        |
| 2769 | + /** @type EE_messenger[] $messengers */  | 
                                                        |
| 2770 | + $messengers = $this->_message_resource_manager->installed_messengers();  | 
                                                        |
| 2771 | + /** @type EE_message_type[] $message_types */  | 
                                                        |
| 2772 | + $message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 2773 | +  | 
                                                        |
| 2774 | +  | 
                                                        |
| 2775 | + //assemble the array for the _tab_text_links helper  | 
                                                        |
| 2776 | +  | 
                                                        |
| 2777 | +		foreach ($messengers as $messenger) { | 
                                                        |
| 2778 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(  | 
                                                        |
| 2779 | + 'label' => ucwords($messenger->label['singular']),  | 
                                                        |
| 2780 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',  | 
                                                        |
| 2781 | + 'href' => $messenger->name,  | 
                                                        |
| 2782 | +				'title' => __('Modify this Messenger', 'event_espresso'), | 
                                                        |
| 2783 | + 'slug' => $messenger->name,  | 
                                                        |
| 2784 | + 'obj' => $messenger  | 
                                                        |
| 2785 | + );  | 
                                                        |
| 2786 | 2786 | |
| 2787 | 2787 | |
| 2788 | - $message_types_for_messenger = $messenger->get_valid_message_types();  | 
                                                        |
| 2788 | + $message_types_for_messenger = $messenger->get_valid_message_types();  | 
                                                        |
| 2789 | 2789 | |
| 2790 | -            foreach ($message_types as $message_type) { | 
                                                        |
| 2791 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.  | 
                                                        |
| 2792 | -                if ( ! in_array($message_type->name, $message_types_for_messenger)) { | 
                                                        |
| 2793 | - continue;  | 
                                                        |
| 2794 | - }  | 
                                                        |
| 2790 | +			foreach ($message_types as $message_type) { | 
                                                        |
| 2791 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.  | 
                                                        |
| 2792 | +				if ( ! in_array($message_type->name, $message_types_for_messenger)) { | 
                                                        |
| 2793 | + continue;  | 
                                                        |
| 2794 | + }  | 
                                                        |
| 2795 | 2795 | |
| 2796 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,  | 
                                                        |
| 2797 | - $message_type->name) ? 'active' : 'inactive';  | 
                                                        |
| 2796 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,  | 
                                                        |
| 2797 | + $message_type->name) ? 'active' : 'inactive';  | 
                                                        |
| 2798 | 2798 | |
| 2799 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(  | 
                                                        |
| 2800 | - 'label' => ucwords($message_type->label['singular']),  | 
                                                        |
| 2801 | - 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 2802 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 2803 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 2804 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 2805 | - 'title' => $a_or_i == 'active'  | 
                                                        |
| 2806 | -                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        |
| 2807 | -                        : __('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        |
| 2808 | - 'content' => $a_or_i == 'active'  | 
                                                        |
| 2809 | - ? $this->_message_type_settings_content($message_type, $messenger, true)  | 
                                                        |
| 2810 | - : $this->_message_type_settings_content($message_type, $messenger),  | 
                                                        |
| 2811 | - 'slug' => $message_type->name,  | 
                                                        |
| 2812 | - 'active' => $a_or_i == 'active' ? true : false,  | 
                                                        |
| 2813 | - 'obj' => $message_type  | 
                                                        |
| 2814 | - );  | 
                                                        |
| 2815 | - }  | 
                                                        |
| 2816 | - }  | 
                                                        |
| 2817 | - }  | 
                                                        |
| 2818 | -  | 
                                                        |
| 2819 | -  | 
                                                        |
| 2820 | - /**  | 
                                                        |
| 2821 | - * This just prepares the content for the message type settings  | 
                                                        |
| 2822 | - *  | 
                                                        |
| 2823 | - * @param object $message_type The message type object  | 
                                                        |
| 2824 | - * @param object $messenger The messenger object  | 
                                                        |
| 2825 | - * @param boolean $active Whether the message type is active or not  | 
                                                        |
| 2826 | - *  | 
                                                        |
| 2827 | - * @return string html output for the content  | 
                                                        |
| 2828 | - */  | 
                                                        |
| 2829 | - protected function _message_type_settings_content($message_type, $messenger, $active = false)  | 
                                                        |
| 2830 | -    { | 
                                                        |
| 2831 | - //get message type fields  | 
                                                        |
| 2832 | - $fields = $message_type->get_admin_settings_fields();  | 
                                                        |
| 2833 | - $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 2834 | -  | 
                                                        |
| 2835 | -        if ( ! empty($fields) && $active) { | 
                                                        |
| 2799 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(  | 
                                                        |
| 2800 | + 'label' => ucwords($message_type->label['singular']),  | 
                                                        |
| 2801 | + 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 2802 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 2803 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 2804 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 2805 | + 'title' => $a_or_i == 'active'  | 
                                                        |
| 2806 | +						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        |
| 2807 | +						: __('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        |
| 2808 | + 'content' => $a_or_i == 'active'  | 
                                                        |
| 2809 | + ? $this->_message_type_settings_content($message_type, $messenger, true)  | 
                                                        |
| 2810 | + : $this->_message_type_settings_content($message_type, $messenger),  | 
                                                        |
| 2811 | + 'slug' => $message_type->name,  | 
                                                        |
| 2812 | + 'active' => $a_or_i == 'active' ? true : false,  | 
                                                        |
| 2813 | + 'obj' => $message_type  | 
                                                        |
| 2814 | + );  | 
                                                        |
| 2815 | + }  | 
                                                        |
| 2816 | + }  | 
                                                        |
| 2817 | + }  | 
                                                        |
| 2818 | +  | 
                                                        |
| 2819 | +  | 
                                                        |
| 2820 | + /**  | 
                                                        |
| 2821 | + * This just prepares the content for the message type settings  | 
                                                        |
| 2822 | + *  | 
                                                        |
| 2823 | + * @param object $message_type The message type object  | 
                                                        |
| 2824 | + * @param object $messenger The messenger object  | 
                                                        |
| 2825 | + * @param boolean $active Whether the message type is active or not  | 
                                                        |
| 2826 | + *  | 
                                                        |
| 2827 | + * @return string html output for the content  | 
                                                        |
| 2828 | + */  | 
                                                        |
| 2829 | + protected function _message_type_settings_content($message_type, $messenger, $active = false)  | 
                                                        |
| 2830 | +	{ | 
                                                        |
| 2831 | + //get message type fields  | 
                                                        |
| 2832 | + $fields = $message_type->get_admin_settings_fields();  | 
                                                        |
| 2833 | + $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 2834 | +  | 
                                                        |
| 2835 | +		if ( ! empty($fields) && $active) { | 
                                                        |
| 2836 | 2836 | |
| 2837 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        |
| 2837 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        |
| 2838 | 2838 | |
| 2839 | -            foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 2840 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 2841 | - $template_form_field[$field_id] = array(  | 
                                                        |
| 2842 | - 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 2843 | - 'label' => $fldprops['label'],  | 
                                                        |
| 2844 | - 'input' => $fldprops['field_type'],  | 
                                                        |
| 2845 | - 'type' => $fldprops['value_type'],  | 
                                                        |
| 2846 | - 'required' => $fldprops['required'],  | 
                                                        |
| 2847 | - 'validation' => $fldprops['validation'],  | 
                                                        |
| 2848 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],  | 
                                                        |
| 2849 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(),  | 
                                                        |
| 2850 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],  | 
                                                        |
| 2851 | - 'css_class' => 'no-drag',  | 
                                                        |
| 2852 | - 'format' => $fldprops['format']  | 
                                                        |
| 2853 | - );  | 
                                                        |
| 2854 | - }  | 
                                                        |
| 2839 | +			foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 2840 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 2841 | + $template_form_field[$field_id] = array(  | 
                                                        |
| 2842 | + 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 2843 | + 'label' => $fldprops['label'],  | 
                                                        |
| 2844 | + 'input' => $fldprops['field_type'],  | 
                                                        |
| 2845 | + 'type' => $fldprops['value_type'],  | 
                                                        |
| 2846 | + 'required' => $fldprops['required'],  | 
                                                        |
| 2847 | + 'validation' => $fldprops['validation'],  | 
                                                        |
| 2848 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],  | 
                                                        |
| 2849 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(),  | 
                                                        |
| 2850 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],  | 
                                                        |
| 2851 | + 'css_class' => 'no-drag',  | 
                                                        |
| 2852 | + 'format' => $fldprops['format']  | 
                                                        |
| 2853 | + );  | 
                                                        |
| 2854 | + }  | 
                                                        |
| 2855 | 2855 | |
| 2856 | 2856 | |
| 2857 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,  | 
                                                        |
| 2858 | - 'string', 'ee_mt_activate_form') : '';  | 
                                                        |
| 2859 | - }  | 
                                                        |
| 2860 | -  | 
                                                        |
| 2861 | - $settings_template_args['description'] = $message_type->description;  | 
                                                        |
| 2862 | - //we also need some hidden fields  | 
                                                        |
| 2863 | - $settings_template_args['hidden_fields'] = array(  | 
                                                        |
| 2864 | - 'message_type_settings[messenger]' => array(  | 
                                                        |
| 2865 | - 'type' => 'hidden',  | 
                                                        |
| 2866 | - 'value' => $messenger->name  | 
                                                        |
| 2867 | - ),  | 
                                                        |
| 2868 | - 'message_type_settings[message_type]' => array(  | 
                                                        |
| 2869 | - 'type' => 'hidden',  | 
                                                        |
| 2870 | - 'value' => $message_type->name  | 
                                                        |
| 2871 | - ),  | 
                                                        |
| 2872 | - 'type' => array(  | 
                                                        |
| 2873 | - 'type' => 'hidden',  | 
                                                        |
| 2874 | - 'value' => 'message_type'  | 
                                                        |
| 2875 | - )  | 
                                                        |
| 2876 | - );  | 
                                                        |
| 2877 | -  | 
                                                        |
| 2878 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],  | 
                                                        |
| 2879 | - 'array');  | 
                                                        |
| 2880 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';  | 
                                                        |
| 2881 | -  | 
                                                        |
| 2882 | -  | 
                                                        |
| 2883 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 2884 | - $content = EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        |
| 2885 | -  | 
                                                        |
| 2886 | - return $content;  | 
                                                        |
| 2887 | - }  | 
                                                        |
| 2888 | -  | 
                                                        |
| 2889 | -  | 
                                                        |
| 2890 | - /**  | 
                                                        |
| 2891 | - * Generate all the metaboxes for the message types and register them for the messages settings page.  | 
                                                        |
| 2892 | - *  | 
                                                        |
| 2893 | - * @access protected  | 
                                                        |
| 2894 | - * @return void  | 
                                                        |
| 2895 | - */  | 
                                                        |
| 2896 | - protected function _messages_settings_metaboxes()  | 
                                                        |
| 2897 | -    { | 
                                                        |
| 2898 | - $this->_set_m_mt_settings();  | 
                                                        |
| 2899 | - $m_boxes = $mt_boxes = array();  | 
                                                        |
| 2900 | - $m_template_args = $mt_template_args = array();  | 
                                                        |
| 2901 | -  | 
                                                        |
| 2902 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2903 | -  | 
                                                        |
| 2904 | -        if (isset($this->_m_mt_settings['messenger_tabs'])) { | 
                                                        |
| 2905 | -            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | 
                                                        |
| 2906 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';  | 
                                                        |
| 2907 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';  | 
                                                        |
| 2908 | - //messenger meta boxes  | 
                                                        |
| 2909 | - $active = $selected_messenger == $messenger ? true : false;  | 
                                                        |
| 2910 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])  | 
                                                        |
| 2911 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']  | 
                                                        |
| 2912 | - : '';  | 
                                                        |
| 2913 | - $m_boxes[$messenger . '_a_box'] = sprintf(  | 
                                                        |
| 2914 | -                    __('%s Settings', 'event_espresso'), | 
                                                        |
| 2915 | - $tab_array['label']  | 
                                                        |
| 2916 | - );  | 
                                                        |
| 2917 | - $m_template_args[$messenger . '_a_box'] = array(  | 
                                                        |
| 2918 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 2919 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2920 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2921 | - : '',  | 
                                                        |
| 2922 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']),  | 
                                                        |
| 2923 | - 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 2924 | - 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 2925 | - 'messenger' => $messenger,  | 
                                                        |
| 2926 | - 'active' => $active  | 
                                                        |
| 2927 | - );  | 
                                                        |
| 2928 | - // message type meta boxes  | 
                                                        |
| 2929 | - // (which is really just the inactive container for each messenger  | 
                                                        |
| 2930 | - // showing inactive message types for that messenger)  | 
                                                        |
| 2931 | -                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 2932 | - $mt_template_args[$messenger . '_i_box'] = array(  | 
                                                        |
| 2933 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 2934 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2935 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2936 | - : '',  | 
                                                        |
| 2937 | - 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 2938 | - 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 2939 | - 'hide_off_message' => $hide_off_message,  | 
                                                        |
| 2940 | - 'messenger' => $messenger,  | 
                                                        |
| 2941 | - 'active' => $active  | 
                                                        |
| 2942 | - );  | 
                                                        |
| 2943 | - }  | 
                                                        |
| 2944 | - }  | 
                                                        |
| 2945 | -  | 
                                                        |
| 2946 | -  | 
                                                        |
| 2947 | - //register messenger metaboxes  | 
                                                        |
| 2948 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 2949 | -        foreach ($m_boxes as $box => $label) { | 
                                                        |
| 2950 | -            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); | 
                                                        |
| 2951 | -            $msgr          = str_replace('_a_box', '', $box); | 
                                                        |
| 2952 | - add_meta_box(  | 
                                                        |
| 2953 | - 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 2954 | - $label,  | 
                                                        |
| 2955 | -                function ($post, $metabox) { | 
                                                        |
| 2956 | - echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        |
| 2957 | - $metabox["args"]["template_args"], true);  | 
                                                        |
| 2958 | - },  | 
                                                        |
| 2959 | - $this->_current_screen->id,  | 
                                                        |
| 2960 | - 'normal',  | 
                                                        |
| 2961 | - 'high',  | 
                                                        |
| 2962 | - $callback_args  | 
                                                        |
| 2963 | - );  | 
                                                        |
| 2964 | - }  | 
                                                        |
| 2965 | -  | 
                                                        |
| 2966 | - //register message type metaboxes  | 
                                                        |
| 2967 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 2968 | -        foreach ($mt_boxes as $box => $label) { | 
                                                        |
| 2969 | - $callback_args = array(  | 
                                                        |
| 2970 | - 'template_path' => $mt_template_path,  | 
                                                        |
| 2971 | - 'template_args' => $mt_template_args[$box]  | 
                                                        |
| 2972 | - );  | 
                                                        |
| 2973 | -            $mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 2974 | - add_meta_box(  | 
                                                        |
| 2975 | - 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 2976 | - $label,  | 
                                                        |
| 2977 | -                function ($post, $metabox) { | 
                                                        |
| 2978 | - echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        |
| 2979 | - $metabox["args"]["template_args"], true);  | 
                                                        |
| 2980 | - },  | 
                                                        |
| 2981 | - $this->_current_screen->id,  | 
                                                        |
| 2982 | - 'side',  | 
                                                        |
| 2983 | - 'high',  | 
                                                        |
| 2984 | - $callback_args  | 
                                                        |
| 2985 | - );  | 
                                                        |
| 2986 | - }  | 
                                                        |
| 2987 | -  | 
                                                        |
| 2988 | - //register metabox for global messages settings but only when on the main site. On single site installs this will  | 
                                                        |
| 2989 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site.  | 
                                                        |
| 2990 | -        if (is_main_site()) { | 
                                                        |
| 2991 | - add_meta_box(  | 
                                                        |
| 2992 | - 'espresso_global_message_settings',  | 
                                                        |
| 2993 | -                __('Global Message Settings', 'event_espresso'), | 
                                                        |
| 2994 | - array($this, 'global_messages_settings_metabox_content'),  | 
                                                        |
| 2995 | - $this->_current_screen->id,  | 
                                                        |
| 2996 | - 'normal',  | 
                                                        |
| 2997 | - 'low',  | 
                                                        |
| 2998 | - array()  | 
                                                        |
| 2999 | - );  | 
                                                        |
| 3000 | - }  | 
                                                        |
| 3001 | -  | 
                                                        |
| 3002 | - }  | 
                                                        |
| 3003 | -  | 
                                                        |
| 3004 | -  | 
                                                        |
| 3005 | - /**  | 
                                                        |
| 3006 | - * This generates the content for the global messages settings metabox.  | 
                                                        |
| 3007 | - * @return string  | 
                                                        |
| 3008 | - */  | 
                                                        |
| 3009 | - public function global_messages_settings_metabox_content()  | 
                                                        |
| 3010 | -    { | 
                                                        |
| 3011 | - $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3012 | - echo $form->form_open(  | 
                                                        |
| 3013 | -                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), | 
                                                        |
| 3014 | - 'POST'  | 
                                                        |
| 3015 | - )  | 
                                                        |
| 3016 | - . $form->get_html()  | 
                                                        |
| 3017 | - . $form->form_close();  | 
                                                        |
| 3018 | - }  | 
                                                        |
| 3019 | -  | 
                                                        |
| 3020 | -  | 
                                                        |
| 3021 | - /**  | 
                                                        |
| 3022 | - * This generates and returns the form object for the global messages settings.  | 
                                                        |
| 3023 | - * @return EE_Form_Section_Proper  | 
                                                        |
| 3024 | - */  | 
                                                        |
| 3025 | - protected function _generate_global_settings_form()  | 
                                                        |
| 3026 | -    { | 
                                                        |
| 3027 | -        EE_Registry::instance()->load_helper('HTML'); | 
                                                        |
| 3028 | - /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3029 | - $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3030 | -  | 
                                                        |
| 3031 | - return new EE_Form_Section_Proper(  | 
                                                        |
| 3032 | - array(  | 
                                                        |
| 3033 | - 'name' => 'global_messages_settings',  | 
                                                        |
| 3034 | - 'html_id' => 'global_messages_settings',  | 
                                                        |
| 3035 | - 'html_class' => 'form-table',  | 
                                                        |
| 3036 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 3037 | - 'subsections' => apply_filters(  | 
                                                        |
| 3038 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',  | 
                                                        |
| 3039 | - array(  | 
                                                        |
| 3040 | - 'do_messages_on_same_request' => new EE_Select_Input(  | 
                                                        |
| 3041 | - array(  | 
                                                        |
| 3042 | -                                true  => esc_html__("On the same request", "event_espresso"), | 
                                                        |
| 3043 | -                                false => esc_html__("On a separate request", "event_espresso") | 
                                                        |
| 3044 | - ),  | 
                                                        |
| 3045 | - array(  | 
                                                        |
| 3046 | - 'default' => $network_config->do_messages_on_same_request,  | 
                                                        |
| 3047 | -                                'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), | 
                                                        |
| 3048 | -                                'html_help_text'  => esc_html__('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.', | 
                                                        |
| 3049 | - 'event_espresso'),  | 
                                                        |
| 3050 | - )  | 
                                                        |
| 3051 | - ),  | 
                                                        |
| 3052 | - 'delete_threshold' => new EE_Select_Input(  | 
                                                        |
| 3053 | - array(  | 
                                                        |
| 3054 | -                                0 => esc_html__('Forever', 'event_espresso'), | 
                                                        |
| 3055 | -                                3 => esc_html__('3 Months', 'event_espresso'), | 
                                                        |
| 3056 | -                                6 => esc_html__('6 Months', 'event_espresso'), | 
                                                        |
| 3057 | -                                9 => esc_html__('9 Months', 'event_espresso'), | 
                                                        |
| 3058 | -                                12 => esc_html__('12 Months', 'event_espresso'), | 
                                                        |
| 3059 | -                                24 => esc_html__('24 Months', 'event_espresso'), | 
                                                        |
| 3060 | -                                36 => esc_html__('36 Months', 'event_espresso') | 
                                                        |
| 3061 | - ),  | 
                                                        |
| 3062 | - array(  | 
                                                        |
| 3063 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold,  | 
                                                        |
| 3064 | -                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | 
                                                        |
| 3065 | -                                'html_help_text' => esc_html__('You can control how long a record of processed messages is kept  | 
                                                        |
| 2857 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,  | 
                                                        |
| 2858 | + 'string', 'ee_mt_activate_form') : '';  | 
                                                        |
| 2859 | + }  | 
                                                        |
| 2860 | +  | 
                                                        |
| 2861 | + $settings_template_args['description'] = $message_type->description;  | 
                                                        |
| 2862 | + //we also need some hidden fields  | 
                                                        |
| 2863 | + $settings_template_args['hidden_fields'] = array(  | 
                                                        |
| 2864 | + 'message_type_settings[messenger]' => array(  | 
                                                        |
| 2865 | + 'type' => 'hidden',  | 
                                                        |
| 2866 | + 'value' => $messenger->name  | 
                                                        |
| 2867 | + ),  | 
                                                        |
| 2868 | + 'message_type_settings[message_type]' => array(  | 
                                                        |
| 2869 | + 'type' => 'hidden',  | 
                                                        |
| 2870 | + 'value' => $message_type->name  | 
                                                        |
| 2871 | + ),  | 
                                                        |
| 2872 | + 'type' => array(  | 
                                                        |
| 2873 | + 'type' => 'hidden',  | 
                                                        |
| 2874 | + 'value' => 'message_type'  | 
                                                        |
| 2875 | + )  | 
                                                        |
| 2876 | + );  | 
                                                        |
| 2877 | +  | 
                                                        |
| 2878 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],  | 
                                                        |
| 2879 | + 'array');  | 
                                                        |
| 2880 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';  | 
                                                        |
| 2881 | +  | 
                                                        |
| 2882 | +  | 
                                                        |
| 2883 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 2884 | + $content = EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        |
| 2885 | +  | 
                                                        |
| 2886 | + return $content;  | 
                                                        |
| 2887 | + }  | 
                                                        |
| 2888 | +  | 
                                                        |
| 2889 | +  | 
                                                        |
| 2890 | + /**  | 
                                                        |
| 2891 | + * Generate all the metaboxes for the message types and register them for the messages settings page.  | 
                                                        |
| 2892 | + *  | 
                                                        |
| 2893 | + * @access protected  | 
                                                        |
| 2894 | + * @return void  | 
                                                        |
| 2895 | + */  | 
                                                        |
| 2896 | + protected function _messages_settings_metaboxes()  | 
                                                        |
| 2897 | +	{ | 
                                                        |
| 2898 | + $this->_set_m_mt_settings();  | 
                                                        |
| 2899 | + $m_boxes = $mt_boxes = array();  | 
                                                        |
| 2900 | + $m_template_args = $mt_template_args = array();  | 
                                                        |
| 2901 | +  | 
                                                        |
| 2902 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';  | 
                                                        |
| 2903 | +  | 
                                                        |
| 2904 | +		if (isset($this->_m_mt_settings['messenger_tabs'])) { | 
                                                        |
| 2905 | +			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | 
                                                        |
| 2906 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';  | 
                                                        |
| 2907 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';  | 
                                                        |
| 2908 | + //messenger meta boxes  | 
                                                        |
| 2909 | + $active = $selected_messenger == $messenger ? true : false;  | 
                                                        |
| 2910 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])  | 
                                                        |
| 2911 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']  | 
                                                        |
| 2912 | + : '';  | 
                                                        |
| 2913 | + $m_boxes[$messenger . '_a_box'] = sprintf(  | 
                                                        |
| 2914 | +					__('%s Settings', 'event_espresso'), | 
                                                        |
| 2915 | + $tab_array['label']  | 
                                                        |
| 2916 | + );  | 
                                                        |
| 2917 | + $m_template_args[$messenger . '_a_box'] = array(  | 
                                                        |
| 2918 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 2919 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2920 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2921 | + : '',  | 
                                                        |
| 2922 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']),  | 
                                                        |
| 2923 | + 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 2924 | + 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 2925 | + 'messenger' => $messenger,  | 
                                                        |
| 2926 | + 'active' => $active  | 
                                                        |
| 2927 | + );  | 
                                                        |
| 2928 | + // message type meta boxes  | 
                                                        |
| 2929 | + // (which is really just the inactive container for each messenger  | 
                                                        |
| 2930 | + // showing inactive message types for that messenger)  | 
                                                        |
| 2931 | +				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 2932 | + $mt_template_args[$messenger . '_i_box'] = array(  | 
                                                        |
| 2933 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 2934 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2935 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 2936 | + : '',  | 
                                                        |
| 2937 | + 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 2938 | + 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 2939 | + 'hide_off_message' => $hide_off_message,  | 
                                                        |
| 2940 | + 'messenger' => $messenger,  | 
                                                        |
| 2941 | + 'active' => $active  | 
                                                        |
| 2942 | + );  | 
                                                        |
| 2943 | + }  | 
                                                        |
| 2944 | + }  | 
                                                        |
| 2945 | +  | 
                                                        |
| 2946 | +  | 
                                                        |
| 2947 | + //register messenger metaboxes  | 
                                                        |
| 2948 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 2949 | +		foreach ($m_boxes as $box => $label) { | 
                                                        |
| 2950 | +			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); | 
                                                        |
| 2951 | +			$msgr          = str_replace('_a_box', '', $box); | 
                                                        |
| 2952 | + add_meta_box(  | 
                                                        |
| 2953 | + 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 2954 | + $label,  | 
                                                        |
| 2955 | +				function ($post, $metabox) { | 
                                                        |
| 2956 | + echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        |
| 2957 | + $metabox["args"]["template_args"], true);  | 
                                                        |
| 2958 | + },  | 
                                                        |
| 2959 | + $this->_current_screen->id,  | 
                                                        |
| 2960 | + 'normal',  | 
                                                        |
| 2961 | + 'high',  | 
                                                        |
| 2962 | + $callback_args  | 
                                                        |
| 2963 | + );  | 
                                                        |
| 2964 | + }  | 
                                                        |
| 2965 | +  | 
                                                        |
| 2966 | + //register message type metaboxes  | 
                                                        |
| 2967 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 2968 | +		foreach ($mt_boxes as $box => $label) { | 
                                                        |
| 2969 | + $callback_args = array(  | 
                                                        |
| 2970 | + 'template_path' => $mt_template_path,  | 
                                                        |
| 2971 | + 'template_args' => $mt_template_args[$box]  | 
                                                        |
| 2972 | + );  | 
                                                        |
| 2973 | +			$mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 2974 | + add_meta_box(  | 
                                                        |
| 2975 | + 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 2976 | + $label,  | 
                                                        |
| 2977 | +				function ($post, $metabox) { | 
                                                        |
| 2978 | + echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        |
| 2979 | + $metabox["args"]["template_args"], true);  | 
                                                        |
| 2980 | + },  | 
                                                        |
| 2981 | + $this->_current_screen->id,  | 
                                                        |
| 2982 | + 'side',  | 
                                                        |
| 2983 | + 'high',  | 
                                                        |
| 2984 | + $callback_args  | 
                                                        |
| 2985 | + );  | 
                                                        |
| 2986 | + }  | 
                                                        |
| 2987 | +  | 
                                                        |
| 2988 | + //register metabox for global messages settings but only when on the main site. On single site installs this will  | 
                                                        |
| 2989 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site.  | 
                                                        |
| 2990 | +		if (is_main_site()) { | 
                                                        |
| 2991 | + add_meta_box(  | 
                                                        |
| 2992 | + 'espresso_global_message_settings',  | 
                                                        |
| 2993 | +				__('Global Message Settings', 'event_espresso'), | 
                                                        |
| 2994 | + array($this, 'global_messages_settings_metabox_content'),  | 
                                                        |
| 2995 | + $this->_current_screen->id,  | 
                                                        |
| 2996 | + 'normal',  | 
                                                        |
| 2997 | + 'low',  | 
                                                        |
| 2998 | + array()  | 
                                                        |
| 2999 | + );  | 
                                                        |
| 3000 | + }  | 
                                                        |
| 3001 | +  | 
                                                        |
| 3002 | + }  | 
                                                        |
| 3003 | +  | 
                                                        |
| 3004 | +  | 
                                                        |
| 3005 | + /**  | 
                                                        |
| 3006 | + * This generates the content for the global messages settings metabox.  | 
                                                        |
| 3007 | + * @return string  | 
                                                        |
| 3008 | + */  | 
                                                        |
| 3009 | + public function global_messages_settings_metabox_content()  | 
                                                        |
| 3010 | +	{ | 
                                                        |
| 3011 | + $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3012 | + echo $form->form_open(  | 
                                                        |
| 3013 | +				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), | 
                                                        |
| 3014 | + 'POST'  | 
                                                        |
| 3015 | + )  | 
                                                        |
| 3016 | + . $form->get_html()  | 
                                                        |
| 3017 | + . $form->form_close();  | 
                                                        |
| 3018 | + }  | 
                                                        |
| 3019 | +  | 
                                                        |
| 3020 | +  | 
                                                        |
| 3021 | + /**  | 
                                                        |
| 3022 | + * This generates and returns the form object for the global messages settings.  | 
                                                        |
| 3023 | + * @return EE_Form_Section_Proper  | 
                                                        |
| 3024 | + */  | 
                                                        |
| 3025 | + protected function _generate_global_settings_form()  | 
                                                        |
| 3026 | +	{ | 
                                                        |
| 3027 | +		EE_Registry::instance()->load_helper('HTML'); | 
                                                        |
| 3028 | + /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3029 | + $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3030 | +  | 
                                                        |
| 3031 | + return new EE_Form_Section_Proper(  | 
                                                        |
| 3032 | + array(  | 
                                                        |
| 3033 | + 'name' => 'global_messages_settings',  | 
                                                        |
| 3034 | + 'html_id' => 'global_messages_settings',  | 
                                                        |
| 3035 | + 'html_class' => 'form-table',  | 
                                                        |
| 3036 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 3037 | + 'subsections' => apply_filters(  | 
                                                        |
| 3038 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',  | 
                                                        |
| 3039 | + array(  | 
                                                        |
| 3040 | + 'do_messages_on_same_request' => new EE_Select_Input(  | 
                                                        |
| 3041 | + array(  | 
                                                        |
| 3042 | +								true  => esc_html__("On the same request", "event_espresso"), | 
                                                        |
| 3043 | +								false => esc_html__("On a separate request", "event_espresso") | 
                                                        |
| 3044 | + ),  | 
                                                        |
| 3045 | + array(  | 
                                                        |
| 3046 | + 'default' => $network_config->do_messages_on_same_request,  | 
                                                        |
| 3047 | +								'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), | 
                                                        |
| 3048 | +								'html_help_text'  => esc_html__('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.', | 
                                                        |
| 3049 | + 'event_espresso'),  | 
                                                        |
| 3050 | + )  | 
                                                        |
| 3051 | + ),  | 
                                                        |
| 3052 | + 'delete_threshold' => new EE_Select_Input(  | 
                                                        |
| 3053 | + array(  | 
                                                        |
| 3054 | +								0 => esc_html__('Forever', 'event_espresso'), | 
                                                        |
| 3055 | +								3 => esc_html__('3 Months', 'event_espresso'), | 
                                                        |
| 3056 | +								6 => esc_html__('6 Months', 'event_espresso'), | 
                                                        |
| 3057 | +								9 => esc_html__('9 Months', 'event_espresso'), | 
                                                        |
| 3058 | +								12 => esc_html__('12 Months', 'event_espresso'), | 
                                                        |
| 3059 | +								24 => esc_html__('24 Months', 'event_espresso'), | 
                                                        |
| 3060 | +								36 => esc_html__('36 Months', 'event_espresso') | 
                                                        |
| 3061 | + ),  | 
                                                        |
| 3062 | + array(  | 
                                                        |
| 3063 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold,  | 
                                                        |
| 3064 | +								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | 
                                                        |
| 3065 | +								'html_help_text' => esc_html__('You can control how long a record of processed messages is kept  | 
                                                        |
| 3066 | 3066 | via this option.', 'event_espresso'),  | 
                                                        
| 3067 | - )  | 
                                                        |
| 3068 | - ),  | 
                                                        |
| 3069 | - 'update_settings' => new EE_Submit_Input(  | 
                                                        |
| 3070 | - array(  | 
                                                        |
| 3071 | -                                'default'         => esc_html__('Update', 'event_espresso'), | 
                                                        |
| 3072 | - 'html_label_text' => ' '  | 
                                                        |
| 3073 | - )  | 
                                                        |
| 3074 | - )  | 
                                                        |
| 3075 | - )  | 
                                                        |
| 3076 | - )  | 
                                                        |
| 3077 | - )  | 
                                                        |
| 3078 | - );  | 
                                                        |
| 3079 | - }  | 
                                                        |
| 3080 | -  | 
                                                        |
| 3081 | -  | 
                                                        |
| 3082 | - /**  | 
                                                        |
| 3083 | - * This handles updating the global settings set on the admin page.  | 
                                                        |
| 3084 | - * @throws \EE_Error  | 
                                                        |
| 3085 | - */  | 
                                                        |
| 3086 | - protected function _update_global_settings()  | 
                                                        |
| 3087 | -    { | 
                                                        |
| 3088 | - /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3089 | - $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3090 | - $messages_config = EE_Registry::instance()->CFG->messages;  | 
                                                        |
| 3091 | - $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3092 | -        if ($form->was_submitted()) { | 
                                                        |
| 3093 | - $form->receive_form_submission();  | 
                                                        |
| 3094 | -            if ($form->is_valid()) { | 
                                                        |
| 3095 | - $valid_data = $form->valid_data();  | 
                                                        |
| 3096 | -                foreach ($valid_data as $property => $value) { | 
                                                        |
| 3097 | - $setter = 'set_' . $property;  | 
                                                        |
| 3098 | -                    if (method_exists($network_config, $setter)) { | 
                                                        |
| 3099 | -                        $network_config->{$setter}($value); | 
                                                        |
| 3100 | - } else if (  | 
                                                        |
| 3101 | - property_exists($network_config, $property)  | 
                                                        |
| 3102 | -                        && $network_config->{$property} !== $value | 
                                                        |
| 3103 | -                    ) { | 
                                                        |
| 3104 | -                        $network_config->{$property} = $value; | 
                                                        |
| 3105 | - } else if (  | 
                                                        |
| 3106 | - property_exists($messages_config, $property)  | 
                                                        |
| 3107 | -                        && $messages_config->{$property} !== $value | 
                                                        |
| 3108 | -                    ) { | 
                                                        |
| 3109 | -                        $messages_config->{$property} = $value; | 
                                                        |
| 3110 | - }  | 
                                                        |
| 3111 | - }  | 
                                                        |
| 3112 | - //only update if the form submission was valid!  | 
                                                        |
| 3113 | - EE_Registry::instance()->NET_CFG->update_config(true, false);  | 
                                                        |
| 3114 | - EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 3115 | - EE_Error::overwrite_success();  | 
                                                        |
| 3116 | -                EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); | 
                                                        |
| 3117 | - }  | 
                                                        |
| 3118 | - }  | 
                                                        |
| 3119 | -        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); | 
                                                        |
| 3120 | - }  | 
                                                        |
| 3121 | -  | 
                                                        |
| 3122 | -  | 
                                                        |
| 3123 | - /**  | 
                                                        |
| 3124 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate  | 
                                                        |
| 3125 | - *  | 
                                                        |
| 3126 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs  | 
                                                        |
| 3127 | - *  | 
                                                        |
| 3128 | - * @return string html formatted tabs  | 
                                                        |
| 3129 | - */  | 
                                                        |
| 3130 | - protected function _get_mt_tabs($tab_array)  | 
                                                        |
| 3131 | -    { | 
                                                        |
| 3132 | - $tab_array = (array)$tab_array;  | 
                                                        |
| 3133 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3134 | - $tabs = '';  | 
                                                        |
| 3135 | -  | 
                                                        |
| 3136 | -        foreach ($tab_array as $tab) { | 
                                                        |
| 3137 | - $tabs .= EEH_Template::display_template($template, $tab, true);  | 
                                                        |
| 3138 | - }  | 
                                                        |
| 3139 | -  | 
                                                        |
| 3140 | - return $tabs;  | 
                                                        |
| 3141 | - }  | 
                                                        |
| 3142 | -  | 
                                                        |
| 3143 | -  | 
                                                        |
| 3144 | - /**  | 
                                                        |
| 3145 | - * This prepares the content of the messenger meta box admin settings  | 
                                                        |
| 3146 | - *  | 
                                                        |
| 3147 | - * @param EE_messenger $messenger The messenger we're setting up content for  | 
                                                        |
| 3148 | - *  | 
                                                        |
| 3149 | - * @return string html formatted content  | 
                                                        |
| 3150 | - */  | 
                                                        |
| 3151 | - protected function _get_messenger_box_content(EE_messenger $messenger)  | 
                                                        |
| 3152 | -    { | 
                                                        |
| 3153 | -  | 
                                                        |
| 3154 | - $fields = $messenger->get_admin_settings_fields();  | 
                                                        |
| 3155 | - $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3156 | -  | 
                                                        |
| 3157 | - //is $messenger active?  | 
                                                        |
| 3158 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3159 | -  | 
                                                        |
| 3160 | -  | 
                                                        |
| 3161 | -        if ( ! empty($fields)) { | 
                                                        |
| 3067 | + )  | 
                                                        |
| 3068 | + ),  | 
                                                        |
| 3069 | + 'update_settings' => new EE_Submit_Input(  | 
                                                        |
| 3070 | + array(  | 
                                                        |
| 3071 | +								'default'         => esc_html__('Update', 'event_espresso'), | 
                                                        |
| 3072 | + 'html_label_text' => ' '  | 
                                                        |
| 3073 | + )  | 
                                                        |
| 3074 | + )  | 
                                                        |
| 3075 | + )  | 
                                                        |
| 3076 | + )  | 
                                                        |
| 3077 | + )  | 
                                                        |
| 3078 | + );  | 
                                                        |
| 3079 | + }  | 
                                                        |
| 3080 | +  | 
                                                        |
| 3081 | +  | 
                                                        |
| 3082 | + /**  | 
                                                        |
| 3083 | + * This handles updating the global settings set on the admin page.  | 
                                                        |
| 3084 | + * @throws \EE_Error  | 
                                                        |
| 3085 | + */  | 
                                                        |
| 3086 | + protected function _update_global_settings()  | 
                                                        |
| 3087 | +	{ | 
                                                        |
| 3088 | + /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3089 | + $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3090 | + $messages_config = EE_Registry::instance()->CFG->messages;  | 
                                                        |
| 3091 | + $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3092 | +		if ($form->was_submitted()) { | 
                                                        |
| 3093 | + $form->receive_form_submission();  | 
                                                        |
| 3094 | +			if ($form->is_valid()) { | 
                                                        |
| 3095 | + $valid_data = $form->valid_data();  | 
                                                        |
| 3096 | +				foreach ($valid_data as $property => $value) { | 
                                                        |
| 3097 | + $setter = 'set_' . $property;  | 
                                                        |
| 3098 | +					if (method_exists($network_config, $setter)) { | 
                                                        |
| 3099 | +						$network_config->{$setter}($value); | 
                                                        |
| 3100 | + } else if (  | 
                                                        |
| 3101 | + property_exists($network_config, $property)  | 
                                                        |
| 3102 | +						&& $network_config->{$property} !== $value | 
                                                        |
| 3103 | +					) { | 
                                                        |
| 3104 | +						$network_config->{$property} = $value; | 
                                                        |
| 3105 | + } else if (  | 
                                                        |
| 3106 | + property_exists($messages_config, $property)  | 
                                                        |
| 3107 | +						&& $messages_config->{$property} !== $value | 
                                                        |
| 3108 | +					) { | 
                                                        |
| 3109 | +						$messages_config->{$property} = $value; | 
                                                        |
| 3110 | + }  | 
                                                        |
| 3111 | + }  | 
                                                        |
| 3112 | + //only update if the form submission was valid!  | 
                                                        |
| 3113 | + EE_Registry::instance()->NET_CFG->update_config(true, false);  | 
                                                        |
| 3114 | + EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 3115 | + EE_Error::overwrite_success();  | 
                                                        |
| 3116 | +				EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); | 
                                                        |
| 3117 | + }  | 
                                                        |
| 3118 | + }  | 
                                                        |
| 3119 | +		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); | 
                                                        |
| 3120 | + }  | 
                                                        |
| 3121 | +  | 
                                                        |
| 3122 | +  | 
                                                        |
| 3123 | + /**  | 
                                                        |
| 3124 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate  | 
                                                        |
| 3125 | + *  | 
                                                        |
| 3126 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs  | 
                                                        |
| 3127 | + *  | 
                                                        |
| 3128 | + * @return string html formatted tabs  | 
                                                        |
| 3129 | + */  | 
                                                        |
| 3130 | + protected function _get_mt_tabs($tab_array)  | 
                                                        |
| 3131 | +	{ | 
                                                        |
| 3132 | + $tab_array = (array)$tab_array;  | 
                                                        |
| 3133 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3134 | + $tabs = '';  | 
                                                        |
| 3135 | +  | 
                                                        |
| 3136 | +		foreach ($tab_array as $tab) { | 
                                                        |
| 3137 | + $tabs .= EEH_Template::display_template($template, $tab, true);  | 
                                                        |
| 3138 | + }  | 
                                                        |
| 3139 | +  | 
                                                        |
| 3140 | + return $tabs;  | 
                                                        |
| 3141 | + }  | 
                                                        |
| 3142 | +  | 
                                                        |
| 3143 | +  | 
                                                        |
| 3144 | + /**  | 
                                                        |
| 3145 | + * This prepares the content of the messenger meta box admin settings  | 
                                                        |
| 3146 | + *  | 
                                                        |
| 3147 | + * @param EE_messenger $messenger The messenger we're setting up content for  | 
                                                        |
| 3148 | + *  | 
                                                        |
| 3149 | + * @return string html formatted content  | 
                                                        |
| 3150 | + */  | 
                                                        |
| 3151 | + protected function _get_messenger_box_content(EE_messenger $messenger)  | 
                                                        |
| 3152 | +	{ | 
                                                        |
| 3153 | +  | 
                                                        |
| 3154 | + $fields = $messenger->get_admin_settings_fields();  | 
                                                        |
| 3155 | + $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3156 | +  | 
                                                        |
| 3157 | + //is $messenger active?  | 
                                                        |
| 3158 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3159 | +  | 
                                                        |
| 3160 | +  | 
                                                        |
| 3161 | +		if ( ! empty($fields)) { | 
                                                        |
| 3162 | 3162 | |
| 3163 | - $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        |
| 3163 | + $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        |
| 3164 | 3164 | |
| 3165 | -            foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 3166 | - $field_id = $messenger->name . '-' . $fldname;  | 
                                                        |
| 3167 | - $template_form_field[$field_id] = array(  | 
                                                        |
| 3168 | - 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3169 | - 'label' => $fldprops['label'],  | 
                                                        |
| 3170 | - 'input' => $fldprops['field_type'],  | 
                                                        |
| 3171 | - 'type' => $fldprops['value_type'],  | 
                                                        |
| 3172 | - 'required' => $fldprops['required'],  | 
                                                        |
| 3173 | - 'validation' => $fldprops['validation'],  | 
                                                        |
| 3174 | - 'value' => isset($existing_settings[$field_id])  | 
                                                        |
| 3175 | - ? $existing_settings[$field_id]  | 
                                                        |
| 3176 | - : $fldprops['default'],  | 
                                                        |
| 3177 | - 'css_class' => '',  | 
                                                        |
| 3178 | - 'format' => $fldprops['format']  | 
                                                        |
| 3179 | - );  | 
                                                        |
| 3180 | - }  | 
                                                        |
| 3165 | +			foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 3166 | + $field_id = $messenger->name . '-' . $fldname;  | 
                                                        |
| 3167 | + $template_form_field[$field_id] = array(  | 
                                                        |
| 3168 | + 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3169 | + 'label' => $fldprops['label'],  | 
                                                        |
| 3170 | + 'input' => $fldprops['field_type'],  | 
                                                        |
| 3171 | + 'type' => $fldprops['value_type'],  | 
                                                        |
| 3172 | + 'required' => $fldprops['required'],  | 
                                                        |
| 3173 | + 'validation' => $fldprops['validation'],  | 
                                                        |
| 3174 | + 'value' => isset($existing_settings[$field_id])  | 
                                                        |
| 3175 | + ? $existing_settings[$field_id]  | 
                                                        |
| 3176 | + : $fldprops['default'],  | 
                                                        |
| 3177 | + 'css_class' => '',  | 
                                                        |
| 3178 | + 'format' => $fldprops['format']  | 
                                                        |
| 3179 | + );  | 
                                                        |
| 3180 | + }  | 
                                                        |
| 3181 | 3181 | |
| 3182 | 3182 | |
| 3183 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3184 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')  | 
                                                        |
| 3185 | - : '';  | 
                                                        |
| 3186 | - }  | 
                                                        |
| 3187 | -  | 
                                                        |
| 3188 | - //we also need some hidden fields  | 
                                                        |
| 3189 | - $settings_template_args['hidden_fields'] = array(  | 
                                                        |
| 3190 | - 'messenger_settings[messenger]' => array(  | 
                                                        |
| 3191 | - 'type' => 'hidden',  | 
                                                        |
| 3192 | - 'value' => $messenger->name  | 
                                                        |
| 3193 | - ),  | 
                                                        |
| 3194 | - 'type' => array(  | 
                                                        |
| 3195 | - 'type' => 'hidden',  | 
                                                        |
| 3196 | - 'value' => 'messenger'  | 
                                                        |
| 3197 | - )  | 
                                                        |
| 3198 | - );  | 
                                                        |
| 3199 | -  | 
                                                        |
| 3200 | - //make sure any active message types that are existing are included in the hidden fields  | 
                                                        |
| 3201 | -        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { | 
                                                        |
| 3202 | -            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { | 
                                                        |
| 3203 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(  | 
                                                        |
| 3204 | - 'type' => 'hidden',  | 
                                                        |
| 3205 | - 'value' => $mt  | 
                                                        |
| 3206 | - );  | 
                                                        |
| 3207 | - }  | 
                                                        |
| 3208 | - }  | 
                                                        |
| 3209 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3210 | - $settings_template_args['hidden_fields'],  | 
                                                        |
| 3211 | - 'array'  | 
                                                        |
| 3212 | - );  | 
                                                        |
| 3213 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3214 | -  | 
                                                        |
| 3215 | - $settings_template_args['messenger'] = $messenger->name;  | 
                                                        |
| 3216 | - $settings_template_args['description'] = $messenger->description;  | 
                                                        |
| 3217 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';  | 
                                                        |
| 3218 | -  | 
                                                        |
| 3219 | -  | 
                                                        |
| 3220 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)  | 
                                                        |
| 3221 | - ? $settings_template_args['show_hide_edit_form']  | 
                                                        |
| 3222 | - : ' hidden';  | 
                                                        |
| 3223 | -  | 
                                                        |
| 3224 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3225 | - ? ' hidden'  | 
                                                        |
| 3226 | - : $settings_template_args['show_hide_edit_form'];  | 
                                                        |
| 3227 | -  | 
                                                        |
| 3228 | -  | 
                                                        |
| 3229 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        |
| 3230 | -        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3231 | - $settings_template_args['on_off_status'] = $active ? true : false;  | 
                                                        |
| 3232 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3233 | - $content = EEH_Template::display_template($template, $settings_template_args,  | 
                                                        |
| 3234 | - true);  | 
                                                        |
| 3235 | -  | 
                                                        |
| 3236 | - return $content;  | 
                                                        |
| 3237 | - }  | 
                                                        |
| 3238 | -  | 
                                                        |
| 3239 | -  | 
                                                        |
| 3240 | - /**  | 
                                                        |
| 3241 | - * used by ajax on the messages settings page to activate|deactivate the messenger  | 
                                                        |
| 3242 | - */  | 
                                                        |
| 3243 | - public function activate_messenger_toggle()  | 
                                                        |
| 3244 | -    { | 
                                                        |
| 3245 | - $success = true;  | 
                                                        |
| 3246 | - $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3247 | - //let's check that we have required data  | 
                                                        |
| 3248 | -        if ( ! isset($this->_req_data['messenger'])) { | 
                                                        |
| 3249 | - EE_Error::add_error(  | 
                                                        |
| 3250 | -                __('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3251 | - __FILE__,  | 
                                                        |
| 3252 | - __FUNCTION__,  | 
                                                        |
| 3253 | - __LINE__  | 
                                                        |
| 3254 | - );  | 
                                                        |
| 3255 | - $success = false;  | 
                                                        |
| 3256 | - }  | 
                                                        |
| 3257 | -  | 
                                                        |
| 3258 | - //do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 3259 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';  | 
                                                        |
| 3260 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';  | 
                                                        |
| 3261 | -  | 
                                                        |
| 3262 | - $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 3263 | -  | 
                                                        |
| 3264 | -  | 
                                                        |
| 3265 | -        if ( ! isset($this->_req_data['status'])) { | 
                                                        |
| 3266 | - EE_Error::add_error(  | 
                                                        |
| 3267 | - __(  | 
                                                        |
| 3268 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 3269 | - 'event_espresso'  | 
                                                        |
| 3270 | - ),  | 
                                                        |
| 3271 | - __FILE__,  | 
                                                        |
| 3272 | - __FUNCTION__,  | 
                                                        |
| 3273 | - __LINE__  | 
                                                        |
| 3274 | - );  | 
                                                        |
| 3275 | - $success = false;  | 
                                                        |
| 3276 | - }  | 
                                                        |
| 3277 | -  | 
                                                        |
| 3278 | - //do check to verify we have a valid status.  | 
                                                        |
| 3279 | - $status = $this->_req_data['status'];  | 
                                                        |
| 3280 | -  | 
                                                        |
| 3281 | -        if ($status != 'off' && $status != 'on') { | 
                                                        |
| 3282 | - EE_Error::add_error(  | 
                                                        |
| 3283 | - sprintf(  | 
                                                        |
| 3284 | -                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 3285 | - $this->_req_data['status']  | 
                                                        |
| 3286 | - ),  | 
                                                        |
| 3287 | - __FILE__,  | 
                                                        |
| 3288 | - __FUNCTION__,  | 
                                                        |
| 3289 | - __LINE__  | 
                                                        |
| 3290 | - );  | 
                                                        |
| 3291 | - $success = false;  | 
                                                        |
| 3292 | - }  | 
                                                        |
| 3293 | -  | 
                                                        |
| 3294 | -        if ($success) { | 
                                                        |
| 3295 | - //made it here? Stop dawdling then!!  | 
                                                        |
| 3296 | - $success = $status == 'off'  | 
                                                        |
| 3297 | - ? $this->_deactivate_messenger($this->_req_data['messenger'])  | 
                                                        |
| 3298 | - : $this->_activate_messenger($this->_req_data['messenger']);  | 
                                                        |
| 3299 | - }  | 
                                                        |
| 3300 | -  | 
                                                        |
| 3301 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 3302 | -  | 
                                                        |
| 3303 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff).  | 
                                                        |
| 3304 | - $this->_return_json();  | 
                                                        |
| 3305 | -  | 
                                                        |
| 3306 | - }  | 
                                                        |
| 3307 | -  | 
                                                        |
| 3308 | -  | 
                                                        |
| 3309 | - /**  | 
                                                        |
| 3310 | - * used by ajax from the messages settings page to activate|deactivate a message type  | 
                                                        |
| 3311 | - *  | 
                                                        |
| 3312 | - */  | 
                                                        |
| 3313 | - public function activate_mt_toggle()  | 
                                                        |
| 3314 | -    { | 
                                                        |
| 3315 | - $success = true;  | 
                                                        |
| 3316 | - $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3317 | -  | 
                                                        |
| 3318 | - //let's make sure we have the necessary data  | 
                                                        |
| 3319 | -        if ( ! isset($this->_req_data['message_type'])) { | 
                                                        |
| 3320 | - EE_Error::add_error(  | 
                                                        |
| 3321 | -                __('Message Type name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3322 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3323 | - );  | 
                                                        |
| 3324 | - $success = false;  | 
                                                        |
| 3325 | - }  | 
                                                        |
| 3326 | -  | 
                                                        |
| 3327 | -        if ( ! isset($this->_req_data['messenger'])) { | 
                                                        |
| 3328 | - EE_Error::add_error(  | 
                                                        |
| 3329 | -                __('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3330 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3331 | - );  | 
                                                        |
| 3332 | - $success = false;  | 
                                                        |
| 3333 | - }  | 
                                                        |
| 3334 | -  | 
                                                        |
| 3335 | -        if ( ! isset($this->_req_data['status'])) { | 
                                                        |
| 3336 | - EE_Error::add_error(  | 
                                                        |
| 3337 | -                __('Messenger status needed to know whether activation or deactivation is happening. No status is given', | 
                                                        |
| 3338 | - 'event_espresso'),  | 
                                                        |
| 3339 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3340 | - );  | 
                                                        |
| 3341 | - $success = false;  | 
                                                        |
| 3342 | - }  | 
                                                        |
| 3343 | -  | 
                                                        |
| 3344 | -  | 
                                                        |
| 3345 | - //do check to verify we have a valid status.  | 
                                                        |
| 3346 | - $status = $this->_req_data['status'];  | 
                                                        |
| 3347 | -  | 
                                                        |
| 3348 | -        if ($status != 'activate' && $status != 'deactivate') { | 
                                                        |
| 3349 | - EE_Error::add_error(  | 
                                                        |
| 3350 | - sprintf(  | 
                                                        |
| 3351 | -                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | 
                                                        |
| 3352 | - $this->_req_data['status']  | 
                                                        |
| 3353 | - ),  | 
                                                        |
| 3354 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3355 | - );  | 
                                                        |
| 3356 | - $success = false;  | 
                                                        |
| 3357 | - }  | 
                                                        |
| 3358 | -  | 
                                                        |
| 3359 | -  | 
                                                        |
| 3360 | - //do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 3361 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';  | 
                                                        |
| 3362 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce';  | 
                                                        |
| 3363 | -  | 
                                                        |
| 3364 | - $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 3365 | -  | 
                                                        |
| 3366 | -        if ($success) { | 
                                                        |
| 3367 | - //made it here? um, what are you waiting for then?  | 
                                                        |
| 3368 | - $success = $status == 'deactivate'  | 
                                                        |
| 3369 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],  | 
                                                        |
| 3370 | - $this->_req_data['message_type'])  | 
                                                        |
| 3371 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],  | 
                                                        |
| 3372 | - $this->_req_data['message_type']);  | 
                                                        |
| 3373 | - }  | 
                                                        |
| 3374 | -  | 
                                                        |
| 3375 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 3376 | - $this->_return_json();  | 
                                                        |
| 3377 | - }  | 
                                                        |
| 3378 | -  | 
                                                        |
| 3379 | -  | 
                                                        |
| 3380 | - /**  | 
                                                        |
| 3381 | - * Takes care of processing activating a messenger and preparing the appropriate response.  | 
                                                        |
| 3382 | - *  | 
                                                        |
| 3383 | - * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 3384 | - *  | 
                                                        |
| 3385 | - * @return bool  | 
                                                        |
| 3386 | - */  | 
                                                        |
| 3387 | - protected function _activate_messenger($messenger_name)  | 
                                                        |
| 3388 | -    { | 
                                                        |
| 3389 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3390 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3391 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();  | 
                                                        |
| 3392 | -  | 
                                                        |
| 3393 | - //ensure is active  | 
                                                        |
| 3394 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);  | 
                                                        |
| 3395 | -  | 
                                                        |
| 3396 | - //set response_data for reload  | 
                                                        |
| 3397 | -        foreach ($message_types_to_activate as $message_type_name) { | 
                                                        |
| 3398 | - /** @var EE_message_type $message_type */  | 
                                                        |
| 3399 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3400 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,  | 
                                                        |
| 3401 | - $message_type_name)  | 
                                                        |
| 3402 | - && $message_type instanceof EE_message_type  | 
                                                        |
| 3403 | -            ) { | 
                                                        |
| 3404 | - $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 3405 | -                if ($message_type->get_admin_settings_fields()) { | 
                                                        |
| 3406 | - $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 3407 | - }  | 
                                                        |
| 3408 | - }  | 
                                                        |
| 3409 | - }  | 
                                                        |
| 3410 | -  | 
                                                        |
| 3411 | - //add success message for activating messenger  | 
                                                        |
| 3412 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 3413 | -  | 
                                                        |
| 3414 | - }  | 
                                                        |
| 3415 | -  | 
                                                        |
| 3416 | -  | 
                                                        |
| 3417 | - /**  | 
                                                        |
| 3418 | - * Takes care of processing deactivating a messenger and preparing the appropriate response.  | 
                                                        |
| 3419 | - *  | 
                                                        |
| 3420 | - * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 3421 | - *  | 
                                                        |
| 3422 | - * @return bool  | 
                                                        |
| 3423 | - */  | 
                                                        |
| 3424 | - protected function _deactivate_messenger($messenger_name)  | 
                                                        |
| 3425 | -    { | 
                                                        |
| 3426 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3427 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3428 | - $this->_message_resource_manager->deactivate_messenger($messenger_name);  | 
                                                        |
| 3429 | -  | 
                                                        |
| 3430 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 3431 | - }  | 
                                                        |
| 3432 | -  | 
                                                        |
| 3433 | -  | 
                                                        |
| 3434 | - /**  | 
                                                        |
| 3435 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 3436 | - *  | 
                                                        |
| 3437 | - * @param string $messenger_name The name of the messenger the message type is being activated for.  | 
                                                        |
| 3438 | - * @param string $message_type_name The name of the message type being activated for the messenger  | 
                                                        |
| 3439 | - *  | 
                                                        |
| 3440 | - * @return bool  | 
                                                        |
| 3441 | - */  | 
                                                        |
| 3442 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 3443 | -    { | 
                                                        |
| 3444 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3445 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3446 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3447 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3448 | -  | 
                                                        |
| 3449 | - //ensure is active  | 
                                                        |
| 3450 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);  | 
                                                        |
| 3451 | -  | 
                                                        |
| 3452 | - //set response for load  | 
                                                        |
| 3453 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,  | 
                                                        |
| 3454 | - $message_type_name)  | 
                                                        |
| 3455 | -        ) { | 
                                                        |
| 3456 | - $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 3457 | -            if ($message_type_to_activate->get_admin_settings_fields()) { | 
                                                        |
| 3458 | - $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 3459 | - }  | 
                                                        |
| 3460 | - }  | 
                                                        |
| 3461 | -  | 
                                                        |
| 3462 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,  | 
                                                        |
| 3463 | - $message_type_to_activate);  | 
                                                        |
| 3464 | - }  | 
                                                        |
| 3465 | -  | 
                                                        |
| 3466 | -  | 
                                                        |
| 3467 | - /**  | 
                                                        |
| 3468 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 3469 | - *  | 
                                                        |
| 3470 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for.  | 
                                                        |
| 3471 | - * @param string $message_type_name The name of the message type being deactivated for the messenger  | 
                                                        |
| 3472 | - *  | 
                                                        |
| 3473 | - * @return bool  | 
                                                        |
| 3474 | - */  | 
                                                        |
| 3475 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 3476 | -    { | 
                                                        |
| 3477 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3478 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3479 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3480 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3481 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);  | 
                                                        |
| 3482 | -  | 
                                                        |
| 3483 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,  | 
                                                        |
| 3484 | - $message_type_to_deactivate);  | 
                                                        |
| 3485 | - }  | 
                                                        |
| 3486 | -  | 
                                                        |
| 3487 | -  | 
                                                        |
| 3488 | - /**  | 
                                                        |
| 3489 | - * This just initializes the defaults for activating messenger and message type responses.  | 
                                                        |
| 3490 | - */  | 
                                                        |
| 3491 | - protected function _prep_default_response_for_messenger_or_message_type_toggle()  | 
                                                        |
| 3492 | -    { | 
                                                        |
| 3493 | - $this->_template_args['data']['active_mts'] = array();  | 
                                                        |
| 3494 | - $this->_template_args['data']['mt_reload'] = array();  | 
                                                        |
| 3495 | - }  | 
                                                        |
| 3496 | -  | 
                                                        |
| 3497 | -  | 
                                                        |
| 3498 | - /**  | 
                                                        |
| 3499 | - * Setup appropriate response for activating a messenger and/or message types  | 
                                                        |
| 3500 | - *  | 
                                                        |
| 3501 | - * @param EE_messenger $messenger  | 
                                                        |
| 3502 | - * @param EE_message_type|null $message_type  | 
                                                        |
| 3503 | - *  | 
                                                        |
| 3504 | - * @return bool  | 
                                                        |
| 3505 | - * @throws EE_Error  | 
                                                        |
| 3506 | - */  | 
                                                        |
| 3507 | - protected function _setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 3508 | - $messenger,  | 
                                                        |
| 3509 | - EE_Message_Type $message_type = null  | 
                                                        |
| 3510 | -    ) { | 
                                                        |
| 3511 | - //if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 3512 | -        if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 3513 | - EE_Error::add_error(  | 
                                                        |
| 3514 | -                __('The messenger being activated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 3515 | - __FILE__,  | 
                                                        |
| 3516 | - __FUNCTION__,  | 
                                                        |
| 3517 | - __LINE__  | 
                                                        |
| 3518 | - );  | 
                                                        |
| 3183 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3184 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')  | 
                                                        |
| 3185 | + : '';  | 
                                                        |
| 3186 | + }  | 
                                                        |
| 3187 | +  | 
                                                        |
| 3188 | + //we also need some hidden fields  | 
                                                        |
| 3189 | + $settings_template_args['hidden_fields'] = array(  | 
                                                        |
| 3190 | + 'messenger_settings[messenger]' => array(  | 
                                                        |
| 3191 | + 'type' => 'hidden',  | 
                                                        |
| 3192 | + 'value' => $messenger->name  | 
                                                        |
| 3193 | + ),  | 
                                                        |
| 3194 | + 'type' => array(  | 
                                                        |
| 3195 | + 'type' => 'hidden',  | 
                                                        |
| 3196 | + 'value' => 'messenger'  | 
                                                        |
| 3197 | + )  | 
                                                        |
| 3198 | + );  | 
                                                        |
| 3199 | +  | 
                                                        |
| 3200 | + //make sure any active message types that are existing are included in the hidden fields  | 
                                                        |
| 3201 | +		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { | 
                                                        |
| 3202 | +			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { | 
                                                        |
| 3203 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(  | 
                                                        |
| 3204 | + 'type' => 'hidden',  | 
                                                        |
| 3205 | + 'value' => $mt  | 
                                                        |
| 3206 | + );  | 
                                                        |
| 3207 | + }  | 
                                                        |
| 3208 | + }  | 
                                                        |
| 3209 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3210 | + $settings_template_args['hidden_fields'],  | 
                                                        |
| 3211 | + 'array'  | 
                                                        |
| 3212 | + );  | 
                                                        |
| 3213 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3214 | +  | 
                                                        |
| 3215 | + $settings_template_args['messenger'] = $messenger->name;  | 
                                                        |
| 3216 | + $settings_template_args['description'] = $messenger->description;  | 
                                                        |
| 3217 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';  | 
                                                        |
| 3218 | +  | 
                                                        |
| 3219 | +  | 
                                                        |
| 3220 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)  | 
                                                        |
| 3221 | + ? $settings_template_args['show_hide_edit_form']  | 
                                                        |
| 3222 | + : ' hidden';  | 
                                                        |
| 3223 | +  | 
                                                        |
| 3224 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3225 | + ? ' hidden'  | 
                                                        |
| 3226 | + : $settings_template_args['show_hide_edit_form'];  | 
                                                        |
| 3227 | +  | 
                                                        |
| 3228 | +  | 
                                                        |
| 3229 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        |
| 3230 | +		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3231 | + $settings_template_args['on_off_status'] = $active ? true : false;  | 
                                                        |
| 3232 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3233 | + $content = EEH_Template::display_template($template, $settings_template_args,  | 
                                                        |
| 3234 | + true);  | 
                                                        |
| 3235 | +  | 
                                                        |
| 3236 | + return $content;  | 
                                                        |
| 3237 | + }  | 
                                                        |
| 3238 | +  | 
                                                        |
| 3239 | +  | 
                                                        |
| 3240 | + /**  | 
                                                        |
| 3241 | + * used by ajax on the messages settings page to activate|deactivate the messenger  | 
                                                        |
| 3242 | + */  | 
                                                        |
| 3243 | + public function activate_messenger_toggle()  | 
                                                        |
| 3244 | +	{ | 
                                                        |
| 3245 | + $success = true;  | 
                                                        |
| 3246 | + $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3247 | + //let's check that we have required data  | 
                                                        |
| 3248 | +		if ( ! isset($this->_req_data['messenger'])) { | 
                                                        |
| 3249 | + EE_Error::add_error(  | 
                                                        |
| 3250 | +				__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3251 | + __FILE__,  | 
                                                        |
| 3252 | + __FUNCTION__,  | 
                                                        |
| 3253 | + __LINE__  | 
                                                        |
| 3254 | + );  | 
                                                        |
| 3255 | + $success = false;  | 
                                                        |
| 3256 | + }  | 
                                                        |
| 3257 | +  | 
                                                        |
| 3258 | + //do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 3259 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';  | 
                                                        |
| 3260 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';  | 
                                                        |
| 3261 | +  | 
                                                        |
| 3262 | + $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 3263 | +  | 
                                                        |
| 3264 | +  | 
                                                        |
| 3265 | +		if ( ! isset($this->_req_data['status'])) { | 
                                                        |
| 3266 | + EE_Error::add_error(  | 
                                                        |
| 3267 | + __(  | 
                                                        |
| 3268 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 3269 | + 'event_espresso'  | 
                                                        |
| 3270 | + ),  | 
                                                        |
| 3271 | + __FILE__,  | 
                                                        |
| 3272 | + __FUNCTION__,  | 
                                                        |
| 3273 | + __LINE__  | 
                                                        |
| 3274 | + );  | 
                                                        |
| 3275 | + $success = false;  | 
                                                        |
| 3276 | + }  | 
                                                        |
| 3277 | +  | 
                                                        |
| 3278 | + //do check to verify we have a valid status.  | 
                                                        |
| 3279 | + $status = $this->_req_data['status'];  | 
                                                        |
| 3280 | +  | 
                                                        |
| 3281 | +		if ($status != 'off' && $status != 'on') { | 
                                                        |
| 3282 | + EE_Error::add_error(  | 
                                                        |
| 3283 | + sprintf(  | 
                                                        |
| 3284 | +					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 3285 | + $this->_req_data['status']  | 
                                                        |
| 3286 | + ),  | 
                                                        |
| 3287 | + __FILE__,  | 
                                                        |
| 3288 | + __FUNCTION__,  | 
                                                        |
| 3289 | + __LINE__  | 
                                                        |
| 3290 | + );  | 
                                                        |
| 3291 | + $success = false;  | 
                                                        |
| 3292 | + }  | 
                                                        |
| 3293 | +  | 
                                                        |
| 3294 | +		if ($success) { | 
                                                        |
| 3295 | + //made it here? Stop dawdling then!!  | 
                                                        |
| 3296 | + $success = $status == 'off'  | 
                                                        |
| 3297 | + ? $this->_deactivate_messenger($this->_req_data['messenger'])  | 
                                                        |
| 3298 | + : $this->_activate_messenger($this->_req_data['messenger']);  | 
                                                        |
| 3299 | + }  | 
                                                        |
| 3300 | +  | 
                                                        |
| 3301 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 3302 | +  | 
                                                        |
| 3303 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff).  | 
                                                        |
| 3304 | + $this->_return_json();  | 
                                                        |
| 3305 | +  | 
                                                        |
| 3306 | + }  | 
                                                        |
| 3307 | +  | 
                                                        |
| 3308 | +  | 
                                                        |
| 3309 | + /**  | 
                                                        |
| 3310 | + * used by ajax from the messages settings page to activate|deactivate a message type  | 
                                                        |
| 3311 | + *  | 
                                                        |
| 3312 | + */  | 
                                                        |
| 3313 | + public function activate_mt_toggle()  | 
                                                        |
| 3314 | +	{ | 
                                                        |
| 3315 | + $success = true;  | 
                                                        |
| 3316 | + $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3317 | +  | 
                                                        |
| 3318 | + //let's make sure we have the necessary data  | 
                                                        |
| 3319 | +		if ( ! isset($this->_req_data['message_type'])) { | 
                                                        |
| 3320 | + EE_Error::add_error(  | 
                                                        |
| 3321 | +				__('Message Type name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3322 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3323 | + );  | 
                                                        |
| 3324 | + $success = false;  | 
                                                        |
| 3325 | + }  | 
                                                        |
| 3326 | +  | 
                                                        |
| 3327 | +		if ( ! isset($this->_req_data['messenger'])) { | 
                                                        |
| 3328 | + EE_Error::add_error(  | 
                                                        |
| 3329 | +				__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3330 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3331 | + );  | 
                                                        |
| 3332 | + $success = false;  | 
                                                        |
| 3333 | + }  | 
                                                        |
| 3334 | +  | 
                                                        |
| 3335 | +		if ( ! isset($this->_req_data['status'])) { | 
                                                        |
| 3336 | + EE_Error::add_error(  | 
                                                        |
| 3337 | +				__('Messenger status needed to know whether activation or deactivation is happening. No status is given', | 
                                                        |
| 3338 | + 'event_espresso'),  | 
                                                        |
| 3339 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3340 | + );  | 
                                                        |
| 3341 | + $success = false;  | 
                                                        |
| 3342 | + }  | 
                                                        |
| 3343 | +  | 
                                                        |
| 3344 | +  | 
                                                        |
| 3345 | + //do check to verify we have a valid status.  | 
                                                        |
| 3346 | + $status = $this->_req_data['status'];  | 
                                                        |
| 3347 | +  | 
                                                        |
| 3348 | +		if ($status != 'activate' && $status != 'deactivate') { | 
                                                        |
| 3349 | + EE_Error::add_error(  | 
                                                        |
| 3350 | + sprintf(  | 
                                                        |
| 3351 | +					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | 
                                                        |
| 3352 | + $this->_req_data['status']  | 
                                                        |
| 3353 | + ),  | 
                                                        |
| 3354 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3355 | + );  | 
                                                        |
| 3356 | + $success = false;  | 
                                                        |
| 3357 | + }  | 
                                                        |
| 3358 | +  | 
                                                        |
| 3359 | +  | 
                                                        |
| 3360 | + //do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 3361 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';  | 
                                                        |
| 3362 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce';  | 
                                                        |
| 3363 | +  | 
                                                        |
| 3364 | + $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 3365 | +  | 
                                                        |
| 3366 | +		if ($success) { | 
                                                        |
| 3367 | + //made it here? um, what are you waiting for then?  | 
                                                        |
| 3368 | + $success = $status == 'deactivate'  | 
                                                        |
| 3369 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],  | 
                                                        |
| 3370 | + $this->_req_data['message_type'])  | 
                                                        |
| 3371 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],  | 
                                                        |
| 3372 | + $this->_req_data['message_type']);  | 
                                                        |
| 3373 | + }  | 
                                                        |
| 3374 | +  | 
                                                        |
| 3375 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 3376 | + $this->_return_json();  | 
                                                        |
| 3377 | + }  | 
                                                        |
| 3378 | +  | 
                                                        |
| 3379 | +  | 
                                                        |
| 3380 | + /**  | 
                                                        |
| 3381 | + * Takes care of processing activating a messenger and preparing the appropriate response.  | 
                                                        |
| 3382 | + *  | 
                                                        |
| 3383 | + * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 3384 | + *  | 
                                                        |
| 3385 | + * @return bool  | 
                                                        |
| 3386 | + */  | 
                                                        |
| 3387 | + protected function _activate_messenger($messenger_name)  | 
                                                        |
| 3388 | +	{ | 
                                                        |
| 3389 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3390 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3391 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();  | 
                                                        |
| 3392 | +  | 
                                                        |
| 3393 | + //ensure is active  | 
                                                        |
| 3394 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);  | 
                                                        |
| 3395 | +  | 
                                                        |
| 3396 | + //set response_data for reload  | 
                                                        |
| 3397 | +		foreach ($message_types_to_activate as $message_type_name) { | 
                                                        |
| 3398 | + /** @var EE_message_type $message_type */  | 
                                                        |
| 3399 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3400 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,  | 
                                                        |
| 3401 | + $message_type_name)  | 
                                                        |
| 3402 | + && $message_type instanceof EE_message_type  | 
                                                        |
| 3403 | +			) { | 
                                                        |
| 3404 | + $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 3405 | +				if ($message_type->get_admin_settings_fields()) { | 
                                                        |
| 3406 | + $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 3407 | + }  | 
                                                        |
| 3408 | + }  | 
                                                        |
| 3409 | + }  | 
                                                        |
| 3410 | +  | 
                                                        |
| 3411 | + //add success message for activating messenger  | 
                                                        |
| 3412 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 3413 | +  | 
                                                        |
| 3414 | + }  | 
                                                        |
| 3415 | +  | 
                                                        |
| 3416 | +  | 
                                                        |
| 3417 | + /**  | 
                                                        |
| 3418 | + * Takes care of processing deactivating a messenger and preparing the appropriate response.  | 
                                                        |
| 3419 | + *  | 
                                                        |
| 3420 | + * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 3421 | + *  | 
                                                        |
| 3422 | + * @return bool  | 
                                                        |
| 3423 | + */  | 
                                                        |
| 3424 | + protected function _deactivate_messenger($messenger_name)  | 
                                                        |
| 3425 | +	{ | 
                                                        |
| 3426 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3427 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3428 | + $this->_message_resource_manager->deactivate_messenger($messenger_name);  | 
                                                        |
| 3429 | +  | 
                                                        |
| 3430 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 3431 | + }  | 
                                                        |
| 3432 | +  | 
                                                        |
| 3433 | +  | 
                                                        |
| 3434 | + /**  | 
                                                        |
| 3435 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 3436 | + *  | 
                                                        |
| 3437 | + * @param string $messenger_name The name of the messenger the message type is being activated for.  | 
                                                        |
| 3438 | + * @param string $message_type_name The name of the message type being activated for the messenger  | 
                                                        |
| 3439 | + *  | 
                                                        |
| 3440 | + * @return bool  | 
                                                        |
| 3441 | + */  | 
                                                        |
| 3442 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 3443 | +	{ | 
                                                        |
| 3444 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3445 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3446 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3447 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3448 | +  | 
                                                        |
| 3449 | + //ensure is active  | 
                                                        |
| 3450 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);  | 
                                                        |
| 3451 | +  | 
                                                        |
| 3452 | + //set response for load  | 
                                                        |
| 3453 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,  | 
                                                        |
| 3454 | + $message_type_name)  | 
                                                        |
| 3455 | +		) { | 
                                                        |
| 3456 | + $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 3457 | +			if ($message_type_to_activate->get_admin_settings_fields()) { | 
                                                        |
| 3458 | + $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 3459 | + }  | 
                                                        |
| 3460 | + }  | 
                                                        |
| 3461 | +  | 
                                                        |
| 3462 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,  | 
                                                        |
| 3463 | + $message_type_to_activate);  | 
                                                        |
| 3464 | + }  | 
                                                        |
| 3465 | +  | 
                                                        |
| 3466 | +  | 
                                                        |
| 3467 | + /**  | 
                                                        |
| 3468 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 3469 | + *  | 
                                                        |
| 3470 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for.  | 
                                                        |
| 3471 | + * @param string $message_type_name The name of the message type being deactivated for the messenger  | 
                                                        |
| 3472 | + *  | 
                                                        |
| 3473 | + * @return bool  | 
                                                        |
| 3474 | + */  | 
                                                        |
| 3475 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 3476 | +	{ | 
                                                        |
| 3477 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3478 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 3479 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 3480 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 3481 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);  | 
                                                        |
| 3482 | +  | 
                                                        |
| 3483 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,  | 
                                                        |
| 3484 | + $message_type_to_deactivate);  | 
                                                        |
| 3485 | + }  | 
                                                        |
| 3486 | +  | 
                                                        |
| 3487 | +  | 
                                                        |
| 3488 | + /**  | 
                                                        |
| 3489 | + * This just initializes the defaults for activating messenger and message type responses.  | 
                                                        |
| 3490 | + */  | 
                                                        |
| 3491 | + protected function _prep_default_response_for_messenger_or_message_type_toggle()  | 
                                                        |
| 3492 | +	{ | 
                                                        |
| 3493 | + $this->_template_args['data']['active_mts'] = array();  | 
                                                        |
| 3494 | + $this->_template_args['data']['mt_reload'] = array();  | 
                                                        |
| 3495 | + }  | 
                                                        |
| 3496 | +  | 
                                                        |
| 3497 | +  | 
                                                        |
| 3498 | + /**  | 
                                                        |
| 3499 | + * Setup appropriate response for activating a messenger and/or message types  | 
                                                        |
| 3500 | + *  | 
                                                        |
| 3501 | + * @param EE_messenger $messenger  | 
                                                        |
| 3502 | + * @param EE_message_type|null $message_type  | 
                                                        |
| 3503 | + *  | 
                                                        |
| 3504 | + * @return bool  | 
                                                        |
| 3505 | + * @throws EE_Error  | 
                                                        |
| 3506 | + */  | 
                                                        |
| 3507 | + protected function _setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 3508 | + $messenger,  | 
                                                        |
| 3509 | + EE_Message_Type $message_type = null  | 
                                                        |
| 3510 | +	) { | 
                                                        |
| 3511 | + //if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 3512 | +		if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 3513 | + EE_Error::add_error(  | 
                                                        |
| 3514 | +				__('The messenger being activated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 3515 | + __FILE__,  | 
                                                        |
| 3516 | + __FUNCTION__,  | 
                                                        |
| 3517 | + __LINE__  | 
                                                        |
| 3518 | + );  | 
                                                        |
| 3519 | 3519 | |
| 3520 | - return false;  | 
                                                        |
| 3521 | - }  | 
                                                        |
| 3522 | - //activated  | 
                                                        |
| 3523 | -        if ($this->_template_args['data']['active_mts']) { | 
                                                        |
| 3524 | - EE_Error::overwrite_success();  | 
                                                        |
| 3525 | - //activated a message type with the messenger  | 
                                                        |
| 3526 | -            if ($message_type instanceof EE_message_type) { | 
                                                        |
| 3527 | - EE_Error::add_success(  | 
                                                        |
| 3528 | - sprintf(  | 
                                                        |
| 3529 | -                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), | 
                                                        |
| 3530 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 3531 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3532 | - )  | 
                                                        |
| 3533 | - );  | 
                                                        |
| 3520 | + return false;  | 
                                                        |
| 3521 | + }  | 
                                                        |
| 3522 | + //activated  | 
                                                        |
| 3523 | +		if ($this->_template_args['data']['active_mts']) { | 
                                                        |
| 3524 | + EE_Error::overwrite_success();  | 
                                                        |
| 3525 | + //activated a message type with the messenger  | 
                                                        |
| 3526 | +			if ($message_type instanceof EE_message_type) { | 
                                                        |
| 3527 | + EE_Error::add_success(  | 
                                                        |
| 3528 | + sprintf(  | 
                                                        |
| 3529 | +						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), | 
                                                        |
| 3530 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 3531 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3532 | + )  | 
                                                        |
| 3533 | + );  | 
                                                        |
| 3534 | 3534 | |
| 3535 | - //if message type was invoice then let's make sure we activate the invoice payment method.  | 
                                                        |
| 3536 | -                if ($message_type->name == 'invoice') { | 
                                                        |
| 3537 | -                    EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 3538 | -                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | 
                                                        |
| 3539 | -                    if ($pm instanceof EE_Payment_Method) { | 
                                                        |
| 3540 | -                        EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', | 
                                                        |
| 3541 | - 'event_espresso'));  | 
                                                        |
| 3542 | - }  | 
                                                        |
| 3543 | - }  | 
                                                        |
| 3544 | - //just toggles the entire messenger  | 
                                                        |
| 3545 | -            } else { | 
                                                        |
| 3546 | - EE_Error::add_success(  | 
                                                        |
| 3547 | - sprintf(  | 
                                                        |
| 3548 | -                        __('%s messenger has been successfully activated', 'event_espresso'), | 
                                                        |
| 3549 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3550 | - )  | 
                                                        |
| 3551 | - );  | 
                                                        |
| 3552 | - }  | 
                                                        |
| 3535 | + //if message type was invoice then let's make sure we activate the invoice payment method.  | 
                                                        |
| 3536 | +				if ($message_type->name == 'invoice') { | 
                                                        |
| 3537 | +					EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 3538 | +					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | 
                                                        |
| 3539 | +					if ($pm instanceof EE_Payment_Method) { | 
                                                        |
| 3540 | +						EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', | 
                                                        |
| 3541 | + 'event_espresso'));  | 
                                                        |
| 3542 | + }  | 
                                                        |
| 3543 | + }  | 
                                                        |
| 3544 | + //just toggles the entire messenger  | 
                                                        |
| 3545 | +			} else { | 
                                                        |
| 3546 | + EE_Error::add_success(  | 
                                                        |
| 3547 | + sprintf(  | 
                                                        |
| 3548 | +						__('%s messenger has been successfully activated', 'event_espresso'), | 
                                                        |
| 3549 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3550 | + )  | 
                                                        |
| 3551 | + );  | 
                                                        |
| 3552 | + }  | 
                                                        |
| 3553 | 3553 | |
| 3554 | - return true;  | 
                                                        |
| 3554 | + return true;  | 
                                                        |
| 3555 | 3555 | |
| 3556 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active  | 
                                                        |
| 3557 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types  | 
                                                        |
| 3558 | - //in which case we just give a success message for the messenger being successfully activated.  | 
                                                        |
| 3559 | -        } else { | 
                                                        |
| 3560 | -            if ( ! $messenger->get_default_message_types()) { | 
                                                        |
| 3561 | - //messenger doesn't have any default message types so still a success.  | 
                                                        |
| 3562 | - EE_Error::add_success(  | 
                                                        |
| 3563 | - sprintf(  | 
                                                        |
| 3564 | -                        __('%s messenger was successfully activated.', 'event_espresso'), | 
                                                        |
| 3565 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3566 | - )  | 
                                                        |
| 3567 | - );  | 
                                                        |
| 3556 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active  | 
                                                        |
| 3557 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types  | 
                                                        |
| 3558 | + //in which case we just give a success message for the messenger being successfully activated.  | 
                                                        |
| 3559 | +		} else { | 
                                                        |
| 3560 | +			if ( ! $messenger->get_default_message_types()) { | 
                                                        |
| 3561 | + //messenger doesn't have any default message types so still a success.  | 
                                                        |
| 3562 | + EE_Error::add_success(  | 
                                                        |
| 3563 | + sprintf(  | 
                                                        |
| 3564 | +						__('%s messenger was successfully activated.', 'event_espresso'), | 
                                                        |
| 3565 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3566 | + )  | 
                                                        |
| 3567 | + );  | 
                                                        |
| 3568 | 3568 | |
| 3569 | - return true;  | 
                                                        |
| 3570 | -            } else { | 
                                                        |
| 3571 | - EE_Error::add_error(  | 
                                                        |
| 3572 | - $message_type instanceof EE_message_type  | 
                                                        |
| 3573 | - ? sprintf(  | 
                                                        |
| 3574 | -                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), | 
                                                        |
| 3575 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 3576 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3577 | - )  | 
                                                        |
| 3578 | - : sprintf(  | 
                                                        |
| 3579 | -                        __('%s messenger was not successfully activated', 'event_espresso'), | 
                                                        |
| 3580 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3581 | - ),  | 
                                                        |
| 3582 | - __FILE__,  | 
                                                        |
| 3583 | - __FUNCTION__,  | 
                                                        |
| 3584 | - __LINE__  | 
                                                        |
| 3585 | - );  | 
                                                        |
| 3569 | + return true;  | 
                                                        |
| 3570 | +			} else { | 
                                                        |
| 3571 | + EE_Error::add_error(  | 
                                                        |
| 3572 | + $message_type instanceof EE_message_type  | 
                                                        |
| 3573 | + ? sprintf(  | 
                                                        |
| 3574 | +						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), | 
                                                        |
| 3575 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 3576 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3577 | + )  | 
                                                        |
| 3578 | + : sprintf(  | 
                                                        |
| 3579 | +						__('%s messenger was not successfully activated', 'event_espresso'), | 
                                                        |
| 3580 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3581 | + ),  | 
                                                        |
| 3582 | + __FILE__,  | 
                                                        |
| 3583 | + __FUNCTION__,  | 
                                                        |
| 3584 | + __LINE__  | 
                                                        |
| 3585 | + );  | 
                                                        |
| 3586 | 3586 | |
| 3587 | - return false;  | 
                                                        |
| 3588 | - }  | 
                                                        |
| 3589 | - }  | 
                                                        |
| 3590 | - }  | 
                                                        |
| 3591 | -  | 
                                                        |
| 3592 | -  | 
                                                        |
| 3593 | - /**  | 
                                                        |
| 3594 | - * This sets up the appropriate response for deactivating a messenger and/or message type.  | 
                                                        |
| 3595 | - *  | 
                                                        |
| 3596 | - * @param EE_messenger $messenger  | 
                                                        |
| 3597 | - * @param EE_message_type|null $message_type  | 
                                                        |
| 3598 | - *  | 
                                                        |
| 3599 | - * @return bool  | 
                                                        |
| 3600 | - */  | 
                                                        |
| 3601 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 3602 | - $messenger,  | 
                                                        |
| 3603 | - EE_message_type $message_type = null  | 
                                                        |
| 3604 | -    ) { | 
                                                        |
| 3605 | - EE_Error::overwrite_success();  | 
                                                        |
| 3606 | -  | 
                                                        |
| 3607 | - //if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 3608 | -        if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 3609 | - EE_Error::add_error(  | 
                                                        |
| 3610 | -                __('The messenger being deactivated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 3611 | - __FILE__,  | 
                                                        |
| 3612 | - __FUNCTION__,  | 
                                                        |
| 3613 | - __LINE__  | 
                                                        |
| 3614 | - );  | 
                                                        |
| 3587 | + return false;  | 
                                                        |
| 3588 | + }  | 
                                                        |
| 3589 | + }  | 
                                                        |
| 3590 | + }  | 
                                                        |
| 3591 | +  | 
                                                        |
| 3592 | +  | 
                                                        |
| 3593 | + /**  | 
                                                        |
| 3594 | + * This sets up the appropriate response for deactivating a messenger and/or message type.  | 
                                                        |
| 3595 | + *  | 
                                                        |
| 3596 | + * @param EE_messenger $messenger  | 
                                                        |
| 3597 | + * @param EE_message_type|null $message_type  | 
                                                        |
| 3598 | + *  | 
                                                        |
| 3599 | + * @return bool  | 
                                                        |
| 3600 | + */  | 
                                                        |
| 3601 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 3602 | + $messenger,  | 
                                                        |
| 3603 | + EE_message_type $message_type = null  | 
                                                        |
| 3604 | +	) { | 
                                                        |
| 3605 | + EE_Error::overwrite_success();  | 
                                                        |
| 3606 | +  | 
                                                        |
| 3607 | + //if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 3608 | +		if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 3609 | + EE_Error::add_error(  | 
                                                        |
| 3610 | +				__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 3611 | + __FILE__,  | 
                                                        |
| 3612 | + __FUNCTION__,  | 
                                                        |
| 3613 | + __LINE__  | 
                                                        |
| 3614 | + );  | 
                                                        |
| 3615 | 3615 | |
| 3616 | - return false;  | 
                                                        |
| 3617 | - }  | 
                                                        |
| 3618 | -  | 
                                                        |
| 3619 | -        if ($message_type instanceof EE_message_type) { | 
                                                        |
| 3620 | - $message_type_name = $message_type->name;  | 
                                                        |
| 3621 | - EE_Error::add_success(  | 
                                                        |
| 3622 | - sprintf(  | 
                                                        |
| 3623 | -                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), | 
                                                        |
| 3624 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 3625 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3626 | - )  | 
                                                        |
| 3627 | - );  | 
                                                        |
| 3628 | -        } else { | 
                                                        |
| 3629 | - $message_type_name = '';  | 
                                                        |
| 3630 | - EE_Error::add_success(  | 
                                                        |
| 3631 | - sprintf(  | 
                                                        |
| 3632 | -                    __('%s messenger has been successfully deactivated.', 'event_espresso'), | 
                                                        |
| 3633 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 3634 | - )  | 
                                                        |
| 3635 | - );  | 
                                                        |
| 3636 | - }  | 
                                                        |
| 3637 | -  | 
                                                        |
| 3638 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.  | 
                                                        |
| 3639 | -        if ($messenger->name == 'html' || $message_type_name == 'invoice') { | 
                                                        |
| 3640 | -            EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 3641 | -            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | 
                                                        |
| 3642 | -            if ($count_updated > 0) { | 
                                                        |
| 3643 | - $msg = $message_type_name == 'invoice'  | 
                                                        |
| 3644 | -                    ? __('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.', | 
                                                        |
| 3645 | - 'event_espresso')  | 
                                                        |
| 3646 | -                    : __('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.', | 
                                                        |
| 3647 | - 'event_espresso');  | 
                                                        |
| 3648 | - EE_Error::add_attention($msg);  | 
                                                        |
| 3649 | - }  | 
                                                        |
| 3650 | - }  | 
                                                        |
| 3651 | -  | 
                                                        |
| 3652 | - return true;  | 
                                                        |
| 3653 | - }  | 
                                                        |
| 3654 | -  | 
                                                        |
| 3655 | -  | 
                                                        |
| 3656 | - /**  | 
                                                        |
| 3657 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)  | 
                                                        |
| 3658 | - */  | 
                                                        |
| 3659 | - public function update_mt_form()  | 
                                                        |
| 3660 | -    { | 
                                                        |
| 3661 | -        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { | 
                                                        |
| 3662 | -            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, | 
                                                        |
| 3663 | - __LINE__);  | 
                                                        |
| 3664 | - $this->_return_json();  | 
                                                        |
| 3665 | - }  | 
                                                        |
| 3666 | -  | 
                                                        |
| 3667 | - $message_types = $this->get_installed_message_types();  | 
                                                        |
| 3668 | -  | 
                                                        |
| 3669 | - $message_type = $message_types[$this->_req_data['message_type']];  | 
                                                        |
| 3670 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 3671 | -  | 
                                                        |
| 3672 | - $content = $this->_message_type_settings_content($message_type, $messenger, true);  | 
                                                        |
| 3673 | - $this->_template_args['success'] = true;  | 
                                                        |
| 3674 | - $this->_template_args['content'] = $content;  | 
                                                        |
| 3675 | - $this->_return_json();  | 
                                                        |
| 3676 | - }  | 
                                                        |
| 3677 | -  | 
                                                        |
| 3678 | -  | 
                                                        |
| 3679 | - /**  | 
                                                        |
| 3680 | - * this handles saving the settings for a messenger or message type  | 
                                                        |
| 3681 | - *  | 
                                                        |
| 3682 | - */  | 
                                                        |
| 3683 | - public function save_settings()  | 
                                                        |
| 3684 | -    { | 
                                                        |
| 3685 | -        if ( ! isset($this->_req_data['type'])) { | 
                                                        |
| 3686 | -            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', | 
                                                        |
| 3687 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 3688 | - $this->_template_args['error'] = true;  | 
                                                        |
| 3689 | - $this->_return_json();  | 
                                                        |
| 3690 | - }  | 
                                                        |
| 3691 | -  | 
                                                        |
| 3692 | -  | 
                                                        |
| 3693 | -        if ($this->_req_data['type'] == 'messenger') { | 
                                                        |
| 3694 | - $settings = $this->_req_data['messenger_settings']; //this should be an array.  | 
                                                        |
| 3695 | - $messenger = $settings['messenger'];  | 
                                                        |
| 3696 | - //let's setup the settings data  | 
                                                        |
| 3697 | -            foreach ($settings as $key => $value) { | 
                                                        |
| 3698 | -                switch ($key) { | 
                                                        |
| 3699 | - case 'messenger' :  | 
                                                        |
| 3700 | - unset($settings['messenger']);  | 
                                                        |
| 3701 | - break;  | 
                                                        |
| 3702 | - case 'message_types' :  | 
                                                        |
| 3703 | - unset($settings['message_types']);  | 
                                                        |
| 3704 | - break;  | 
                                                        |
| 3705 | - default :  | 
                                                        |
| 3706 | - $settings[$key] = $value;  | 
                                                        |
| 3707 | - break;  | 
                                                        |
| 3708 | - }  | 
                                                        |
| 3709 | - }  | 
                                                        |
| 3710 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);  | 
                                                        |
| 3711 | -        } else if ($this->_req_data['type'] == 'message_type') { | 
                                                        |
| 3712 | - $settings = $this->_req_data['message_type_settings'];  | 
                                                        |
| 3713 | - $messenger = $settings['messenger'];  | 
                                                        |
| 3714 | - $message_type = $settings['message_type'];  | 
                                                        |
| 3616 | + return false;  | 
                                                        |
| 3617 | + }  | 
                                                        |
| 3618 | +  | 
                                                        |
| 3619 | +		if ($message_type instanceof EE_message_type) { | 
                                                        |
| 3620 | + $message_type_name = $message_type->name;  | 
                                                        |
| 3621 | + EE_Error::add_success(  | 
                                                        |
| 3622 | + sprintf(  | 
                                                        |
| 3623 | +					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), | 
                                                        |
| 3624 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 3625 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3626 | + )  | 
                                                        |
| 3627 | + );  | 
                                                        |
| 3628 | +		} else { | 
                                                        |
| 3629 | + $message_type_name = '';  | 
                                                        |
| 3630 | + EE_Error::add_success(  | 
                                                        |
| 3631 | + sprintf(  | 
                                                        |
| 3632 | +					__('%s messenger has been successfully deactivated.', 'event_espresso'), | 
                                                        |
| 3633 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 3634 | + )  | 
                                                        |
| 3635 | + );  | 
                                                        |
| 3636 | + }  | 
                                                        |
| 3637 | +  | 
                                                        |
| 3638 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.  | 
                                                        |
| 3639 | +		if ($messenger->name == 'html' || $message_type_name == 'invoice') { | 
                                                        |
| 3640 | +			EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 3641 | +			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | 
                                                        |
| 3642 | +			if ($count_updated > 0) { | 
                                                        |
| 3643 | + $msg = $message_type_name == 'invoice'  | 
                                                        |
| 3644 | +					? __('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.', | 
                                                        |
| 3645 | + 'event_espresso')  | 
                                                        |
| 3646 | +					: __('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.', | 
                                                        |
| 3647 | + 'event_espresso');  | 
                                                        |
| 3648 | + EE_Error::add_attention($msg);  | 
                                                        |
| 3649 | + }  | 
                                                        |
| 3650 | + }  | 
                                                        |
| 3651 | +  | 
                                                        |
| 3652 | + return true;  | 
                                                        |
| 3653 | + }  | 
                                                        |
| 3654 | +  | 
                                                        |
| 3655 | +  | 
                                                        |
| 3656 | + /**  | 
                                                        |
| 3657 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)  | 
                                                        |
| 3658 | + */  | 
                                                        |
| 3659 | + public function update_mt_form()  | 
                                                        |
| 3660 | +	{ | 
                                                        |
| 3661 | +		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { | 
                                                        |
| 3662 | +			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, | 
                                                        |
| 3663 | + __LINE__);  | 
                                                        |
| 3664 | + $this->_return_json();  | 
                                                        |
| 3665 | + }  | 
                                                        |
| 3666 | +  | 
                                                        |
| 3667 | + $message_types = $this->get_installed_message_types();  | 
                                                        |
| 3668 | +  | 
                                                        |
| 3669 | + $message_type = $message_types[$this->_req_data['message_type']];  | 
                                                        |
| 3670 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        |
| 3671 | +  | 
                                                        |
| 3672 | + $content = $this->_message_type_settings_content($message_type, $messenger, true);  | 
                                                        |
| 3673 | + $this->_template_args['success'] = true;  | 
                                                        |
| 3674 | + $this->_template_args['content'] = $content;  | 
                                                        |
| 3675 | + $this->_return_json();  | 
                                                        |
| 3676 | + }  | 
                                                        |
| 3677 | +  | 
                                                        |
| 3678 | +  | 
                                                        |
| 3679 | + /**  | 
                                                        |
| 3680 | + * this handles saving the settings for a messenger or message type  | 
                                                        |
| 3681 | + *  | 
                                                        |
| 3682 | + */  | 
                                                        |
| 3683 | + public function save_settings()  | 
                                                        |
| 3684 | +	{ | 
                                                        |
| 3685 | +		if ( ! isset($this->_req_data['type'])) { | 
                                                        |
| 3686 | +			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', | 
                                                        |
| 3687 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 3688 | + $this->_template_args['error'] = true;  | 
                                                        |
| 3689 | + $this->_return_json();  | 
                                                        |
| 3690 | + }  | 
                                                        |
| 3691 | +  | 
                                                        |
| 3692 | +  | 
                                                        |
| 3693 | +		if ($this->_req_data['type'] == 'messenger') { | 
                                                        |
| 3694 | + $settings = $this->_req_data['messenger_settings']; //this should be an array.  | 
                                                        |
| 3695 | + $messenger = $settings['messenger'];  | 
                                                        |
| 3696 | + //let's setup the settings data  | 
                                                        |
| 3697 | +			foreach ($settings as $key => $value) { | 
                                                        |
| 3698 | +				switch ($key) { | 
                                                        |
| 3699 | + case 'messenger' :  | 
                                                        |
| 3700 | + unset($settings['messenger']);  | 
                                                        |
| 3701 | + break;  | 
                                                        |
| 3702 | + case 'message_types' :  | 
                                                        |
| 3703 | + unset($settings['message_types']);  | 
                                                        |
| 3704 | + break;  | 
                                                        |
| 3705 | + default :  | 
                                                        |
| 3706 | + $settings[$key] = $value;  | 
                                                        |
| 3707 | + break;  | 
                                                        |
| 3708 | + }  | 
                                                        |
| 3709 | + }  | 
                                                        |
| 3710 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);  | 
                                                        |
| 3711 | +		} else if ($this->_req_data['type'] == 'message_type') { | 
                                                        |
| 3712 | + $settings = $this->_req_data['message_type_settings'];  | 
                                                        |
| 3713 | + $messenger = $settings['messenger'];  | 
                                                        |
| 3714 | + $message_type = $settings['message_type'];  | 
                                                        |
| 3715 | 3715 | |
| 3716 | -            foreach ($settings as $key => $value) { | 
                                                        |
| 3717 | -                switch ($key) { | 
                                                        |
| 3718 | - case 'messenger' :  | 
                                                        |
| 3719 | - unset($settings['messenger']);  | 
                                                        |
| 3720 | - break;  | 
                                                        |
| 3721 | - case 'message_type' :  | 
                                                        |
| 3722 | - unset($settings['message_type']);  | 
                                                        |
| 3723 | - break;  | 
                                                        |
| 3724 | - default :  | 
                                                        |
| 3725 | - $settings[$key] = $value;  | 
                                                        |
| 3726 | - break;  | 
                                                        |
| 3727 | - }  | 
                                                        |
| 3728 | - }  | 
                                                        |
| 3716 | +			foreach ($settings as $key => $value) { | 
                                                        |
| 3717 | +				switch ($key) { | 
                                                        |
| 3718 | + case 'messenger' :  | 
                                                        |
| 3719 | + unset($settings['messenger']);  | 
                                                        |
| 3720 | + break;  | 
                                                        |
| 3721 | + case 'message_type' :  | 
                                                        |
| 3722 | + unset($settings['message_type']);  | 
                                                        |
| 3723 | + break;  | 
                                                        |
| 3724 | + default :  | 
                                                        |
| 3725 | + $settings[$key] = $value;  | 
                                                        |
| 3726 | + break;  | 
                                                        |
| 3727 | + }  | 
                                                        |
| 3728 | + }  | 
                                                        |
| 3729 | 3729 | |
| 3730 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);  | 
                                                        |
| 3731 | - }  | 
                                                        |
| 3732 | -  | 
                                                        |
| 3733 | - //okay we should have the data all setup. Now we just update!  | 
                                                        |
| 3734 | - $success = $this->_message_resource_manager->update_active_messengers_option();  | 
                                                        |
| 3735 | -  | 
                                                        |
| 3736 | -        if ($success) { | 
                                                        |
| 3737 | -            EE_Error::add_success(__('Settings updated', 'event_espresso')); | 
                                                        |
| 3738 | -        } else { | 
                                                        |
| 3739 | -            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); | 
                                                        |
| 3740 | - }  | 
                                                        |
| 3741 | -  | 
                                                        |
| 3742 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 3743 | - $this->_return_json();  | 
                                                        |
| 3744 | - }  | 
                                                        |
| 3745 | -  | 
                                                        |
| 3746 | -  | 
                                                        |
| 3747 | -  | 
                                                        |
| 3748 | -  | 
                                                        |
| 3749 | - /** EE MESSAGE PROCESSING ACTIONS **/  | 
                                                        |
| 3750 | -  | 
                                                        |
| 3751 | -  | 
                                                        |
| 3752 | - /**  | 
                                                        |
| 3753 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete  | 
                                                        |
| 3754 | - * However, this does not send immediately, it just queues for sending.  | 
                                                        |
| 3755 | - *  | 
                                                        |
| 3756 | - * @since 4.9.0  | 
                                                        |
| 3757 | - */  | 
                                                        |
| 3758 | - protected function _generate_now()  | 
                                                        |
| 3759 | -    { | 
                                                        |
| 3760 | - $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3761 | - EED_Messages::generate_now($msg_ids);  | 
                                                        |
| 3762 | - $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3763 | - }  | 
                                                        |
| 3764 | -  | 
                                                        |
| 3765 | -  | 
                                                        |
| 3766 | - /**  | 
                                                        |
| 3767 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that  | 
                                                        |
| 3768 | - * are EEM_Message::status_resend or EEM_Message::status_idle  | 
                                                        |
| 3769 | - *  | 
                                                        |
| 3770 | - * @since 4.9.0  | 
                                                        |
| 3771 | - *  | 
                                                        |
| 3772 | - */  | 
                                                        |
| 3773 | - protected function _generate_and_send_now()  | 
                                                        |
| 3774 | -    { | 
                                                        |
| 3775 | - $this->_generate_now();  | 
                                                        |
| 3776 | - $this->_send_now();  | 
                                                        |
| 3777 | - $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3778 | - }  | 
                                                        |
| 3779 | -  | 
                                                        |
| 3780 | -  | 
                                                        |
| 3781 | - /**  | 
                                                        |
| 3782 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.  | 
                                                        |
| 3783 | - *  | 
                                                        |
| 3784 | - * @since 4.9.0  | 
                                                        |
| 3785 | - */  | 
                                                        |
| 3786 | - protected function _queue_for_resending()  | 
                                                        |
| 3787 | -    { | 
                                                        |
| 3788 | - $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3789 | - EED_Messages::queue_for_resending($msg_ids);  | 
                                                        |
| 3790 | - $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3791 | - }  | 
                                                        |
| 3792 | -  | 
                                                        |
| 3793 | -  | 
                                                        |
| 3794 | - /**  | 
                                                        |
| 3795 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue  | 
                                                        |
| 3796 | - *  | 
                                                        |
| 3797 | - * @since 4.9.0  | 
                                                        |
| 3798 | - */  | 
                                                        |
| 3799 | - protected function _send_now()  | 
                                                        |
| 3800 | -    { | 
                                                        |
| 3801 | - $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3802 | - EED_Messages::send_now($msg_ids);  | 
                                                        |
| 3803 | - $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3804 | - }  | 
                                                        |
| 3805 | -  | 
                                                        |
| 3806 | -  | 
                                                        |
| 3807 | - /**  | 
                                                        |
| 3808 | - * Deletes EE_messages for IDs in the request.  | 
                                                        |
| 3809 | - *  | 
                                                        |
| 3810 | - * @since 4.9.0  | 
                                                        |
| 3811 | - */  | 
                                                        |
| 3812 | - protected function _delete_ee_messages()  | 
                                                        |
| 3813 | -    { | 
                                                        |
| 3814 | - $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3815 | - $deleted_count = 0;  | 
                                                        |
| 3816 | -        foreach ($msg_ids as $msg_id) { | 
                                                        |
| 3817 | -            if (EEM_Message::instance()->delete_by_ID($msg_id)) { | 
                                                        |
| 3818 | - $deleted_count++;  | 
                                                        |
| 3819 | - }  | 
                                                        |
| 3820 | - }  | 
                                                        |
| 3821 | -        if ($deleted_count) { | 
                                                        |
| 3822 | - $this->_redirect_after_action(  | 
                                                        |
| 3823 | - true,  | 
                                                        |
| 3824 | -                _n('message', 'messages', $deleted_count, 'event_espresso'), | 
                                                        |
| 3825 | -                __('deleted', 'event_espresso') | 
                                                        |
| 3826 | - );  | 
                                                        |
| 3827 | -        } else { | 
                                                        |
| 3828 | - EE_Error::add_error(  | 
                                                        |
| 3829 | -                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), | 
                                                        |
| 3830 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3831 | - );  | 
                                                        |
| 3832 | - $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3833 | - }  | 
                                                        |
| 3834 | - }  | 
                                                        |
| 3835 | -  | 
                                                        |
| 3836 | -  | 
                                                        |
| 3837 | - /**  | 
                                                        |
| 3838 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.  | 
                                                        |
| 3839 | - * @since 4.9.0  | 
                                                        |
| 3840 | - * @return array  | 
                                                        |
| 3841 | - */  | 
                                                        |
| 3842 | - protected function _get_msg_ids_from_request()  | 
                                                        |
| 3843 | -    { | 
                                                        |
| 3844 | -        if ( ! isset($this->_req_data['MSG_ID'])) { | 
                                                        |
| 3845 | - return array();  | 
                                                        |
| 3846 | - }  | 
                                                        |
| 3847 | -  | 
                                                        |
| 3848 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);  | 
                                                        |
| 3849 | - }  | 
                                                        |
| 3730 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);  | 
                                                        |
| 3731 | + }  | 
                                                        |
| 3732 | +  | 
                                                        |
| 3733 | + //okay we should have the data all setup. Now we just update!  | 
                                                        |
| 3734 | + $success = $this->_message_resource_manager->update_active_messengers_option();  | 
                                                        |
| 3735 | +  | 
                                                        |
| 3736 | +		if ($success) { | 
                                                        |
| 3737 | +			EE_Error::add_success(__('Settings updated', 'event_espresso')); | 
                                                        |
| 3738 | +		} else { | 
                                                        |
| 3739 | +			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); | 
                                                        |
| 3740 | + }  | 
                                                        |
| 3741 | +  | 
                                                        |
| 3742 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 3743 | + $this->_return_json();  | 
                                                        |
| 3744 | + }  | 
                                                        |
| 3745 | +  | 
                                                        |
| 3746 | +  | 
                                                        |
| 3747 | +  | 
                                                        |
| 3748 | +  | 
                                                        |
| 3749 | + /** EE MESSAGE PROCESSING ACTIONS **/  | 
                                                        |
| 3750 | +  | 
                                                        |
| 3751 | +  | 
                                                        |
| 3752 | + /**  | 
                                                        |
| 3753 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete  | 
                                                        |
| 3754 | + * However, this does not send immediately, it just queues for sending.  | 
                                                        |
| 3755 | + *  | 
                                                        |
| 3756 | + * @since 4.9.0  | 
                                                        |
| 3757 | + */  | 
                                                        |
| 3758 | + protected function _generate_now()  | 
                                                        |
| 3759 | +	{ | 
                                                        |
| 3760 | + $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3761 | + EED_Messages::generate_now($msg_ids);  | 
                                                        |
| 3762 | + $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3763 | + }  | 
                                                        |
| 3764 | +  | 
                                                        |
| 3765 | +  | 
                                                        |
| 3766 | + /**  | 
                                                        |
| 3767 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that  | 
                                                        |
| 3768 | + * are EEM_Message::status_resend or EEM_Message::status_idle  | 
                                                        |
| 3769 | + *  | 
                                                        |
| 3770 | + * @since 4.9.0  | 
                                                        |
| 3771 | + *  | 
                                                        |
| 3772 | + */  | 
                                                        |
| 3773 | + protected function _generate_and_send_now()  | 
                                                        |
| 3774 | +	{ | 
                                                        |
| 3775 | + $this->_generate_now();  | 
                                                        |
| 3776 | + $this->_send_now();  | 
                                                        |
| 3777 | + $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3778 | + }  | 
                                                        |
| 3779 | +  | 
                                                        |
| 3780 | +  | 
                                                        |
| 3781 | + /**  | 
                                                        |
| 3782 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.  | 
                                                        |
| 3783 | + *  | 
                                                        |
| 3784 | + * @since 4.9.0  | 
                                                        |
| 3785 | + */  | 
                                                        |
| 3786 | + protected function _queue_for_resending()  | 
                                                        |
| 3787 | +	{ | 
                                                        |
| 3788 | + $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3789 | + EED_Messages::queue_for_resending($msg_ids);  | 
                                                        |
| 3790 | + $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3791 | + }  | 
                                                        |
| 3792 | +  | 
                                                        |
| 3793 | +  | 
                                                        |
| 3794 | + /**  | 
                                                        |
| 3795 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue  | 
                                                        |
| 3796 | + *  | 
                                                        |
| 3797 | + * @since 4.9.0  | 
                                                        |
| 3798 | + */  | 
                                                        |
| 3799 | + protected function _send_now()  | 
                                                        |
| 3800 | +	{ | 
                                                        |
| 3801 | + $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3802 | + EED_Messages::send_now($msg_ids);  | 
                                                        |
| 3803 | + $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3804 | + }  | 
                                                        |
| 3805 | +  | 
                                                        |
| 3806 | +  | 
                                                        |
| 3807 | + /**  | 
                                                        |
| 3808 | + * Deletes EE_messages for IDs in the request.  | 
                                                        |
| 3809 | + *  | 
                                                        |
| 3810 | + * @since 4.9.0  | 
                                                        |
| 3811 | + */  | 
                                                        |
| 3812 | + protected function _delete_ee_messages()  | 
                                                        |
| 3813 | +	{ | 
                                                        |
| 3814 | + $msg_ids = $this->_get_msg_ids_from_request();  | 
                                                        |
| 3815 | + $deleted_count = 0;  | 
                                                        |
| 3816 | +		foreach ($msg_ids as $msg_id) { | 
                                                        |
| 3817 | +			if (EEM_Message::instance()->delete_by_ID($msg_id)) { | 
                                                        |
| 3818 | + $deleted_count++;  | 
                                                        |
| 3819 | + }  | 
                                                        |
| 3820 | + }  | 
                                                        |
| 3821 | +		if ($deleted_count) { | 
                                                        |
| 3822 | + $this->_redirect_after_action(  | 
                                                        |
| 3823 | + true,  | 
                                                        |
| 3824 | +				_n('message', 'messages', $deleted_count, 'event_espresso'), | 
                                                        |
| 3825 | +				__('deleted', 'event_espresso') | 
                                                        |
| 3826 | + );  | 
                                                        |
| 3827 | +		} else { | 
                                                        |
| 3828 | + EE_Error::add_error(  | 
                                                        |
| 3829 | +				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), | 
                                                        |
| 3830 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 3831 | + );  | 
                                                        |
| 3832 | + $this->_redirect_after_action(false, '', '', array(), true);  | 
                                                        |
| 3833 | + }  | 
                                                        |
| 3834 | + }  | 
                                                        |
| 3835 | +  | 
                                                        |
| 3836 | +  | 
                                                        |
| 3837 | + /**  | 
                                                        |
| 3838 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.  | 
                                                        |
| 3839 | + * @since 4.9.0  | 
                                                        |
| 3840 | + * @return array  | 
                                                        |
| 3841 | + */  | 
                                                        |
| 3842 | + protected function _get_msg_ids_from_request()  | 
                                                        |
| 3843 | +	{ | 
                                                        |
| 3844 | +		if ( ! isset($this->_req_data['MSG_ID'])) { | 
                                                        |
| 3845 | + return array();  | 
                                                        |
| 3846 | + }  | 
                                                        |
| 3847 | +  | 
                                                        |
| 3848 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);  | 
                                                        |
| 3849 | + }  | 
                                                        |
| 3850 | 3850 | |
| 3851 | 3851 | |
| 3852 | 3852 | }  | 
                                                        
@@ -87,7 +87,7 @@ discard block  | 
                                                    ||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL;  | 
                                                        
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN;  | 
                                                        
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();  | 
                                                        |
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();  | 
                                                        |
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;  | 
                                                        
| 93 | 93 | $this->_load_message_resource_manager();  | 
                                                        
@@ -219,7 +219,7 @@ discard block  | 
                                                    ||
| 219 | 219 |              array('none_selected' => __('Show All Messengers', 'event_espresso')), | 
                                                        
| 220 | 220 | $messenger_options  | 
                                                        
| 221 | 221 | );  | 
                                                        
| 222 | - $input = new EE_Select_Input(  | 
                                                        |
| 222 | + $input = new EE_Select_Input(  | 
                                                        |
| 223 | 223 | $messenger_options,  | 
                                                        
| 224 | 224 | array(  | 
                                                        
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by',  | 
                                                        
@@ -257,7 +257,7 @@ discard block  | 
                                                    ||
| 257 | 257 |              array('none_selected' => __('Show All Message Types', 'event_espresso')), | 
                                                        
| 258 | 258 | $message_type_options  | 
                                                        
| 259 | 259 | );  | 
                                                        
| 260 | - $input = new EE_Select_Input(  | 
                                                        |
| 260 | + $input = new EE_Select_Input(  | 
                                                        |
| 261 | 261 | $message_type_options,  | 
                                                        
| 262 | 262 | array(  | 
                                                        
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by',  | 
                                                        
@@ -295,7 +295,7 @@ discard block  | 
                                                    ||
| 295 | 295 |              array('none_selected' => __('Show all Contexts', 'event_espresso')), | 
                                                        
| 296 | 296 | $context_options  | 
                                                        
| 297 | 297 | );  | 
                                                        
| 298 | - $input = new EE_Select_Input(  | 
                                                        |
| 298 | + $input = new EE_Select_Input(  | 
                                                        |
| 299 | 299 | $context_options,  | 
                                                        
| 300 | 300 | array(  | 
                                                        
| 301 | 301 | 'html_name' => 'ee_context_filter_by',  | 
                                                        
@@ -676,47 +676,47 @@ discard block  | 
                                                    ||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab()  | 
                                                        
| 678 | 678 |      { | 
                                                        
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 680 | 680 | }  | 
                                                        
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab()  | 
                                                        
| 684 | 684 |      { | 
                                                        
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 686 | 686 | }  | 
                                                        
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab()  | 
                                                        
| 690 | 690 |      { | 
                                                        
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 692 | 692 | }  | 
                                                        
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab()  | 
                                                        
| 696 | 696 |      { | 
                                                        
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 698 | 698 | }  | 
                                                        
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab()  | 
                                                        
| 702 | 702 |      { | 
                                                        
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 704 | 704 | }  | 
                                                        
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab()  | 
                                                        
| 708 | 708 |      { | 
                                                        
| 709 | -        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', | 
                                                        |
| 710 | - 'event_espresso') . '" />';  | 
                                                        |
| 711 | -        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', | 
                                                        |
| 712 | - 'event_espresso') . '" />';  | 
                                                        |
| 713 | -        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', | 
                                                        |
| 714 | - 'event_espresso') . '" />';  | 
                                                        |
| 715 | -        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', | 
                                                        |
| 716 | - 'event_espresso') . '" />';  | 
                                                        |
| 717 | -        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', | 
                                                        |
| 718 | - 'event_espresso') . '" />';  | 
                                                        |
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 709 | +        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', | 
                                                        |
| 710 | + 'event_espresso').'" />';  | 
                                                        |
| 711 | +        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', | 
                                                        |
| 712 | + 'event_espresso').'" />';  | 
                                                        |
| 713 | +        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', | 
                                                        |
| 714 | + 'event_espresso').'" />';  | 
                                                        |
| 715 | +        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', | 
                                                        |
| 716 | + 'event_espresso').'" />';  | 
                                                        |
| 717 | +        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', | 
                                                        |
| 718 | + 'event_espresso').'" />';  | 
                                                        |
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 720 | 720 | $args);  | 
                                                        
| 721 | 721 | }  | 
                                                        
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block  | 
                                                    ||
| 725 | 725 |      { | 
                                                        
| 726 | 726 | $this->_set_shortcodes();  | 
                                                        
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes;  | 
                                                        
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 729 | 729 | $args);  | 
                                                        
| 730 | 730 | }  | 
                                                        
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab()  | 
                                                        
| 734 | 734 |      { | 
                                                        
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 736 | 736 | }  | 
                                                        
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab()  | 
                                                        
| 740 | 740 |      { | 
                                                        
| 741 | -        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', | 
                                                        |
| 742 | - 'event_espresso') . '" />';  | 
                                                        |
| 743 | -        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', | 
                                                        |
| 744 | - 'event_espresso') . '" />';  | 
                                                        |
| 741 | +        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', | 
                                                        |
| 742 | + 'event_espresso').'" />';  | 
                                                        |
| 743 | +        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', | 
                                                        |
| 744 | + 'event_espresso').'" />';  | 
                                                        |
| 745 | 745 | $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        
| 746 | 746 | $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';  | 
                                                        
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 748 | 748 | }  | 
                                                        
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles()  | 
                                                        
| 752 | 752 |      { | 
                                                        
| 753 | -        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 753 | +        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 754 | 754 |          wp_enqueue_style('espresso_ee_msg'); | 
                                                        
| 755 | 755 | |
| 756 | -        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', | 
                                                        |
| 756 | +        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', | 
                                                        |
| 757 | 757 |              array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); | 
                                                        
| 758 | -        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', | 
                                                        |
| 758 | +        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', | 
                                                        |
| 759 | 759 |              array('ee-dialog'), EVENT_ESPRESSO_VERSION); | 
                                                        
| 760 | 760 | }  | 
                                                        
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block  | 
                                                    ||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes();  | 
                                                        
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 791 | 791 |              __('Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.', | 
                                                        
| 792 | 792 | 'event_espresso'),  | 
                                                        
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'],  | 
                                                        
@@ -796,7 +796,7 @@ discard block  | 
                                                    ||
| 796 | 796 |          EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?', | 
                                                        
| 797 | 797 | 'event_espresso');  | 
                                                        
| 798 | 798 | |
| 799 | -        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), | 
                                                        |
| 799 | +        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), | 
                                                        |
| 800 | 800 | EVENT_ESPRESSO_VERSION);  | 
                                                        
| 801 | 801 | |
| 802 | 802 |          wp_enqueue_script('ee_admin_js'); | 
                                                        
@@ -827,7 +827,7 @@ discard block  | 
                                                    ||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings()  | 
                                                        
| 829 | 829 |      { | 
                                                        
| 830 | -        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), | 
                                                        |
| 830 | +        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), | 
                                                        |
| 831 | 831 | EVENT_ESPRESSO_VERSION);  | 
                                                        
| 832 | 832 |          wp_enqueue_style('ee-text-links'); | 
                                                        
| 833 | 833 |          wp_enqueue_style('ee-message-settings'); | 
                                                        
@@ -893,7 +893,7 @@ discard block  | 
                                                    ||
| 893 | 893 | }  | 
                                                        
| 894 | 894 | $status_bulk_actions = $common_bulk_actions;  | 
                                                        
| 895 | 895 | //unset bulk actions not applying to status  | 
                                                        
| 896 | -            if (! empty($status_bulk_actions)) { | 
                                                        |
| 896 | +            if ( ! empty($status_bulk_actions)) { | 
                                                        |
| 897 | 897 |                  switch ($status) { | 
                                                        
| 898 | 898 | case EEM_Message::status_idle:  | 
                                                        
| 899 | 899 | case EEM_Message::status_resend:  | 
                                                        
@@ -918,7 +918,7 @@ discard block  | 
                                                    ||
| 918 | 918 | }  | 
                                                        
| 919 | 919 | |
| 920 | 920 | //skip adding messenger executing status to views because it will be included with the Failed view.  | 
                                                        
| 921 | -            if ( $status === EEM_Message::status_messenger_executing ) { | 
                                                        |
| 921 | +            if ($status === EEM_Message::status_messenger_executing) { | 
                                                        |
| 922 | 922 | continue;  | 
                                                        
| 923 | 923 | }  | 
                                                        
| 924 | 924 | |
@@ -944,7 +944,7 @@ discard block  | 
                                                    ||
| 944 | 944 |          $this->_search_btn_label                   = __('Message Activity', 'event_espresso'); | 
                                                        
| 945 | 945 | $this->_template_args['per_column'] = 6;  | 
                                                        
| 946 | 946 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());  | 
                                                        
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';  | 
                                                        |
| 947 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>';  | 
                                                        |
| 948 | 948 | $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        
| 949 | 949 | }  | 
                                                        
| 950 | 950 | |
@@ -968,37 +968,37 @@ discard block  | 
                                                    ||
| 968 | 968 | /** @type array $status_items status legend setup */  | 
                                                        
| 969 | 969 | $status_items = array(  | 
                                                        
| 970 | 970 | 'sent_status' => array(  | 
                                                        
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,  | 
                                                        |
| 971 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,  | 
                                                        |
| 972 | 972 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')  | 
                                                        
| 973 | 973 | ),  | 
                                                        
| 974 | 974 | 'idle_status' => array(  | 
                                                        
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,  | 
                                                        |
| 975 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,  | 
                                                        |
| 976 | 976 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')  | 
                                                        
| 977 | 977 | ),  | 
                                                        
| 978 | 978 | 'failed_status' => array(  | 
                                                        
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,  | 
                                                        |
| 979 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,  | 
                                                        |
| 980 | 980 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')  | 
                                                        
| 981 | 981 | ),  | 
                                                        
| 982 | 982 | 'messenger_executing_status' => array(  | 
                                                        
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 983 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,  | 
                                                        |
| 984 | 984 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')  | 
                                                        
| 985 | 985 | ),  | 
                                                        
| 986 | 986 | 'resend_status' => array(  | 
                                                        
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,  | 
                                                        |
| 987 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,  | 
                                                        |
| 988 | 988 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')  | 
                                                        
| 989 | 989 | ),  | 
                                                        
| 990 | 990 | 'incomplete_status' => array(  | 
                                                        
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,  | 
                                                        |
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,  | 
                                                        |
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')  | 
                                                        
| 993 | 993 | ),  | 
                                                        
| 994 | 994 | 'retry_status' => array(  | 
                                                        
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,  | 
                                                        |
| 995 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,  | 
                                                        |
| 996 | 996 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')  | 
                                                        
| 997 | 997 | )  | 
                                                        
| 998 | 998 | );  | 
                                                        
| 999 | 999 |          if (EEM_Message::debug()) { | 
                                                        
| 1000 | 1000 | $status_items['debug_only_status'] = array(  | 
                                                        
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,  | 
                                                        |
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,  | 
                                                        |
| 1002 | 1002 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')  | 
                                                        
| 1003 | 1003 | );  | 
                                                        
| 1004 | 1004 | }  | 
                                                        
@@ -1010,10 +1010,10 @@ discard block  | 
                                                    ||
| 1010 | 1010 | protected function _custom_mtps_preview()  | 
                                                        
| 1011 | 1011 |      { | 
                                                        
| 1012 | 1012 |          $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        
| 1013 | -        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', | 
                                                        |
| 1014 | - 'event_espresso') . '" />';  | 
                                                        |
| 1015 | -        $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | 
                                                        |
| 1016 | - 'event_espresso') . '</strong>';  | 
                                                        |
| 1013 | +        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', | 
                                                        |
| 1014 | + 'event_espresso').'" />';  | 
                                                        |
| 1015 | +        $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | 
                                                        |
| 1016 | + 'event_espresso').'</strong>';  | 
                                                        |
| 1017 | 1017 |          $this->display_admin_caf_preview_page('custom_message_types', false); | 
                                                        
| 1018 | 1018 | }  | 
                                                        
| 1019 | 1019 | |
@@ -1261,7 +1261,7 @@ discard block  | 
                                                    ||
| 1261 | 1261 | //let's verify if we need this extra field via the shortcodes parameter.  | 
                                                        
| 1262 | 1262 | $continue = false;  | 
                                                        
| 1263 | 1263 |                              if (isset($extra_array['shortcodes_required'])) { | 
                                                        
| 1264 | -                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1264 | +                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1265 | 1265 |                                      if ( ! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        
| 1266 | 1266 | $continue = true;  | 
                                                        
| 1267 | 1267 | }  | 
                                                        
@@ -1271,9 +1271,9 @@ discard block  | 
                                                    ||
| 1271 | 1271 | }  | 
                                                        
| 1272 | 1272 | }  | 
                                                        
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1274 | + $field_id = $reference_field.'-'.$extra_field.'-content';  | 
                                                        |
| 1275 | 1275 | $template_form_fields[$field_id] = $extra_array;  | 
                                                        
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';  | 
                                                        |
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']';  | 
                                                        |
| 1277 | 1277 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';  | 
                                                        
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        
@@ -1283,7 +1283,7 @@ discard block  | 
                                                    ||
| 1283 | 1283 | is_array($validators[$extra_field])  | 
                                                        
| 1284 | 1284 | && isset($validators[$extra_field]['msg'])  | 
                                                        
| 1285 | 1285 | )  | 
                                                        
| 1286 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1286 | + ? 'validate-error '.$css_class  | 
                                                        |
| 1287 | 1287 | : $css_class;  | 
                                                        
| 1288 | 1288 | |
| 1289 | 1289 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])  | 
                                                        
@@ -1311,11 +1311,11 @@ discard block  | 
                                                    ||
| 1311 | 1311 | |
| 1312 | 1312 | }/**/  | 
                                                        
| 1313 | 1313 | }  | 
                                                        
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1315 | - $templatefield_templatename_id = $reference_field . '-name';  | 
                                                        |
| 1314 | + $templatefield_MTP_id = $reference_field.'-MTP_ID';  | 
                                                        |
| 1315 | + $templatefield_templatename_id = $reference_field.'-name';  | 
                                                        |
| 1316 | 1316 | |
| 1317 | 1317 | $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1318 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]',  | 
                                                        |
| 1319 | 1319 | 'label' => null,  | 
                                                        
| 1320 | 1320 | 'input' => 'hidden',  | 
                                                        
| 1321 | 1321 | 'type' => 'int',  | 
                                                        
@@ -1328,7 +1328,7 @@ discard block  | 
                                                    ||
| 1328 | 1328 | );  | 
                                                        
| 1329 | 1329 | |
| 1330 | 1330 | $template_form_fields[$templatefield_templatename_id] = array(  | 
                                                        
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1331 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]',  | 
                                                        |
| 1332 | 1332 | 'label' => null,  | 
                                                        
| 1333 | 1333 | 'input' => 'hidden',  | 
                                                        
| 1334 | 1334 | 'type' => 'string',  | 
                                                        
@@ -1342,9 +1342,9 @@ discard block  | 
                                                    ||
| 1342 | 1342 | }  | 
                                                        
| 1343 | 1343 | continue; //skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        
| 1344 | 1344 |                  } else { | 
                                                        
| 1345 | - $field_id = $template_field . '-content';  | 
                                                        |
| 1345 | + $field_id = $template_field.'-content';  | 
                                                        |
| 1346 | 1346 | $template_form_fields[$field_id] = $field_setup_array;  | 
                                                        
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]';  | 
                                                        |
| 1348 | 1348 | $message_template = isset($message_templates[$context][$template_field])  | 
                                                        
| 1349 | 1349 | ? $message_templates[$context][$template_field]  | 
                                                        
| 1350 | 1350 | : null;  | 
                                                        
@@ -1365,7 +1365,7 @@ discard block  | 
                                                    ||
| 1365 | 1365 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        
| 1366 | 1366 | && in_array($template_field, $v_fields)  | 
                                                        
| 1367 | 1367 | && isset($validators[$template_field]['msg'])  | 
                                                        
| 1368 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1368 | + ? 'validate-error '.$css_class  | 
                                                        |
| 1369 | 1369 | : $css_class;  | 
                                                        
| 1370 | 1370 | |
| 1371 | 1371 | //shortcode selector  | 
                                                        
@@ -1376,12 +1376,12 @@ discard block  | 
                                                    ||
| 1376 | 1376 | |
| 1377 | 1377 | //k took care of content field(s) now let's take care of others.  | 
                                                        
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name';  | 
                                                        |
| 1379 | + $templatefield_MTP_id = $template_field.'-MTP_ID';  | 
                                                        |
| 1380 | + $templatefield_field_templatename_id = $template_field.'-name';  | 
                                                        |
| 1381 | 1381 | |
| 1382 | 1382 | //foreach template field there are actually two form fields created  | 
                                                        
| 1383 | 1383 | $template_form_fields[$templatefield_MTP_id] = array(  | 
                                                        
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1384 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]',  | 
                                                        |
| 1385 | 1385 | 'label' => null,  | 
                                                        
| 1386 | 1386 | 'input' => 'hidden',  | 
                                                        
| 1387 | 1387 | 'type' => 'int',  | 
                                                        
@@ -1394,7 +1394,7 @@ discard block  | 
                                                    ||
| 1394 | 1394 | );  | 
                                                        
| 1395 | 1395 | |
| 1396 | 1396 | $template_form_fields[$templatefield_field_templatename_id] = array(  | 
                                                        
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1397 | + 'name' => 'MTP_template_fields['.$template_field.'][name]',  | 
                                                        |
| 1398 | 1398 | 'label' => null,  | 
                                                        
| 1399 | 1399 | 'input' => 'hidden',  | 
                                                        
| 1400 | 1400 | 'type' => 'string',  | 
                                                        
@@ -1512,7 +1512,7 @@ discard block  | 
                                                    ||
| 1512 | 1512 | 'format' => '%d',  | 
                                                        
| 1513 | 1513 | 'db-col' => 'MTP_deleted'  | 
                                                        
| 1514 | 1514 | );  | 
                                                        
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array(  | 
                                                        |
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array(  | 
                                                        |
| 1516 | 1516 | 'name' => 'MTP_user_id',  | 
                                                        
| 1517 | 1517 |                  'label'      => __('Author', 'event_espresso'), | 
                                                        
| 1518 | 1518 | 'input' => 'hidden',  | 
                                                        
@@ -1531,17 +1531,17 @@ discard block  | 
                                                    ||
| 1531 | 1531 | 'value' => $action  | 
                                                        
| 1532 | 1532 | );  | 
                                                        
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array(  | 
                                                        |
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array(  | 
                                                        |
| 1535 | 1535 | 'name' => 'id',  | 
                                                        
| 1536 | 1536 | 'input' => 'hidden',  | 
                                                        
| 1537 | 1537 | 'type' => 'int',  | 
                                                        
| 1538 | 1538 | 'value' => $GRP_ID  | 
                                                        
| 1539 | 1539 | );  | 
                                                        
| 1540 | 1540 | $sidebar_form_fields['ee-msg-evt-nonce'] = array(  | 
                                                        
| 1541 | - 'name' => $action . '_nonce',  | 
                                                        |
| 1541 | + 'name' => $action.'_nonce',  | 
                                                        |
| 1542 | 1542 | 'input' => 'hidden',  | 
                                                        
| 1543 | 1543 | 'type' => 'string',  | 
                                                        
| 1544 | - 'value' => wp_create_nonce($action . '_nonce')  | 
                                                        |
| 1544 | + 'value' => wp_create_nonce($action.'_nonce')  | 
                                                        |
| 1545 | 1545 | );  | 
                                                        
| 1546 | 1546 | |
| 1547 | 1547 |              if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { | 
                                                        
@@ -1573,7 +1573,7 @@ discard block  | 
                                                    ||
| 1573 | 1573 | );  | 
                                                        
| 1574 | 1574 | |
| 1575 | 1575 | //add preview button  | 
                                                        
| 1576 | - $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1576 | + $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1577 | 1577 | array(  | 
                                                        
| 1578 | 1578 | 'message_type' => $message_template_group->message_type(),  | 
                                                        
| 1579 | 1579 | 'messenger' => $message_template_group->messenger(),  | 
                                                        
@@ -1583,8 +1583,8 @@ discard block  | 
                                                    ||
| 1583 | 1583 | ),  | 
                                                        
| 1584 | 1584 | $this->_admin_base_url  | 
                                                        
| 1585 | 1585 | );  | 
                                                        
| 1586 | -        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', | 
                                                        |
| 1587 | - 'event_espresso') . '</a>';  | 
                                                        |
| 1586 | +        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', | 
                                                        |
| 1587 | + 'event_espresso').'</a>';  | 
                                                        |
| 1588 | 1588 | |
| 1589 | 1589 | |
| 1590 | 1590 | //setup context switcher  | 
                                                        
@@ -1613,7 +1613,7 @@ discard block  | 
                                                    ||
| 1613 | 1613 | |
| 1614 | 1614 | $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        
| 1615 | 1615 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1616 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1617 | 1617 | |
| 1618 | 1618 | //send along EE_Message_Template_Group object for further template use.  | 
                                                        
| 1619 | 1619 | $this->_template_args['MTP'] = $message_template_group;  | 
                                                        
@@ -1648,7 +1648,7 @@ discard block  | 
                                                    ||
| 1648 | 1648 | |
| 1649 | 1649 | public function _add_form_element_before()  | 
                                                        
| 1650 | 1650 |      { | 
                                                        
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';  | 
                                                        |
| 1651 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">';  | 
                                                        |
| 1652 | 1652 | }  | 
                                                        
| 1653 | 1653 | |
| 1654 | 1654 | public function _add_form_element_after()  | 
                                                        
@@ -1843,14 +1843,14 @@ discard block  | 
                                                    ||
| 1843 | 1843 | }  | 
                                                        
| 1844 | 1844 | |
| 1845 | 1845 | //let's add a button to go back to the edit view  | 
                                                        
| 1846 | - $query_args = array(  | 
                                                        |
| 1846 | + $query_args = array(  | 
                                                        |
| 1847 | 1847 | 'id' => $this->_req_data['GRP_ID'],  | 
                                                        
| 1848 | 1848 | 'context' => $this->_req_data['context'],  | 
                                                        
| 1849 | 1849 | 'action' => 'edit_message_template'  | 
                                                        
| 1850 | 1850 | );  | 
                                                        
| 1851 | 1851 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        
| 1852 | -        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', | 
                                                        |
| 1853 | - 'event_espresso') . '</a>';  | 
                                                        |
| 1852 | +        $preview_button         = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', | 
                                                        |
| 1853 | + 'event_espresso').'</a>';  | 
                                                        |
| 1854 | 1854 | $message_types = $this->get_installed_message_types();  | 
                                                        
| 1855 | 1855 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);  | 
                                                        
| 1856 | 1856 | $active_messenger_label = $active_messenger instanceof EE_messenger  | 
                                                        
@@ -1864,7 +1864,7 @@ discard block  | 
                                                    ||
| 1864 | 1864 | );  | 
                                                        
| 1865 | 1865 | //setup display of preview.  | 
                                                        
| 1866 | 1866 | $this->_admin_page_title = $preview_title;  | 
                                                        
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);  | 
                                                        |
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview);  | 
                                                        |
| 1868 | 1868 | $this->_template_args['data']['force_json'] = true;  | 
                                                        
| 1869 | 1869 | |
| 1870 | 1870 | return '';  | 
                                                        
@@ -1946,7 +1946,7 @@ discard block  | 
                                                    ||
| 1946 | 1946 | }  | 
                                                        
| 1947 | 1947 | |
| 1948 | 1948 | //setup variation select values for the currently selected template.  | 
                                                        
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 1950 | 1950 | $this->_message_template_group->messenger(),  | 
                                                        
| 1951 | 1951 | $this->_message_template_group->message_type()  | 
                                                        
| 1952 | 1952 | );  | 
                                                        
@@ -1960,12 +1960,12 @@ discard block  | 
                                                    ||
| 1960 | 1960 | |
| 1961 | 1961 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        
| 1962 | 1962 | |
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1964 | 1964 | 'MTP_template_pack',  | 
                                                        
| 1965 | 1965 | $tp_select_values,  | 
                                                        
| 1966 | 1966 | $this->_message_template_group->get_template_pack_name()  | 
                                                        
| 1967 | 1967 | );  | 
                                                        
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 1969 | 1969 | 'MTP_template_variation',  | 
                                                        
| 1970 | 1970 | $variations_select_values,  | 
                                                        
| 1971 | 1971 | $this->_message_template_group->get_template_pack_variation()  | 
                                                        
@@ -1975,7 +1975,7 @@ discard block  | 
                                                    ||
| 1975 | 1975 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        
| 1976 | 1976 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        
| 1977 | 1977 | |
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 1978 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 1979 | 1979 | |
| 1980 | 1980 | EEH_Template::display_template($template, $template_args);  | 
                                                        
| 1981 | 1981 | }  | 
                                                        
@@ -2004,7 +2004,7 @@ discard block  | 
                                                    ||
| 2004 | 2004 |          if ( ! empty($fields)) { | 
                                                        
| 2005 | 2005 | //yup there be fields  | 
                                                        
| 2006 | 2006 |              foreach ($fields as $field => $config) { | 
                                                        
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2007 | + $field_id = $this->_message_template_group->messenger().'_'.$field;  | 
                                                        |
| 2008 | 2008 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        
| 2009 | 2009 | $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        
| 2010 | 2010 | $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        
@@ -2019,7 +2019,7 @@ discard block  | 
                                                    ||
| 2019 | 2019 | : $fix;  | 
                                                        
| 2020 | 2020 | |
| 2021 | 2021 | $template_form_fields[$field_id] = array(  | 
                                                        
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2022 | + 'name' => 'test_settings_fld['.$field.']',  | 
                                                        |
| 2023 | 2023 | 'label' => $config['label'],  | 
                                                        
| 2024 | 2024 | 'input' => $config['input'],  | 
                                                        
| 2025 | 2025 | 'type' => $config['type'],  | 
                                                        
@@ -2049,7 +2049,7 @@ discard block  | 
                                                    ||
| 2049 | 2049 | }  | 
                                                        
| 2050 | 2050 | |
| 2051 | 2051 | //and button  | 
                                                        
| 2052 | -        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; | 
                                                        |
| 2052 | +        $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; | 
                                                        |
| 2053 | 2053 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">';  | 
                                                        
| 2054 | 2054 | $test_settings_html .= $this->get_action_link_or_button(  | 
                                                        
| 2055 | 2055 | 'reset_to_default',  | 
                                                        
@@ -2080,7 +2080,7 @@ discard block  | 
                                                    ||
| 2080 | 2080 | 'linked_input_id' => $linked_input_id  | 
                                                        
| 2081 | 2081 | );  | 
                                                        
| 2082 | 2082 | |
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2084 | 2084 | $template_args, true);  | 
                                                        
| 2085 | 2085 | }  | 
                                                        
| 2086 | 2086 | |
@@ -2098,7 +2098,7 @@ discard block  | 
                                                    ||
| 2098 | 2098 | //$messenger = $this->_message_template_group->messenger_obj();  | 
                                                        
| 2099 | 2099 | //now let's set the content depending on the status of the shortcodes array  | 
                                                        
| 2100 | 2100 |          if (empty($shortcodes)) { | 
                                                        
| 2101 | -            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2101 | +            $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; | 
                                                        |
| 2102 | 2102 | echo $content;  | 
                                                        
| 2103 | 2103 |          } else { | 
                                                        
| 2104 | 2104 | //$alt = 0;  | 
                                                        
@@ -2215,7 +2215,7 @@ discard block  | 
                                                    ||
| 2215 | 2215 | <?php  | 
                                                        
| 2216 | 2216 | }  | 
                                                        
| 2217 | 2217 | //setup nonce_url  | 
                                                        
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2218 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);  | 
                                                        |
| 2219 | 2219 | ?>  | 
                                                        
| 2220 | 2220 | <select name="context">  | 
                                                        
| 2221 | 2221 | <?php  | 
                                                        
@@ -2313,7 +2313,7 @@ discard block  | 
                                                    ||
| 2313 | 2313 | : '';  | 
                                                        
| 2314 | 2314 |          $context      = ucwords(str_replace('_', ' ', $context_slug)); | 
                                                        
| 2315 | 2315 | |
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';  | 
                                                        |
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : '';  | 
                                                        |
| 2317 | 2317 | $item_desc .= 'Message Template';  | 
                                                        
| 2318 | 2318 | $query_args = array();  | 
                                                        
| 2319 | 2319 | $edit_array = array();  | 
                                                        
@@ -2688,8 +2688,8 @@ discard block  | 
                                                    ||
| 2688 | 2688 | */  | 
                                                        
| 2689 | 2689 | protected function _learn_more_about_message_templates_link()  | 
                                                        
| 2690 | 2690 |      { | 
                                                        
| 2691 | -        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', | 
                                                        |
| 2692 | - 'event_espresso') . '</a>';  | 
                                                        |
| 2691 | +        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', | 
                                                        |
| 2692 | + 'event_espresso').'</a>';  | 
                                                        |
| 2693 | 2693 | }  | 
                                                        
| 2694 | 2694 | |
| 2695 | 2695 | |
@@ -2765,10 +2765,10 @@ discard block  | 
                                                    ||
| 2765 | 2765 | |
| 2766 | 2766 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(  | 
                                                        
| 2767 | 2767 | 'label' => ucwords($message_type->label['singular']),  | 
                                                        
| 2768 | - 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 2769 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 2770 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 2771 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 2768 | + 'class' => 'message-type-'.$a_or_i,  | 
                                                        |
| 2769 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name,  | 
                                                        |
| 2770 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),  | 
                                                        |
| 2771 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings',  | 
                                                        |
| 2772 | 2772 | 'title' => $a_or_i == 'active'  | 
                                                        
| 2773 | 2773 |                          ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        
| 2774 | 2774 |                          : __('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        
@@ -2804,9 +2804,9 @@ discard block  | 
                                                    ||
| 2804 | 2804 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        
| 2805 | 2805 | |
| 2806 | 2806 |              foreach ($fields as $fldname => $fldprops) { | 
                                                        
| 2807 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 2807 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname;  | 
                                                        |
| 2808 | 2808 | $template_form_field[$field_id] = array(  | 
                                                        
| 2809 | - 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 2809 | + 'name' => 'message_type_settings['.$fldname.']',  | 
                                                        |
| 2810 | 2810 | 'label' => $fldprops['label'],  | 
                                                        
| 2811 | 2811 | 'input' => $fldprops['field_type'],  | 
                                                        
| 2812 | 2812 | 'type' => $fldprops['value_type'],  | 
                                                        
@@ -2847,7 +2847,7 @@ discard block  | 
                                                    ||
| 2847 | 2847 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';  | 
                                                        
| 2848 | 2848 | |
| 2849 | 2849 | |
| 2850 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 2850 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 2851 | 2851 | $content = EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        
| 2852 | 2852 | |
| 2853 | 2853 | return $content;  | 
                                                        
@@ -2877,11 +2877,11 @@ discard block  | 
                                                    ||
| 2877 | 2877 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])  | 
                                                        
| 2878 | 2878 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']  | 
                                                        
| 2879 | 2879 | : '';  | 
                                                        
| 2880 | - $m_boxes[$messenger . '_a_box'] = sprintf(  | 
                                                        |
| 2880 | + $m_boxes[$messenger.'_a_box'] = sprintf(  | 
                                                        |
| 2881 | 2881 |                      __('%s Settings', 'event_espresso'), | 
                                                        
| 2882 | 2882 | $tab_array['label']  | 
                                                        
| 2883 | 2883 | );  | 
                                                        
| 2884 | - $m_template_args[$messenger . '_a_box'] = array(  | 
                                                        |
| 2884 | + $m_template_args[$messenger.'_a_box'] = array(  | 
                                                        |
| 2885 | 2885 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        
| 2886 | 2886 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        
| 2887 | 2887 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        
@@ -2895,8 +2895,8 @@ discard block  | 
                                                    ||
| 2895 | 2895 | // message type meta boxes  | 
                                                        
| 2896 | 2896 | // (which is really just the inactive container for each messenger  | 
                                                        
| 2897 | 2897 | // showing inactive message types for that messenger)  | 
                                                        
| 2898 | -                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 2899 | - $mt_template_args[$messenger . '_i_box'] = array(  | 
                                                        |
| 2898 | +                $mt_boxes[$messenger.'_i_box']         = __('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 2899 | + $mt_template_args[$messenger.'_i_box'] = array(  | 
                                                        |
| 2900 | 2900 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        
| 2901 | 2901 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        
| 2902 | 2902 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        
@@ -2912,14 +2912,14 @@ discard block  | 
                                                    ||
| 2912 | 2912 | |
| 2913 | 2913 | |
| 2914 | 2914 | //register messenger metaboxes  | 
                                                        
| 2915 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 2915 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 2916 | 2916 |          foreach ($m_boxes as $box => $label) { | 
                                                        
| 2917 | 2917 |              $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); | 
                                                        
| 2918 | 2918 |              $msgr          = str_replace('_a_box', '', $box); | 
                                                        
| 2919 | 2919 | add_meta_box(  | 
                                                        
| 2920 | - 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 2920 | + 'espresso_'.$msgr.'_settings',  | 
                                                        |
| 2921 | 2921 | $label,  | 
                                                        
| 2922 | -                function ($post, $metabox) { | 
                                                        |
| 2922 | +                function($post, $metabox) { | 
                                                        |
| 2923 | 2923 | echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        
| 2924 | 2924 | $metabox["args"]["template_args"], true);  | 
                                                        
| 2925 | 2925 | },  | 
                                                        
@@ -2931,17 +2931,17 @@ discard block  | 
                                                    ||
| 2931 | 2931 | }  | 
                                                        
| 2932 | 2932 | |
| 2933 | 2933 | //register message type metaboxes  | 
                                                        
| 2934 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 2934 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 2935 | 2935 |          foreach ($mt_boxes as $box => $label) { | 
                                                        
| 2936 | 2936 | $callback_args = array(  | 
                                                        
| 2937 | 2937 | 'template_path' => $mt_template_path,  | 
                                                        
| 2938 | 2938 | 'template_args' => $mt_template_args[$box]  | 
                                                        
| 2939 | 2939 | );  | 
                                                        
| 2940 | -            $mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 2940 | +            $mt = str_replace('_i_box', '', $box); | 
                                                        |
| 2941 | 2941 | add_meta_box(  | 
                                                        
| 2942 | - 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 2942 | + 'espresso_'.$mt.'_inactive_mts',  | 
                                                        |
| 2943 | 2943 | $label,  | 
                                                        
| 2944 | -                function ($post, $metabox) { | 
                                                        |
| 2944 | +                function($post, $metabox) { | 
                                                        |
| 2945 | 2945 | echo EEH_Template::display_template($metabox["args"]["template_path"],  | 
                                                        
| 2946 | 2946 | $metabox["args"]["template_args"], true);  | 
                                                        
| 2947 | 2947 | },  | 
                                                        
@@ -3043,7 +3043,7 @@ discard block  | 
                                                    ||
| 3043 | 3043 |              if ($form->is_valid()) { | 
                                                        
| 3044 | 3044 | $valid_data = $form->valid_data();  | 
                                                        
| 3045 | 3045 |                  foreach ($valid_data as $property => $value) { | 
                                                        
| 3046 | - $setter = 'set_' . $property;  | 
                                                        |
| 3046 | + $setter = 'set_'.$property;  | 
                                                        |
| 3047 | 3047 |                      if (method_exists($network_config, $setter)) { | 
                                                        
| 3048 | 3048 |                          $network_config->{$setter}($value); | 
                                                        
| 3049 | 3049 | } else if (  | 
                                                        
@@ -3072,8 +3072,8 @@ discard block  | 
                                                    ||
| 3072 | 3072 | */  | 
                                                        
| 3073 | 3073 | protected function _get_mt_tabs($tab_array)  | 
                                                        
| 3074 | 3074 |      { | 
                                                        
| 3075 | - $tab_array = (array)$tab_array;  | 
                                                        |
| 3076 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3075 | + $tab_array = (array) $tab_array;  | 
                                                        |
| 3076 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3077 | 3077 | $tabs = '';  | 
                                                        
| 3078 | 3078 | |
| 3079 | 3079 |          foreach ($tab_array as $tab) { | 
                                                        
@@ -3106,9 +3106,9 @@ discard block  | 
                                                    ||
| 3106 | 3106 | $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        
| 3107 | 3107 | |
| 3108 | 3108 |              foreach ($fields as $fldname => $fldprops) { | 
                                                        
| 3109 | - $field_id = $messenger->name . '-' . $fldname;  | 
                                                        |
| 3109 | + $field_id = $messenger->name.'-'.$fldname;  | 
                                                        |
| 3110 | 3110 | $template_form_field[$field_id] = array(  | 
                                                        
| 3111 | - 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3111 | + 'name' => 'messenger_settings['.$field_id.']',  | 
                                                        |
| 3112 | 3112 | 'label' => $fldprops['label'],  | 
                                                        
| 3113 | 3113 | 'input' => $fldprops['field_type'],  | 
                                                        
| 3114 | 3114 | 'type' => $fldprops['value_type'],  | 
                                                        
@@ -3143,7 +3143,7 @@ discard block  | 
                                                    ||
| 3143 | 3143 | //make sure any active message types that are existing are included in the hidden fields  | 
                                                        
| 3144 | 3144 |          if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { | 
                                                        
| 3145 | 3145 |              foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { | 
                                                        
| 3146 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(  | 
                                                        |
| 3146 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(  | 
                                                        |
| 3147 | 3147 | 'type' => 'hidden',  | 
                                                        
| 3148 | 3148 | 'value' => $mt  | 
                                                        
| 3149 | 3149 | );  | 
                                                        
@@ -3153,7 +3153,7 @@ discard block  | 
                                                    ||
| 3153 | 3153 | $settings_template_args['hidden_fields'],  | 
                                                        
| 3154 | 3154 | 'array'  | 
                                                        
| 3155 | 3155 | );  | 
                                                        
| 3156 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3156 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3157 | 3157 | |
| 3158 | 3158 | $settings_template_args['messenger'] = $messenger->name;  | 
                                                        
| 3159 | 3159 | $settings_template_args['description'] = $messenger->description;  | 
                                                        
@@ -3170,9 +3170,9 @@ discard block  | 
                                                    ||
| 3170 | 3170 | |
| 3171 | 3171 | |
| 3172 | 3172 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        
| 3173 | -        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3173 | +        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); | 
                                                        |
| 3174 | 3174 | $settings_template_args['on_off_status'] = $active ? true : false;  | 
                                                        
| 3175 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3175 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3176 | 3176 | $content = EEH_Template::display_template($template, $settings_template_args,  | 
                                                        
| 3177 | 3177 | true);  | 
                                                        
| 3178 | 3178 | |
@@ -3200,7 +3200,7 @@ discard block  | 
                                                    ||
| 3200 | 3200 | |
| 3201 | 3201 | //do a nonce check here since we're not arriving via a normal route  | 
                                                        
| 3202 | 3202 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';  | 
                                                        
| 3203 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';  | 
                                                        |
| 3203 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';  | 
                                                        |
| 3204 | 3204 | |
| 3205 | 3205 | $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        
| 3206 | 3206 | |
@@ -3302,7 +3302,7 @@ discard block  | 
                                                    ||
| 3302 | 3302 | |
| 3303 | 3303 | //do a nonce check here since we're not arriving via a normal route  | 
                                                        
| 3304 | 3304 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';  | 
                                                        
| 3305 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce';  | 
                                                        |
| 3305 | + $nonce_ref = $this->_req_data['message_type'].'_nonce';  | 
                                                        |
| 3306 | 3306 | |
| 3307 | 3307 | $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        
| 3308 | 3308 | |
@@ -21,345 +21,345 @@  | 
                                                    ||
| 21 | 21 | class TicketSelectorRowStandard extends TicketSelectorRow  | 
                                                        
| 22 | 22 |  { | 
                                                        
| 23 | 23 | |
| 24 | - /**  | 
                                                        |
| 25 | - * @var TicketDetails $ticket_details  | 
                                                        |
| 26 | - */  | 
                                                        |
| 27 | - protected $ticket_details;  | 
                                                        |
| 28 | -  | 
                                                        |
| 29 | - /**  | 
                                                        |
| 30 | - * @var \EE_Ticket_Selector_Config $template_settings  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - protected $template_settings;  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - /**  | 
                                                        |
| 35 | - * @var EE_Tax_Config $tax_settings  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - protected $tax_settings;  | 
                                                        |
| 38 | -  | 
                                                        |
| 39 | - /**  | 
                                                        |
| 40 | - * @var boolean $prices_displayed_including_taxes  | 
                                                        |
| 41 | - */  | 
                                                        |
| 42 | - protected $prices_displayed_including_taxes;  | 
                                                        |
| 43 | -  | 
                                                        |
| 44 | - /**  | 
                                                        |
| 45 | - * @var int $row  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected $row;  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | - /**  | 
                                                        |
| 50 | - * @var int $cols  | 
                                                        |
| 51 | - */  | 
                                                        |
| 52 | - protected $cols;  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /**  | 
                                                        |
| 55 | - * @var boolean $hidden_input_qty  | 
                                                        |
| 56 | - */  | 
                                                        |
| 57 | - protected $hidden_input_qty;  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - /**  | 
                                                        |
| 60 | - * @var string $ticket_datetime_classes  | 
                                                        |
| 61 | - */  | 
                                                        |
| 62 | - protected $ticket_datetime_classes;  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - /**  | 
                                                        |
| 67 | - * TicketDetails constructor.  | 
                                                        |
| 68 | - *  | 
                                                        |
| 69 | - * @param TicketDetails $ticket_details  | 
                                                        |
| 70 | - * @param EE_Tax_Config $tax_settings  | 
                                                        |
| 71 | - * @param int $total_tickets  | 
                                                        |
| 72 | - * @param int $max_attendees  | 
                                                        |
| 73 | - * @param int $row  | 
                                                        |
| 74 | - * @param int $cols  | 
                                                        |
| 75 | - * @param boolean $required_ticket_sold_out  | 
                                                        |
| 76 | - * @param string $event_status  | 
                                                        |
| 77 | - * @param string $ticket_datetime_classes  | 
                                                        |
| 78 | - * @throws EE_Error  | 
                                                        |
| 79 | - * @throws UnexpectedEntityException  | 
                                                        |
| 80 | - */  | 
                                                        |
| 81 | - public function __construct(  | 
                                                        |
| 82 | - TicketDetails $ticket_details,  | 
                                                        |
| 83 | - EE_Tax_Config $tax_settings,  | 
                                                        |
| 84 | - $total_tickets,  | 
                                                        |
| 85 | - $max_attendees,  | 
                                                        |
| 86 | - $row,  | 
                                                        |
| 87 | - $cols,  | 
                                                        |
| 88 | - $required_ticket_sold_out,  | 
                                                        |
| 89 | - $event_status,  | 
                                                        |
| 90 | - $ticket_datetime_classes  | 
                                                        |
| 91 | -    ) { | 
                                                        |
| 92 | - $this->ticket_details = $ticket_details;  | 
                                                        |
| 93 | - $this->template_settings = $ticket_details->getTemplateSettings();  | 
                                                        |
| 94 | - $this->tax_settings = $tax_settings;  | 
                                                        |
| 95 | - $this->row = $row;  | 
                                                        |
| 96 | - $this->cols = $cols;  | 
                                                        |
| 97 | - $this->ticket_datetime_classes = $ticket_datetime_classes;  | 
                                                        |
| 98 | - parent::__construct(  | 
                                                        |
| 99 | - $ticket_details->getTicket(),  | 
                                                        |
| 100 | - $max_attendees,  | 
                                                        |
| 101 | - $ticket_details->getDateFormat(),  | 
                                                        |
| 102 | - $event_status,  | 
                                                        |
| 103 | - $required_ticket_sold_out,  | 
                                                        |
| 104 | - $total_tickets  | 
                                                        |
| 105 | - );  | 
                                                        |
| 106 | - }  | 
                                                        |
| 107 | -  | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /**  | 
                                                        |
| 111 | - * other ticket rows will need to know if a required ticket is sold out,  | 
                                                        |
| 112 | - * so that they are not offered for sale  | 
                                                        |
| 113 | - *  | 
                                                        |
| 114 | - * @return boolean  | 
                                                        |
| 115 | - */  | 
                                                        |
| 116 | - public function getRequiredTicketSoldOut()  | 
                                                        |
| 117 | -    { | 
                                                        |
| 118 | - return $this->required_ticket_sold_out;  | 
                                                        |
| 119 | - }  | 
                                                        |
| 120 | -  | 
                                                        |
| 121 | -  | 
                                                        |
| 122 | -  | 
                                                        |
| 123 | - /**  | 
                                                        |
| 124 | - * @return int  | 
                                                        |
| 125 | - */  | 
                                                        |
| 126 | - public function getCols()  | 
                                                        |
| 127 | -    { | 
                                                        |
| 128 | - return $this->cols;  | 
                                                        |
| 129 | - }  | 
                                                        |
| 130 | -  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - /**  | 
                                                        |
| 134 | - * getHtml  | 
                                                        |
| 135 | - *  | 
                                                        |
| 136 | - * @return string  | 
                                                        |
| 137 | - * @throws EE_Error  | 
                                                        |
| 138 | - */  | 
                                                        |
| 139 | - public function getHtml()  | 
                                                        |
| 140 | -    { | 
                                                        |
| 141 | - $this->min = 0;  | 
                                                        |
| 142 | - $this->max = $this->ticket->max();  | 
                                                        |
| 143 | - $remaining = $this->ticket->remaining();  | 
                                                        |
| 144 | -        if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { | 
                                                        |
| 145 | - $this->setTicketMinAndMax($remaining);  | 
                                                        |
| 146 | -        } else { | 
                                                        |
| 147 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)  | 
                                                        |
| 148 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining  | 
                                                        |
| 149 | - ? $this->ticket->start_date()  | 
                                                        |
| 150 | - : $this->required_ticket_sold_out;  | 
                                                        |
| 151 | - }  | 
                                                        |
| 152 | - $this->setTicketPriceDetails();  | 
                                                        |
| 153 | - $this->setTicketStatusClasses($remaining);  | 
                                                        |
| 154 | - $filtered_row_html = $this->getFilteredRowHtml();  | 
                                                        |
| 155 | -        if ($filtered_row_html !== false) { | 
                                                        |
| 156 | - return $filtered_row_html;  | 
                                                        |
| 157 | - }  | 
                                                        |
| 158 | - $ticket_selector_row_html = EEH_HTML::tr(  | 
                                                        |
| 159 | - '', '',  | 
                                                        |
| 160 | -            "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " | 
                                                        |
| 161 | - . espresso_get_object_css_class($this->ticket)  | 
                                                        |
| 162 | - );  | 
                                                        |
| 163 | - $filtered_row_content = $this->getFilteredRowContents();  | 
                                                        |
| 164 | -        if ($filtered_row_content !== false && $this->max_attendees === 1) { | 
                                                        |
| 165 | - return $ticket_selector_row_html  | 
                                                        |
| 166 | - . $filtered_row_content  | 
                                                        |
| 167 | - . $this->ticketQtyAndIdHiddenInputs()  | 
                                                        |
| 168 | - . EEH_HTML::trx();  | 
                                                        |
| 169 | - }  | 
                                                        |
| 170 | -        if ($filtered_row_content !== false) { | 
                                                        |
| 171 | - return $ticket_selector_row_html  | 
                                                        |
| 172 | - . $filtered_row_content  | 
                                                        |
| 173 | - . EEH_HTML::trx();  | 
                                                        |
| 174 | - }  | 
                                                        |
| 175 | - $this->hidden_input_qty = $this->max_attendees > 1;  | 
                                                        |
| 176 | -  | 
                                                        |
| 177 | - $ticket_selector_row_html .= $this->ticketNameTableCell();  | 
                                                        |
| 178 | - $ticket_selector_row_html .= $this->ticketPriceTableCell();  | 
                                                        |
| 179 | -        $ticket_selector_row_html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); | 
                                                        |
| 180 | - $this->setTicketStatusDisplay($remaining);  | 
                                                        |
| 181 | -        if (empty($this->ticket_status_display)) { | 
                                                        |
| 182 | -            if ($this->max_attendees === 1) { | 
                                                        |
| 183 | - // only ONE attendee is allowed to register at a time  | 
                                                        |
| 184 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();  | 
                                                        |
| 185 | -            } elseif ($this->max > 0) { | 
                                                        |
| 186 | - $ticket_selector_row_html .= $this->ticketQuantitySelector();  | 
                                                        |
| 187 | - }  | 
                                                        |
| 188 | - }  | 
                                                        |
| 189 | - $ticket_selector_row_html .= $this->ticket_status_display;  | 
                                                        |
| 190 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();  | 
                                                        |
| 191 | - $ticket_selector_row_html .= $this->ticket_details->display(  | 
                                                        |
| 192 | - $this->ticket_price,  | 
                                                        |
| 193 | - $remaining,  | 
                                                        |
| 194 | - $this->cols  | 
                                                        |
| 195 | - );  | 
                                                        |
| 196 | - $ticket_selector_row_html .= EEH_HTML::tdx();  | 
                                                        |
| 197 | - $ticket_selector_row_html .= EEH_HTML::trx();  | 
                                                        |
| 198 | -  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | - $this->row++;  | 
                                                        |
| 201 | - return $ticket_selector_row_html;  | 
                                                        |
| 202 | - }  | 
                                                        |
| 203 | -  | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | -  | 
                                                        |
| 206 | -  | 
                                                        |
| 207 | - /**  | 
                                                        |
| 208 | - * getTicketPriceDetails  | 
                                                        |
| 209 | - *  | 
                                                        |
| 210 | - * @return void  | 
                                                        |
| 211 | - * @throws EE_Error  | 
                                                        |
| 212 | - */  | 
                                                        |
| 213 | - protected function setTicketPriceDetails()  | 
                                                        |
| 214 | -    { | 
                                                        |
| 215 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes  | 
                                                        |
| 216 | - ? $this->ticket->get_ticket_total_with_taxes()  | 
                                                        |
| 217 | - : $this->ticket->get_ticket_subtotal();  | 
                                                        |
| 218 | - $this->ticket_bundle = false;  | 
                                                        |
| 219 | - $ticket_min = $this->ticket->min();  | 
                                                        |
| 220 | - // for ticket bundles, set min and max qty the same  | 
                                                        |
| 221 | -        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { | 
                                                        |
| 222 | - $this->ticket_price *= $ticket_min;  | 
                                                        |
| 223 | - $this->ticket_bundle = true;  | 
                                                        |
| 224 | - }  | 
                                                        |
| 225 | - $this->ticket_price = apply_filters(  | 
                                                        |
| 226 | - 'FHEE__ticket_selector_chart_template__ticket_price',  | 
                                                        |
| 227 | - $this->ticket_price,  | 
                                                        |
| 228 | - $this->ticket  | 
                                                        |
| 229 | - );  | 
                                                        |
| 230 | - }  | 
                                                        |
| 231 | -  | 
                                                        |
| 232 | -  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | - /**  | 
                                                        |
| 236 | - * ticketNameTableCell  | 
                                                        |
| 237 | - *  | 
                                                        |
| 238 | - * @return string  | 
                                                        |
| 239 | - * @throws EE_Error  | 
                                                        |
| 240 | - */  | 
                                                        |
| 241 | - protected function ticketNameTableCell()  | 
                                                        |
| 242 | -    { | 
                                                        |
| 243 | -        $html = EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); | 
                                                        |
| 244 | -        $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); | 
                                                        |
| 245 | - $html .= $this->ticket_details->getShowHideLinks();  | 
                                                        |
| 246 | -        if ($this->ticket->required()) { | 
                                                        |
| 247 | - $html .= EEH_HTML::p(  | 
                                                        |
| 248 | - apply_filters(  | 
                                                        |
| 249 | - 'FHEE__ticket_selector_chart_template__ticket_required_message',  | 
                                                        |
| 250 | -                        esc_html__('This ticket is required and must be purchased.', 'event_espresso') | 
                                                        |
| 251 | - ),  | 
                                                        |
| 252 | - '', 'ticket-required-pg'  | 
                                                        |
| 253 | - );  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | - $html .= EEH_HTML::tdx();  | 
                                                        |
| 256 | - return $html;  | 
                                                        |
| 257 | - }  | 
                                                        |
| 258 | -  | 
                                                        |
| 259 | -  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | - /**  | 
                                                        |
| 262 | - * ticketPriceTableCell  | 
                                                        |
| 263 | - *  | 
                                                        |
| 264 | - * @return string  | 
                                                        |
| 265 | - * @throws EE_Error  | 
                                                        |
| 266 | - */  | 
                                                        |
| 267 | - protected function ticketPriceTableCell()  | 
                                                        |
| 268 | -    { | 
                                                        |
| 269 | - $html = '';  | 
                                                        |
| 270 | -        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { | 
                                                        |
| 271 | -            $html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); | 
                                                        |
| 272 | - $html .= \EEH_Template::format_currency($this->ticket_price);  | 
                                                        |
| 273 | - $html .= $this->ticket->taxable()  | 
                                                        |
| 274 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )  | 
                                                        |
| 275 | - : '';  | 
                                                        |
| 276 | - $html .= ' ';  | 
                                                        |
| 277 | - $html .= EEH_HTML::span(  | 
                                                        |
| 278 | - $this->ticket_bundle  | 
                                                        |
| 279 | - ? apply_filters(  | 
                                                        |
| 280 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',  | 
                                                        |
| 281 | -                        __(' / bundle', 'event_espresso') | 
                                                        |
| 282 | - )  | 
                                                        |
| 283 | - : apply_filters(  | 
                                                        |
| 284 | - 'FHEE__ticket_selector_chart_template__per_ticket_text',  | 
                                                        |
| 285 | -                        __('', 'event_espresso') | 
                                                        |
| 286 | - ),  | 
                                                        |
| 287 | - '', 'smaller-text no-bold'  | 
                                                        |
| 288 | - );  | 
                                                        |
| 289 | - $html .= ' ';  | 
                                                        |
| 290 | - $html .= EEH_HTML::tdx();  | 
                                                        |
| 291 | - $this->cols++;  | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | - return $html;  | 
                                                        |
| 294 | - }  | 
                                                        |
| 295 | -  | 
                                                        |
| 296 | -  | 
                                                        |
| 297 | -  | 
                                                        |
| 298 | - /**  | 
                                                        |
| 299 | - * onlyOneAttendeeCanRegister  | 
                                                        |
| 300 | - *  | 
                                                        |
| 301 | - * @return string  | 
                                                        |
| 302 | - */  | 
                                                        |
| 303 | - protected function onlyOneAttendeeCanRegister()  | 
                                                        |
| 304 | -    { | 
                                                        |
| 305 | - // display submit button since we have tickets available  | 
                                                        |
| 306 | -        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 307 | - $this->hidden_input_qty = false;  | 
                                                        |
| 308 | - $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';  | 
                                                        |
| 309 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 310 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';  | 
                                                        |
| 311 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';  | 
                                                        |
| 312 | - $html .= ' title=""/>';  | 
                                                        |
| 313 | - return $html;  | 
                                                        |
| 314 | - }  | 
                                                        |
| 315 | -  | 
                                                        |
| 316 | -  | 
                                                        |
| 317 | -  | 
                                                        |
| 318 | - /**  | 
                                                        |
| 319 | - * ticketQuantitySelector  | 
                                                        |
| 320 | - *  | 
                                                        |
| 321 | - * @return string  | 
                                                        |
| 322 | - * @throws EE_Error  | 
                                                        |
| 323 | - */  | 
                                                        |
| 324 | - protected function ticketQuantitySelector()  | 
                                                        |
| 325 | -    { | 
                                                        |
| 326 | - // display submit button since we have tickets available  | 
                                                        |
| 327 | -        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 328 | - $this->hidden_input_qty = false;  | 
                                                        |
| 329 | - $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 330 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 331 | - $html .= ' class="ticket-selector-tbl-qty-slct">';  | 
                                                        |
| 332 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased  | 
                                                        |
| 333 | -        if ($this->min !== 0 && ! $this->ticket->required()) { | 
                                                        |
| 334 | - $html .= '<option value="0"> 0 </option>';  | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | - // offer ticket quantities from the min to the max  | 
                                                        |
| 337 | -        for ($i = $this->min; $i <= $this->max; $i++) { | 
                                                        |
| 338 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>';  | 
                                                        |
| 339 | - }  | 
                                                        |
| 340 | - $html .= '</select>';  | 
                                                        |
| 341 | - return $html;  | 
                                                        |
| 342 | - }  | 
                                                        |
| 343 | -  | 
                                                        |
| 344 | -  | 
                                                        |
| 345 | -  | 
                                                        |
| 346 | - /**  | 
                                                        |
| 347 | - * getHiddenInputs  | 
                                                        |
| 348 | - *  | 
                                                        |
| 349 | - * @return string  | 
                                                        |
| 350 | - * @throws EE_Error  | 
                                                        |
| 351 | - */  | 
                                                        |
| 352 | - protected function ticketQtyAndIdHiddenInputs()  | 
                                                        |
| 353 | -    { | 
                                                        |
| 354 | - $html = '';  | 
                                                        |
| 355 | - // depending on group reg we need to change the format for qty  | 
                                                        |
| 356 | -        if ($this->hidden_input_qty) { | 
                                                        |
| 357 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';  | 
                                                        |
| 358 | - }  | 
                                                        |
| 359 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 360 | - $html .= ' value="' . $this->ticket->ID() . '"/>';  | 
                                                        |
| 361 | - return $html;  | 
                                                        |
| 362 | - }  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * @var TicketDetails $ticket_details  | 
                                                        |
| 26 | + */  | 
                                                        |
| 27 | + protected $ticket_details;  | 
                                                        |
| 28 | +  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + * @var \EE_Ticket_Selector_Config $template_settings  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + protected $template_settings;  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * @var EE_Tax_Config $tax_settings  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + protected $tax_settings;  | 
                                                        |
| 38 | +  | 
                                                        |
| 39 | + /**  | 
                                                        |
| 40 | + * @var boolean $prices_displayed_including_taxes  | 
                                                        |
| 41 | + */  | 
                                                        |
| 42 | + protected $prices_displayed_including_taxes;  | 
                                                        |
| 43 | +  | 
                                                        |
| 44 | + /**  | 
                                                        |
| 45 | + * @var int $row  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected $row;  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | + /**  | 
                                                        |
| 50 | + * @var int $cols  | 
                                                        |
| 51 | + */  | 
                                                        |
| 52 | + protected $cols;  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * @var boolean $hidden_input_qty  | 
                                                        |
| 56 | + */  | 
                                                        |
| 57 | + protected $hidden_input_qty;  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + /**  | 
                                                        |
| 60 | + * @var string $ticket_datetime_classes  | 
                                                        |
| 61 | + */  | 
                                                        |
| 62 | + protected $ticket_datetime_classes;  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * TicketDetails constructor.  | 
                                                        |
| 68 | + *  | 
                                                        |
| 69 | + * @param TicketDetails $ticket_details  | 
                                                        |
| 70 | + * @param EE_Tax_Config $tax_settings  | 
                                                        |
| 71 | + * @param int $total_tickets  | 
                                                        |
| 72 | + * @param int $max_attendees  | 
                                                        |
| 73 | + * @param int $row  | 
                                                        |
| 74 | + * @param int $cols  | 
                                                        |
| 75 | + * @param boolean $required_ticket_sold_out  | 
                                                        |
| 76 | + * @param string $event_status  | 
                                                        |
| 77 | + * @param string $ticket_datetime_classes  | 
                                                        |
| 78 | + * @throws EE_Error  | 
                                                        |
| 79 | + * @throws UnexpectedEntityException  | 
                                                        |
| 80 | + */  | 
                                                        |
| 81 | + public function __construct(  | 
                                                        |
| 82 | + TicketDetails $ticket_details,  | 
                                                        |
| 83 | + EE_Tax_Config $tax_settings,  | 
                                                        |
| 84 | + $total_tickets,  | 
                                                        |
| 85 | + $max_attendees,  | 
                                                        |
| 86 | + $row,  | 
                                                        |
| 87 | + $cols,  | 
                                                        |
| 88 | + $required_ticket_sold_out,  | 
                                                        |
| 89 | + $event_status,  | 
                                                        |
| 90 | + $ticket_datetime_classes  | 
                                                        |
| 91 | +	) { | 
                                                        |
| 92 | + $this->ticket_details = $ticket_details;  | 
                                                        |
| 93 | + $this->template_settings = $ticket_details->getTemplateSettings();  | 
                                                        |
| 94 | + $this->tax_settings = $tax_settings;  | 
                                                        |
| 95 | + $this->row = $row;  | 
                                                        |
| 96 | + $this->cols = $cols;  | 
                                                        |
| 97 | + $this->ticket_datetime_classes = $ticket_datetime_classes;  | 
                                                        |
| 98 | + parent::__construct(  | 
                                                        |
| 99 | + $ticket_details->getTicket(),  | 
                                                        |
| 100 | + $max_attendees,  | 
                                                        |
| 101 | + $ticket_details->getDateFormat(),  | 
                                                        |
| 102 | + $event_status,  | 
                                                        |
| 103 | + $required_ticket_sold_out,  | 
                                                        |
| 104 | + $total_tickets  | 
                                                        |
| 105 | + );  | 
                                                        |
| 106 | + }  | 
                                                        |
| 107 | +  | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * other ticket rows will need to know if a required ticket is sold out,  | 
                                                        |
| 112 | + * so that they are not offered for sale  | 
                                                        |
| 113 | + *  | 
                                                        |
| 114 | + * @return boolean  | 
                                                        |
| 115 | + */  | 
                                                        |
| 116 | + public function getRequiredTicketSoldOut()  | 
                                                        |
| 117 | +	{ | 
                                                        |
| 118 | + return $this->required_ticket_sold_out;  | 
                                                        |
| 119 | + }  | 
                                                        |
| 120 | +  | 
                                                        |
| 121 | +  | 
                                                        |
| 122 | +  | 
                                                        |
| 123 | + /**  | 
                                                        |
| 124 | + * @return int  | 
                                                        |
| 125 | + */  | 
                                                        |
| 126 | + public function getCols()  | 
                                                        |
| 127 | +	{ | 
                                                        |
| 128 | + return $this->cols;  | 
                                                        |
| 129 | + }  | 
                                                        |
| 130 | +  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + /**  | 
                                                        |
| 134 | + * getHtml  | 
                                                        |
| 135 | + *  | 
                                                        |
| 136 | + * @return string  | 
                                                        |
| 137 | + * @throws EE_Error  | 
                                                        |
| 138 | + */  | 
                                                        |
| 139 | + public function getHtml()  | 
                                                        |
| 140 | +	{ | 
                                                        |
| 141 | + $this->min = 0;  | 
                                                        |
| 142 | + $this->max = $this->ticket->max();  | 
                                                        |
| 143 | + $remaining = $this->ticket->remaining();  | 
                                                        |
| 144 | +		if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { | 
                                                        |
| 145 | + $this->setTicketMinAndMax($remaining);  | 
                                                        |
| 146 | +		} else { | 
                                                        |
| 147 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)  | 
                                                        |
| 148 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining  | 
                                                        |
| 149 | + ? $this->ticket->start_date()  | 
                                                        |
| 150 | + : $this->required_ticket_sold_out;  | 
                                                        |
| 151 | + }  | 
                                                        |
| 152 | + $this->setTicketPriceDetails();  | 
                                                        |
| 153 | + $this->setTicketStatusClasses($remaining);  | 
                                                        |
| 154 | + $filtered_row_html = $this->getFilteredRowHtml();  | 
                                                        |
| 155 | +		if ($filtered_row_html !== false) { | 
                                                        |
| 156 | + return $filtered_row_html;  | 
                                                        |
| 157 | + }  | 
                                                        |
| 158 | + $ticket_selector_row_html = EEH_HTML::tr(  | 
                                                        |
| 159 | + '', '',  | 
                                                        |
| 160 | +			"tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " | 
                                                        |
| 161 | + . espresso_get_object_css_class($this->ticket)  | 
                                                        |
| 162 | + );  | 
                                                        |
| 163 | + $filtered_row_content = $this->getFilteredRowContents();  | 
                                                        |
| 164 | +		if ($filtered_row_content !== false && $this->max_attendees === 1) { | 
                                                        |
| 165 | + return $ticket_selector_row_html  | 
                                                        |
| 166 | + . $filtered_row_content  | 
                                                        |
| 167 | + . $this->ticketQtyAndIdHiddenInputs()  | 
                                                        |
| 168 | + . EEH_HTML::trx();  | 
                                                        |
| 169 | + }  | 
                                                        |
| 170 | +		if ($filtered_row_content !== false) { | 
                                                        |
| 171 | + return $ticket_selector_row_html  | 
                                                        |
| 172 | + . $filtered_row_content  | 
                                                        |
| 173 | + . EEH_HTML::trx();  | 
                                                        |
| 174 | + }  | 
                                                        |
| 175 | + $this->hidden_input_qty = $this->max_attendees > 1;  | 
                                                        |
| 176 | +  | 
                                                        |
| 177 | + $ticket_selector_row_html .= $this->ticketNameTableCell();  | 
                                                        |
| 178 | + $ticket_selector_row_html .= $this->ticketPriceTableCell();  | 
                                                        |
| 179 | +		$ticket_selector_row_html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); | 
                                                        |
| 180 | + $this->setTicketStatusDisplay($remaining);  | 
                                                        |
| 181 | +		if (empty($this->ticket_status_display)) { | 
                                                        |
| 182 | +			if ($this->max_attendees === 1) { | 
                                                        |
| 183 | + // only ONE attendee is allowed to register at a time  | 
                                                        |
| 184 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();  | 
                                                        |
| 185 | +			} elseif ($this->max > 0) { | 
                                                        |
| 186 | + $ticket_selector_row_html .= $this->ticketQuantitySelector();  | 
                                                        |
| 187 | + }  | 
                                                        |
| 188 | + }  | 
                                                        |
| 189 | + $ticket_selector_row_html .= $this->ticket_status_display;  | 
                                                        |
| 190 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();  | 
                                                        |
| 191 | + $ticket_selector_row_html .= $this->ticket_details->display(  | 
                                                        |
| 192 | + $this->ticket_price,  | 
                                                        |
| 193 | + $remaining,  | 
                                                        |
| 194 | + $this->cols  | 
                                                        |
| 195 | + );  | 
                                                        |
| 196 | + $ticket_selector_row_html .= EEH_HTML::tdx();  | 
                                                        |
| 197 | + $ticket_selector_row_html .= EEH_HTML::trx();  | 
                                                        |
| 198 | +  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | + $this->row++;  | 
                                                        |
| 201 | + return $ticket_selector_row_html;  | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | +  | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | +  | 
                                                        |
| 206 | +  | 
                                                        |
| 207 | + /**  | 
                                                        |
| 208 | + * getTicketPriceDetails  | 
                                                        |
| 209 | + *  | 
                                                        |
| 210 | + * @return void  | 
                                                        |
| 211 | + * @throws EE_Error  | 
                                                        |
| 212 | + */  | 
                                                        |
| 213 | + protected function setTicketPriceDetails()  | 
                                                        |
| 214 | +	{ | 
                                                        |
| 215 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes  | 
                                                        |
| 216 | + ? $this->ticket->get_ticket_total_with_taxes()  | 
                                                        |
| 217 | + : $this->ticket->get_ticket_subtotal();  | 
                                                        |
| 218 | + $this->ticket_bundle = false;  | 
                                                        |
| 219 | + $ticket_min = $this->ticket->min();  | 
                                                        |
| 220 | + // for ticket bundles, set min and max qty the same  | 
                                                        |
| 221 | +		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { | 
                                                        |
| 222 | + $this->ticket_price *= $ticket_min;  | 
                                                        |
| 223 | + $this->ticket_bundle = true;  | 
                                                        |
| 224 | + }  | 
                                                        |
| 225 | + $this->ticket_price = apply_filters(  | 
                                                        |
| 226 | + 'FHEE__ticket_selector_chart_template__ticket_price',  | 
                                                        |
| 227 | + $this->ticket_price,  | 
                                                        |
| 228 | + $this->ticket  | 
                                                        |
| 229 | + );  | 
                                                        |
| 230 | + }  | 
                                                        |
| 231 | +  | 
                                                        |
| 232 | +  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | + /**  | 
                                                        |
| 236 | + * ticketNameTableCell  | 
                                                        |
| 237 | + *  | 
                                                        |
| 238 | + * @return string  | 
                                                        |
| 239 | + * @throws EE_Error  | 
                                                        |
| 240 | + */  | 
                                                        |
| 241 | + protected function ticketNameTableCell()  | 
                                                        |
| 242 | +	{ | 
                                                        |
| 243 | +		$html = EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); | 
                                                        |
| 244 | +		$html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); | 
                                                        |
| 245 | + $html .= $this->ticket_details->getShowHideLinks();  | 
                                                        |
| 246 | +		if ($this->ticket->required()) { | 
                                                        |
| 247 | + $html .= EEH_HTML::p(  | 
                                                        |
| 248 | + apply_filters(  | 
                                                        |
| 249 | + 'FHEE__ticket_selector_chart_template__ticket_required_message',  | 
                                                        |
| 250 | +						esc_html__('This ticket is required and must be purchased.', 'event_espresso') | 
                                                        |
| 251 | + ),  | 
                                                        |
| 252 | + '', 'ticket-required-pg'  | 
                                                        |
| 253 | + );  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | + $html .= EEH_HTML::tdx();  | 
                                                        |
| 256 | + return $html;  | 
                                                        |
| 257 | + }  | 
                                                        |
| 258 | +  | 
                                                        |
| 259 | +  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | + /**  | 
                                                        |
| 262 | + * ticketPriceTableCell  | 
                                                        |
| 263 | + *  | 
                                                        |
| 264 | + * @return string  | 
                                                        |
| 265 | + * @throws EE_Error  | 
                                                        |
| 266 | + */  | 
                                                        |
| 267 | + protected function ticketPriceTableCell()  | 
                                                        |
| 268 | +	{ | 
                                                        |
| 269 | + $html = '';  | 
                                                        |
| 270 | +		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { | 
                                                        |
| 271 | +			$html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); | 
                                                        |
| 272 | + $html .= \EEH_Template::format_currency($this->ticket_price);  | 
                                                        |
| 273 | + $html .= $this->ticket->taxable()  | 
                                                        |
| 274 | + ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )  | 
                                                        |
| 275 | + : '';  | 
                                                        |
| 276 | + $html .= ' ';  | 
                                                        |
| 277 | + $html .= EEH_HTML::span(  | 
                                                        |
| 278 | + $this->ticket_bundle  | 
                                                        |
| 279 | + ? apply_filters(  | 
                                                        |
| 280 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',  | 
                                                        |
| 281 | +						__(' / bundle', 'event_espresso') | 
                                                        |
| 282 | + )  | 
                                                        |
| 283 | + : apply_filters(  | 
                                                        |
| 284 | + 'FHEE__ticket_selector_chart_template__per_ticket_text',  | 
                                                        |
| 285 | +						__('', 'event_espresso') | 
                                                        |
| 286 | + ),  | 
                                                        |
| 287 | + '', 'smaller-text no-bold'  | 
                                                        |
| 288 | + );  | 
                                                        |
| 289 | + $html .= ' ';  | 
                                                        |
| 290 | + $html .= EEH_HTML::tdx();  | 
                                                        |
| 291 | + $this->cols++;  | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | + return $html;  | 
                                                        |
| 294 | + }  | 
                                                        |
| 295 | +  | 
                                                        |
| 296 | +  | 
                                                        |
| 297 | +  | 
                                                        |
| 298 | + /**  | 
                                                        |
| 299 | + * onlyOneAttendeeCanRegister  | 
                                                        |
| 300 | + *  | 
                                                        |
| 301 | + * @return string  | 
                                                        |
| 302 | + */  | 
                                                        |
| 303 | + protected function onlyOneAttendeeCanRegister()  | 
                                                        |
| 304 | +	{ | 
                                                        |
| 305 | + // display submit button since we have tickets available  | 
                                                        |
| 306 | +		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 307 | + $this->hidden_input_qty = false;  | 
                                                        |
| 308 | + $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';  | 
                                                        |
| 309 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 310 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';  | 
                                                        |
| 311 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';  | 
                                                        |
| 312 | + $html .= ' title=""/>';  | 
                                                        |
| 313 | + return $html;  | 
                                                        |
| 314 | + }  | 
                                                        |
| 315 | +  | 
                                                        |
| 316 | +  | 
                                                        |
| 317 | +  | 
                                                        |
| 318 | + /**  | 
                                                        |
| 319 | + * ticketQuantitySelector  | 
                                                        |
| 320 | + *  | 
                                                        |
| 321 | + * @return string  | 
                                                        |
| 322 | + * @throws EE_Error  | 
                                                        |
| 323 | + */  | 
                                                        |
| 324 | + protected function ticketQuantitySelector()  | 
                                                        |
| 325 | +	{ | 
                                                        |
| 326 | + // display submit button since we have tickets available  | 
                                                        |
| 327 | +		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 328 | + $this->hidden_input_qty = false;  | 
                                                        |
| 329 | + $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 330 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 331 | + $html .= ' class="ticket-selector-tbl-qty-slct">';  | 
                                                        |
| 332 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased  | 
                                                        |
| 333 | +		if ($this->min !== 0 && ! $this->ticket->required()) { | 
                                                        |
| 334 | + $html .= '<option value="0"> 0 </option>';  | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | + // offer ticket quantities from the min to the max  | 
                                                        |
| 337 | +		for ($i = $this->min; $i <= $this->max; $i++) { | 
                                                        |
| 338 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>';  | 
                                                        |
| 339 | + }  | 
                                                        |
| 340 | + $html .= '</select>';  | 
                                                        |
| 341 | + return $html;  | 
                                                        |
| 342 | + }  | 
                                                        |
| 343 | +  | 
                                                        |
| 344 | +  | 
                                                        |
| 345 | +  | 
                                                        |
| 346 | + /**  | 
                                                        |
| 347 | + * getHiddenInputs  | 
                                                        |
| 348 | + *  | 
                                                        |
| 349 | + * @return string  | 
                                                        |
| 350 | + * @throws EE_Error  | 
                                                        |
| 351 | + */  | 
                                                        |
| 352 | + protected function ticketQtyAndIdHiddenInputs()  | 
                                                        |
| 353 | +	{ | 
                                                        |
| 354 | + $html = '';  | 
                                                        |
| 355 | + // depending on group reg we need to change the format for qty  | 
                                                        |
| 356 | +		if ($this->hidden_input_qty) { | 
                                                        |
| 357 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';  | 
                                                        |
| 358 | + }  | 
                                                        |
| 359 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 360 | + $html .= ' value="' . $this->ticket->ID() . '"/>';  | 
                                                        |
| 361 | + return $html;  | 
                                                        |
| 362 | + }  | 
                                                        |
| 363 | 363 | |
| 364 | 364 | }  | 
                                                        
| 365 | 365 | // End of file TicketSelectorRowStandard.php  | 
                                                        
@@ -271,7 +271,7 @@ discard block  | 
                                                    ||
| 271 | 271 |              $html .= EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); | 
                                                        
| 272 | 272 | $html .= \EEH_Template::format_currency($this->ticket_price);  | 
                                                        
| 273 | 273 | $html .= $this->ticket->taxable()  | 
                                                        
| 274 | - ? EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' )  | 
                                                        |
| 274 | +                ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') | 
                                                        |
| 275 | 275 | : '';  | 
                                                        
| 276 | 276 | $html .= ' ';  | 
                                                        
| 277 | 277 | $html .= EEH_HTML::span(  | 
                                                        
@@ -305,9 +305,9 @@ discard block  | 
                                                    ||
| 305 | 305 | // display submit button since we have tickets available  | 
                                                        
| 306 | 306 |          add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        
| 307 | 307 | $this->hidden_input_qty = false;  | 
                                                        
| 308 | - $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"';  | 
                                                        |
| 309 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 310 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"';  | 
                                                        |
| 308 | + $html = '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"';  | 
                                                        |
| 309 | + $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"';  | 
                                                        |
| 310 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"';  | 
                                                        |
| 311 | 311 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : '';  | 
                                                        
| 312 | 312 | $html .= ' title=""/>';  | 
                                                        
| 313 | 313 | return $html;  | 
                                                        
@@ -326,8 +326,8 @@ discard block  | 
                                                    ||
| 326 | 326 | // display submit button since we have tickets available  | 
                                                        
| 327 | 327 |          add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        
| 328 | 328 | $this->hidden_input_qty = false;  | 
                                                        
| 329 | - $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 330 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"';  | 
                                                        |
| 329 | + $html = '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"';  | 
                                                        |
| 330 | + $html .= ' id="ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row.'"';  | 
                                                        |
| 331 | 331 | $html .= ' class="ticket-selector-tbl-qty-slct">';  | 
                                                        
| 332 | 332 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased  | 
                                                        
| 333 | 333 |          if ($this->min !== 0 && ! $this->ticket->required()) { | 
                                                        
@@ -335,7 +335,7 @@ discard block  | 
                                                    ||
| 335 | 335 | }  | 
                                                        
| 336 | 336 | // offer ticket quantities from the min to the max  | 
                                                        
| 337 | 337 |          for ($i = $this->min; $i <= $this->max; $i++) { | 
                                                        
| 338 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>';  | 
                                                        |
| 338 | + $html .= '<option value="'.$i.'"> '.$i.' </option>';  | 
                                                        |
| 339 | 339 | }  | 
                                                        
| 340 | 340 | $html .= '</select>';  | 
                                                        
| 341 | 341 | return $html;  | 
                                                        
@@ -354,10 +354,10 @@ discard block  | 
                                                    ||
| 354 | 354 | $html = '';  | 
                                                        
| 355 | 355 | // depending on group reg we need to change the format for qty  | 
                                                        
| 356 | 356 |          if ($this->hidden_input_qty) { | 
                                                        
| 357 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>';  | 
                                                        |
| 357 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>';  | 
                                                        |
| 358 | 358 | }  | 
                                                        
| 359 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"';  | 
                                                        |
| 360 | - $html .= ' value="' . $this->ticket->ID() . '"/>';  | 
                                                        |
| 359 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"';  | 
                                                        |
| 360 | + $html .= ' value="'.$this->ticket->ID().'"/>';  | 
                                                        |
| 361 | 361 | return $html;  | 
                                                        
| 362 | 362 | }  | 
                                                        
| 363 | 363 | |
@@ -22,370 +22,370 @@  | 
                                                    ||
| 22 | 22 | abstract class TicketSelectorRow  | 
                                                        
| 23 | 23 |  { | 
                                                        
| 24 | 24 | |
| 25 | - /**  | 
                                                        |
| 26 | - * @var EE_Ticket $ticket  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - protected $ticket;  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - /**  | 
                                                        |
| 31 | - * @var int $total_tickets  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - protected $total_tickets;  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | - /**  | 
                                                        |
| 36 | - * @var int $max_attendees  | 
                                                        |
| 37 | - */  | 
                                                        |
| 38 | - protected $max_attendees;  | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - /**  | 
                                                        |
| 41 | - * @var string $date_format  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - protected $date_format;  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /**  | 
                                                        |
| 46 | - * @var int $EVT_ID  | 
                                                        |
| 47 | - */  | 
                                                        |
| 48 | - protected $EVT_ID;  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * @var string $event_status  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - protected $event_status;  | 
                                                        |
| 54 | -  | 
                                                        |
| 55 | - /**  | 
                                                        |
| 56 | - * @var boolean $required_ticket_sold_out  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - protected $required_ticket_sold_out;  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | - /**  | 
                                                        |
| 61 | - * @var string $ticket_status_display  | 
                                                        |
| 62 | - */  | 
                                                        |
| 63 | - protected $ticket_status_display;  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - /**  | 
                                                        |
| 66 | - * @var int $max  | 
                                                        |
| 67 | - */  | 
                                                        |
| 68 | - protected $max = 0;  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - /**  | 
                                                        |
| 71 | - * @var int $min  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - protected $min = 0;  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - /**  | 
                                                        |
| 76 | - * @var float $ticket_price  | 
                                                        |
| 77 | - */  | 
                                                        |
| 78 | - protected $ticket_price = 0.00;  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | - /**  | 
                                                        |
| 81 | - * @var bool $ticket_bundle  | 
                                                        |
| 82 | - */  | 
                                                        |
| 83 | - protected $ticket_bundle = false;  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - /**  | 
                                                        |
| 86 | - * @var string $ticket_status_id  | 
                                                        |
| 87 | - */  | 
                                                        |
| 88 | - protected $ticket_status_id = EE_Ticket::sold_out;  | 
                                                        |
| 89 | -  | 
                                                        |
| 90 | - /**  | 
                                                        |
| 91 | - * @var string $ticket_status_html  | 
                                                        |
| 92 | - */  | 
                                                        |
| 93 | - protected $ticket_status_html = 'ticket-sales-sold-out';  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | - /**  | 
                                                        |
| 96 | - * @var string $status_class  | 
                                                        |
| 97 | - */  | 
                                                        |
| 98 | - protected $status_class = 'ticket-sales-sold-out lt-grey-text';  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | -  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - /**  | 
                                                        |
| 103 | - * @param EE_Ticket $ticket  | 
                                                        |
| 104 | - * @param int $max_attendees  | 
                                                        |
| 105 | - * @param string $date_format  | 
                                                        |
| 106 | - * @param string $event_status  | 
                                                        |
| 107 | - * @param bool $required_ticket_sold_out  | 
                                                        |
| 108 | - * @param int $total_tickets  | 
                                                        |
| 109 | - * @throws EE_Error  | 
                                                        |
| 110 | - * @throws UnexpectedEntityException  | 
                                                        |
| 111 | - */  | 
                                                        |
| 112 | - public function __construct(  | 
                                                        |
| 113 | - EE_Ticket $ticket,  | 
                                                        |
| 114 | - $max_attendees,  | 
                                                        |
| 115 | - $date_format,  | 
                                                        |
| 116 | - $event_status,  | 
                                                        |
| 117 | - $required_ticket_sold_out = false,  | 
                                                        |
| 118 | - $total_tickets = 1  | 
                                                        |
| 119 | -    ) { | 
                                                        |
| 120 | - $this->ticket = $ticket;  | 
                                                        |
| 121 | - $this->max_attendees = $max_attendees;  | 
                                                        |
| 122 | - $this->date_format = $date_format;  | 
                                                        |
| 123 | - $this->EVT_ID = $this->ticket->get_event_ID();  | 
                                                        |
| 124 | - $this->event_status = $event_status;  | 
                                                        |
| 125 | - $this->required_ticket_sold_out = $required_ticket_sold_out;  | 
                                                        |
| 126 | - $this->total_tickets = $total_tickets;  | 
                                                        |
| 127 | - }  | 
                                                        |
| 128 | -  | 
                                                        |
| 129 | -  | 
                                                        |
| 130 | -  | 
                                                        |
| 131 | - /**  | 
                                                        |
| 132 | - * getTicketStatusClasses  | 
                                                        |
| 133 | - *  | 
                                                        |
| 134 | - * @param int $remaining  | 
                                                        |
| 135 | - * @return void  | 
                                                        |
| 136 | - * @throws EE_Error  | 
                                                        |
| 137 | - */  | 
                                                        |
| 138 | - protected function setTicketStatusClasses($remaining = 0)  | 
                                                        |
| 139 | -    { | 
                                                        |
| 140 | - // if a previous required ticket with the same sale start date is sold out,  | 
                                                        |
| 141 | - // then mark this ticket as sold out as well.  | 
                                                        |
| 142 | - // tickets that go on sale at a later date than the required ticket will NOT be affected  | 
                                                        |
| 143 | - $this->ticket_status_id = $this->required_ticket_sold_out !== false  | 
                                                        |
| 144 | - && $this->required_ticket_sold_out === $this->ticket->start_date()  | 
                                                        |
| 145 | - ? EE_Ticket::sold_out  | 
                                                        |
| 146 | - : $this->ticket->ticket_status();  | 
                                                        |
| 147 | - $this->ticket_status_id = $this->event_status === EE_Datetime::sold_out  | 
                                                        |
| 148 | - ? EE_Ticket::sold_out  | 
                                                        |
| 149 | - : $this->ticket_status_id;  | 
                                                        |
| 150 | - // check ticket status  | 
                                                        |
| 151 | -        switch ($this->ticket_status_id) { | 
                                                        |
| 152 | - // sold_out  | 
                                                        |
| 153 | - case EE_Ticket::sold_out :  | 
                                                        |
| 154 | - $ticket_status_class = 'ticket-sales-sold-out';  | 
                                                        |
| 155 | - $this->status_class = 'ticket-sales-sold-out lt-grey-text';  | 
                                                        |
| 156 | - break;  | 
                                                        |
| 157 | - // expired  | 
                                                        |
| 158 | - case EE_Ticket::expired :  | 
                                                        |
| 159 | - $ticket_status_class = 'ticket-sales-expired';  | 
                                                        |
| 160 | - $this->status_class = 'ticket-sales-expired lt-grey-text';  | 
                                                        |
| 161 | - break;  | 
                                                        |
| 162 | - // archived  | 
                                                        |
| 163 | - case EE_Ticket::archived :  | 
                                                        |
| 164 | - $ticket_status_class = 'archived-ticket';  | 
                                                        |
| 165 | - $this->status_class = 'archived-ticket hidden';  | 
                                                        |
| 166 | - break;  | 
                                                        |
| 167 | - // pending  | 
                                                        |
| 168 | - case EE_Ticket::pending :  | 
                                                        |
| 169 | - $ticket_status_class = 'ticket-pending';  | 
                                                        |
| 170 | - $this->status_class = 'ticket-pending';  | 
                                                        |
| 171 | - break;  | 
                                                        |
| 172 | - // on sale  | 
                                                        |
| 173 | - case EE_Ticket::onsale :  | 
                                                        |
| 174 | - default :  | 
                                                        |
| 175 | - $ticket_status_class = 'ticket-on-sale';  | 
                                                        |
| 176 | - $this->status_class = 'ticket-on-sale';  | 
                                                        |
| 177 | - break;  | 
                                                        |
| 178 | - }  | 
                                                        |
| 179 | - $this->ticket_status_html = EEH_HTML::span(  | 
                                                        |
| 180 | - $this->ticket->ticket_status(true, ($remaining > 0)),  | 
                                                        |
| 181 | -            "{$ticket_status_class}-{$this->ticket->ID()}", | 
                                                        |
| 182 | - $ticket_status_class  | 
                                                        |
| 183 | - );  | 
                                                        |
| 184 | - }  | 
                                                        |
| 185 | -  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - /**  | 
                                                        |
| 188 | - * @return string  | 
                                                        |
| 189 | - */  | 
                                                        |
| 190 | - public function getTicketStatusDisplay()  | 
                                                        |
| 191 | -    { | 
                                                        |
| 192 | - return $this->ticket_status_display;  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | -  | 
                                                        |
| 196 | -  | 
                                                        |
| 197 | - /**  | 
                                                        |
| 198 | - * setTicketStatusDisplay  | 
                                                        |
| 199 | - *  | 
                                                        |
| 200 | - * @param int $remaining  | 
                                                        |
| 201 | - * @throws EE_Error  | 
                                                        |
| 202 | - */  | 
                                                        |
| 203 | -    protected function setTicketStatusDisplay($remaining) { | 
                                                        |
| 204 | - $this->ticket_status_display = '';  | 
                                                        |
| 205 | - // now depending on the ticket and other circumstances...  | 
                                                        |
| 206 | -        if ($this->max_attendees === 0) { | 
                                                        |
| 207 | - // registration is CLOSED because admin set max attendees to ZERO  | 
                                                        |
| 208 | - $this->ticket_status_display = $this->registrationClosed();  | 
                                                        |
| 209 | -        } elseif ($this->ticket_status_id === EE_Ticket::sold_out || $remaining === 0) { | 
                                                        |
| 210 | - // SOLD OUT - no tickets remaining  | 
                                                        |
| 211 | - $this->ticket_status_display = $this->ticketsSoldOut();  | 
                                                        |
| 212 | -        } elseif ($this->ticket_status_id === EE_Ticket::expired || $this->ticket_status_id === EE_Ticket::archived) { | 
                                                        |
| 213 | - // expired or archived ticket  | 
                                                        |
| 214 | - $this->ticket_status_display = $this->ticket_status_html;  | 
                                                        |
| 215 | -        } elseif ($this->ticket_status_id === EE_Ticket::pending) { | 
                                                        |
| 216 | - // ticket not on sale yet  | 
                                                        |
| 217 | - $this->ticket_status_display = $this->ticketsSalesPending();  | 
                                                        |
| 218 | -        } elseif ($this->ticket->min() > $remaining) { | 
                                                        |
| 219 | - // min qty purchasable is less than tickets available  | 
                                                        |
| 220 | - $this->ticket_status_display = $this->notEnoughTicketsAvailable();  | 
                                                        |
| 221 | - }  | 
                                                        |
| 222 | - }  | 
                                                        |
| 223 | -  | 
                                                        |
| 224 | -  | 
                                                        |
| 225 | -  | 
                                                        |
| 226 | - /**  | 
                                                        |
| 227 | - * registrationClosed  | 
                                                        |
| 228 | - */  | 
                                                        |
| 229 | - protected function registrationClosed()  | 
                                                        |
| 230 | -    { | 
                                                        |
| 231 | - return EEH_HTML::span(  | 
                                                        |
| 232 | - apply_filters(  | 
                                                        |
| 233 | - 'FHEE__ticket_selector_chart_template__ticket_closed_msg',  | 
                                                        |
| 234 | -                __('Closed', 'event_espresso') | 
                                                        |
| 235 | - ),  | 
                                                        |
| 236 | - '', 'sold-out'  | 
                                                        |
| 237 | - );  | 
                                                        |
| 238 | - }  | 
                                                        |
| 239 | -  | 
                                                        |
| 240 | -  | 
                                                        |
| 241 | -  | 
                                                        |
| 242 | - /**  | 
                                                        |
| 243 | - * ticketsSoldOut  | 
                                                        |
| 244 | - */  | 
                                                        |
| 245 | - protected function ticketsSoldOut()  | 
                                                        |
| 246 | -    { | 
                                                        |
| 247 | - return EEH_HTML::span(  | 
                                                        |
| 248 | - apply_filters(  | 
                                                        |
| 249 | - 'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',  | 
                                                        |
| 250 | -                __('Sold Out', 'event_espresso') | 
                                                        |
| 251 | - ),  | 
                                                        |
| 252 | - '', 'sold-out'  | 
                                                        |
| 253 | - );  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | -  | 
                                                        |
| 256 | -  | 
                                                        |
| 257 | -  | 
                                                        |
| 258 | - /**  | 
                                                        |
| 259 | - * ticketsSalesPending  | 
                                                        |
| 260 | - *  | 
                                                        |
| 261 | - * @throws EE_Error  | 
                                                        |
| 262 | - */  | 
                                                        |
| 263 | - protected function ticketsSalesPending()  | 
                                                        |
| 264 | -    { | 
                                                        |
| 265 | - return EEH_HTML::span(  | 
                                                        |
| 266 | - EEH_HTML::span(  | 
                                                        |
| 267 | - apply_filters(  | 
                                                        |
| 268 | - 'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',  | 
                                                        |
| 269 | -                    __('Goes On Sale', 'event_espresso') | 
                                                        |
| 270 | - ),  | 
                                                        |
| 271 | - '', 'ticket-pending'  | 
                                                        |
| 272 | - )  | 
                                                        |
| 273 | - . EEH_HTML::br()  | 
                                                        |
| 274 | - . EEH_HTML::span(  | 
                                                        |
| 275 | - $this->ticket->get_i18n_datetime(  | 
                                                        |
| 276 | - 'TKT_start_date',  | 
                                                        |
| 277 | - apply_filters(  | 
                                                        |
| 278 | - 'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',  | 
                                                        |
| 279 | - $this->date_format  | 
                                                        |
| 280 | - )  | 
                                                        |
| 281 | - ),  | 
                                                        |
| 282 | - '', 'small-text'  | 
                                                        |
| 283 | - ),  | 
                                                        |
| 284 | - '', 'ticket-pending-pg'  | 
                                                        |
| 285 | - );  | 
                                                        |
| 286 | - }  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | -  | 
                                                        |
| 289 | -  | 
                                                        |
| 290 | - /**  | 
                                                        |
| 291 | - * notEnoughTicketsAvailable  | 
                                                        |
| 292 | - */  | 
                                                        |
| 293 | - protected function notEnoughTicketsAvailable()  | 
                                                        |
| 294 | -    { | 
                                                        |
| 295 | - return EEH_HTML::div(  | 
                                                        |
| 296 | - EEH_HTML::span(  | 
                                                        |
| 297 | - apply_filters(  | 
                                                        |
| 298 | - 'FHEE__ticket_selector_chart_template__ticket_not_available_msg',  | 
                                                        |
| 299 | -                    __('Not Available', 'event_espresso') | 
                                                        |
| 300 | - ),  | 
                                                        |
| 301 | - '', 'archived-ticket small-text'  | 
                                                        |
| 302 | - )  | 
                                                        |
| 303 | - . EEH_HTML::br(),  | 
                                                        |
| 304 | - '', 'archived-ticket-pg'  | 
                                                        |
| 305 | - );  | 
                                                        |
| 306 | - }  | 
                                                        |
| 307 | -  | 
                                                        |
| 308 | -  | 
                                                        |
| 309 | -  | 
                                                        |
| 310 | - /**  | 
                                                        |
| 311 | - * setTicketMinAndMax  | 
                                                        |
| 312 | - *  | 
                                                        |
| 313 | - * @param int $remaining  | 
                                                        |
| 314 | - * @return void  | 
                                                        |
| 315 | - * @throws EE_Error  | 
                                                        |
| 316 | - */  | 
                                                        |
| 317 | - protected function setTicketMinAndMax($remaining)  | 
                                                        |
| 318 | -    { | 
                                                        |
| 319 | - // offer the number of $tickets_remaining or $this->max_attendees, whichever is smaller  | 
                                                        |
| 320 | - $this->max = min($remaining, $this->max_attendees);  | 
                                                        |
| 321 | - // but... we also want to restrict the number of tickets by the ticket max setting,  | 
                                                        |
| 322 | - // however, the max still can't be higher than what was just set above  | 
                                                        |
| 323 | - $this->max = $this->ticket->max() > 0  | 
                                                        |
| 324 | - ? min($this->ticket->max(), $this->max)  | 
                                                        |
| 325 | - : $this->max;  | 
                                                        |
| 326 | - // and we also want to restrict the minimum number of tickets by the ticket min setting  | 
                                                        |
| 327 | - $this->min = $this->ticket->min() > 0  | 
                                                        |
| 328 | - ? $this->ticket->min()  | 
                                                        |
| 329 | - : 0;  | 
                                                        |
| 330 | - // and if the ticket is required, then make sure that min qty is at least 1  | 
                                                        |
| 331 | - $this->min = $this->ticket->required()  | 
                                                        |
| 332 | - ? max($this->min, 1)  | 
                                                        |
| 333 | - : $this->min;  | 
                                                        |
| 334 | - }  | 
                                                        |
| 335 | -  | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | - /**  | 
                                                        |
| 338 | - * Allow plugins to hook in and abort the generation and display of this row to do  | 
                                                        |
| 339 | - * something elseif they want.  | 
                                                        |
| 340 | - * For an addon to abort things, all they have to do is register a filter with this hook, and  | 
                                                        |
| 341 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the  | 
                                                        |
| 342 | - * current row.  | 
                                                        |
| 343 | - *  | 
                                                        |
| 344 | - * @return string|bool  | 
                                                        |
| 345 | - */  | 
                                                        |
| 346 | -    protected function getFilteredRowHtml() { | 
                                                        |
| 347 | - return apply_filters(  | 
                                                        |
| 348 | - 'FHEE__ticket_selector_chart_template__do_ticket_entire_row',  | 
                                                        |
| 349 | - false,  | 
                                                        |
| 350 | - $this->ticket,  | 
                                                        |
| 351 | - $this->max,  | 
                                                        |
| 352 | - $this->min,  | 
                                                        |
| 353 | - $this->required_ticket_sold_out,  | 
                                                        |
| 354 | - $this->ticket_price,  | 
                                                        |
| 355 | - $this->ticket_bundle,  | 
                                                        |
| 356 | - $this->ticket_status_html,  | 
                                                        |
| 357 | - $this->status_class,  | 
                                                        |
| 358 | - $this  | 
                                                        |
| 359 | - );  | 
                                                        |
| 360 | - }  | 
                                                        |
| 361 | -  | 
                                                        |
| 362 | -  | 
                                                        |
| 363 | -  | 
                                                        |
| 364 | - /**  | 
                                                        |
| 365 | - * Allow plugins to hook in and abort the generation and display of the contents of this  | 
                                                        |
| 366 | - * row to do something elseif they want.  | 
                                                        |
| 367 | - * For an addon to abort things, all they have to do is register a filter with this hook, and  | 
                                                        |
| 368 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the  | 
                                                        |
| 369 | - * current row.  | 
                                                        |
| 370 | - *  | 
                                                        |
| 371 | - * @return string|bool  | 
                                                        |
| 372 | - */  | 
                                                        |
| 373 | - protected function getFilteredRowContents()  | 
                                                        |
| 374 | -    { | 
                                                        |
| 375 | - return apply_filters(  | 
                                                        |
| 376 | - 'FHEE__ticket_selector_chart_template__do_ticket_inside_row',  | 
                                                        |
| 377 | - false,  | 
                                                        |
| 378 | - $this->ticket,  | 
                                                        |
| 379 | - $this->max,  | 
                                                        |
| 380 | - $this->min,  | 
                                                        |
| 381 | - $this->required_ticket_sold_out,  | 
                                                        |
| 382 | - $this->ticket_price,  | 
                                                        |
| 383 | - $this->ticket_bundle,  | 
                                                        |
| 384 | - $this->ticket_status_html,  | 
                                                        |
| 385 | - $this->status_class,  | 
                                                        |
| 386 | - $this  | 
                                                        |
| 387 | - );  | 
                                                        |
| 388 | - }  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @var EE_Ticket $ticket  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + protected $ticket;  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * @var int $total_tickets  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + protected $total_tickets;  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | + /**  | 
                                                        |
| 36 | + * @var int $max_attendees  | 
                                                        |
| 37 | + */  | 
                                                        |
| 38 | + protected $max_attendees;  | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * @var string $date_format  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + protected $date_format;  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /**  | 
                                                        |
| 46 | + * @var int $EVT_ID  | 
                                                        |
| 47 | + */  | 
                                                        |
| 48 | + protected $EVT_ID;  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @var string $event_status  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + protected $event_status;  | 
                                                        |
| 54 | +  | 
                                                        |
| 55 | + /**  | 
                                                        |
| 56 | + * @var boolean $required_ticket_sold_out  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + protected $required_ticket_sold_out;  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | + /**  | 
                                                        |
| 61 | + * @var string $ticket_status_display  | 
                                                        |
| 62 | + */  | 
                                                        |
| 63 | + protected $ticket_status_display;  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + /**  | 
                                                        |
| 66 | + * @var int $max  | 
                                                        |
| 67 | + */  | 
                                                        |
| 68 | + protected $max = 0;  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + /**  | 
                                                        |
| 71 | + * @var int $min  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + protected $min = 0;  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * @var float $ticket_price  | 
                                                        |
| 77 | + */  | 
                                                        |
| 78 | + protected $ticket_price = 0.00;  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | + /**  | 
                                                        |
| 81 | + * @var bool $ticket_bundle  | 
                                                        |
| 82 | + */  | 
                                                        |
| 83 | + protected $ticket_bundle = false;  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + /**  | 
                                                        |
| 86 | + * @var string $ticket_status_id  | 
                                                        |
| 87 | + */  | 
                                                        |
| 88 | + protected $ticket_status_id = EE_Ticket::sold_out;  | 
                                                        |
| 89 | +  | 
                                                        |
| 90 | + /**  | 
                                                        |
| 91 | + * @var string $ticket_status_html  | 
                                                        |
| 92 | + */  | 
                                                        |
| 93 | + protected $ticket_status_html = 'ticket-sales-sold-out';  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | + /**  | 
                                                        |
| 96 | + * @var string $status_class  | 
                                                        |
| 97 | + */  | 
                                                        |
| 98 | + protected $status_class = 'ticket-sales-sold-out lt-grey-text';  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | +  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + /**  | 
                                                        |
| 103 | + * @param EE_Ticket $ticket  | 
                                                        |
| 104 | + * @param int $max_attendees  | 
                                                        |
| 105 | + * @param string $date_format  | 
                                                        |
| 106 | + * @param string $event_status  | 
                                                        |
| 107 | + * @param bool $required_ticket_sold_out  | 
                                                        |
| 108 | + * @param int $total_tickets  | 
                                                        |
| 109 | + * @throws EE_Error  | 
                                                        |
| 110 | + * @throws UnexpectedEntityException  | 
                                                        |
| 111 | + */  | 
                                                        |
| 112 | + public function __construct(  | 
                                                        |
| 113 | + EE_Ticket $ticket,  | 
                                                        |
| 114 | + $max_attendees,  | 
                                                        |
| 115 | + $date_format,  | 
                                                        |
| 116 | + $event_status,  | 
                                                        |
| 117 | + $required_ticket_sold_out = false,  | 
                                                        |
| 118 | + $total_tickets = 1  | 
                                                        |
| 119 | +	) { | 
                                                        |
| 120 | + $this->ticket = $ticket;  | 
                                                        |
| 121 | + $this->max_attendees = $max_attendees;  | 
                                                        |
| 122 | + $this->date_format = $date_format;  | 
                                                        |
| 123 | + $this->EVT_ID = $this->ticket->get_event_ID();  | 
                                                        |
| 124 | + $this->event_status = $event_status;  | 
                                                        |
| 125 | + $this->required_ticket_sold_out = $required_ticket_sold_out;  | 
                                                        |
| 126 | + $this->total_tickets = $total_tickets;  | 
                                                        |
| 127 | + }  | 
                                                        |
| 128 | +  | 
                                                        |
| 129 | +  | 
                                                        |
| 130 | +  | 
                                                        |
| 131 | + /**  | 
                                                        |
| 132 | + * getTicketStatusClasses  | 
                                                        |
| 133 | + *  | 
                                                        |
| 134 | + * @param int $remaining  | 
                                                        |
| 135 | + * @return void  | 
                                                        |
| 136 | + * @throws EE_Error  | 
                                                        |
| 137 | + */  | 
                                                        |
| 138 | + protected function setTicketStatusClasses($remaining = 0)  | 
                                                        |
| 139 | +	{ | 
                                                        |
| 140 | + // if a previous required ticket with the same sale start date is sold out,  | 
                                                        |
| 141 | + // then mark this ticket as sold out as well.  | 
                                                        |
| 142 | + // tickets that go on sale at a later date than the required ticket will NOT be affected  | 
                                                        |
| 143 | + $this->ticket_status_id = $this->required_ticket_sold_out !== false  | 
                                                        |
| 144 | + && $this->required_ticket_sold_out === $this->ticket->start_date()  | 
                                                        |
| 145 | + ? EE_Ticket::sold_out  | 
                                                        |
| 146 | + : $this->ticket->ticket_status();  | 
                                                        |
| 147 | + $this->ticket_status_id = $this->event_status === EE_Datetime::sold_out  | 
                                                        |
| 148 | + ? EE_Ticket::sold_out  | 
                                                        |
| 149 | + : $this->ticket_status_id;  | 
                                                        |
| 150 | + // check ticket status  | 
                                                        |
| 151 | +		switch ($this->ticket_status_id) { | 
                                                        |
| 152 | + // sold_out  | 
                                                        |
| 153 | + case EE_Ticket::sold_out :  | 
                                                        |
| 154 | + $ticket_status_class = 'ticket-sales-sold-out';  | 
                                                        |
| 155 | + $this->status_class = 'ticket-sales-sold-out lt-grey-text';  | 
                                                        |
| 156 | + break;  | 
                                                        |
| 157 | + // expired  | 
                                                        |
| 158 | + case EE_Ticket::expired :  | 
                                                        |
| 159 | + $ticket_status_class = 'ticket-sales-expired';  | 
                                                        |
| 160 | + $this->status_class = 'ticket-sales-expired lt-grey-text';  | 
                                                        |
| 161 | + break;  | 
                                                        |
| 162 | + // archived  | 
                                                        |
| 163 | + case EE_Ticket::archived :  | 
                                                        |
| 164 | + $ticket_status_class = 'archived-ticket';  | 
                                                        |
| 165 | + $this->status_class = 'archived-ticket hidden';  | 
                                                        |
| 166 | + break;  | 
                                                        |
| 167 | + // pending  | 
                                                        |
| 168 | + case EE_Ticket::pending :  | 
                                                        |
| 169 | + $ticket_status_class = 'ticket-pending';  | 
                                                        |
| 170 | + $this->status_class = 'ticket-pending';  | 
                                                        |
| 171 | + break;  | 
                                                        |
| 172 | + // on sale  | 
                                                        |
| 173 | + case EE_Ticket::onsale :  | 
                                                        |
| 174 | + default :  | 
                                                        |
| 175 | + $ticket_status_class = 'ticket-on-sale';  | 
                                                        |
| 176 | + $this->status_class = 'ticket-on-sale';  | 
                                                        |
| 177 | + break;  | 
                                                        |
| 178 | + }  | 
                                                        |
| 179 | + $this->ticket_status_html = EEH_HTML::span(  | 
                                                        |
| 180 | + $this->ticket->ticket_status(true, ($remaining > 0)),  | 
                                                        |
| 181 | +			"{$ticket_status_class}-{$this->ticket->ID()}", | 
                                                        |
| 182 | + $ticket_status_class  | 
                                                        |
| 183 | + );  | 
                                                        |
| 184 | + }  | 
                                                        |
| 185 | +  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + /**  | 
                                                        |
| 188 | + * @return string  | 
                                                        |
| 189 | + */  | 
                                                        |
| 190 | + public function getTicketStatusDisplay()  | 
                                                        |
| 191 | +	{ | 
                                                        |
| 192 | + return $this->ticket_status_display;  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | +  | 
                                                        |
| 196 | +  | 
                                                        |
| 197 | + /**  | 
                                                        |
| 198 | + * setTicketStatusDisplay  | 
                                                        |
| 199 | + *  | 
                                                        |
| 200 | + * @param int $remaining  | 
                                                        |
| 201 | + * @throws EE_Error  | 
                                                        |
| 202 | + */  | 
                                                        |
| 203 | +	protected function setTicketStatusDisplay($remaining) { | 
                                                        |
| 204 | + $this->ticket_status_display = '';  | 
                                                        |
| 205 | + // now depending on the ticket and other circumstances...  | 
                                                        |
| 206 | +		if ($this->max_attendees === 0) { | 
                                                        |
| 207 | + // registration is CLOSED because admin set max attendees to ZERO  | 
                                                        |
| 208 | + $this->ticket_status_display = $this->registrationClosed();  | 
                                                        |
| 209 | +		} elseif ($this->ticket_status_id === EE_Ticket::sold_out || $remaining === 0) { | 
                                                        |
| 210 | + // SOLD OUT - no tickets remaining  | 
                                                        |
| 211 | + $this->ticket_status_display = $this->ticketsSoldOut();  | 
                                                        |
| 212 | +		} elseif ($this->ticket_status_id === EE_Ticket::expired || $this->ticket_status_id === EE_Ticket::archived) { | 
                                                        |
| 213 | + // expired or archived ticket  | 
                                                        |
| 214 | + $this->ticket_status_display = $this->ticket_status_html;  | 
                                                        |
| 215 | +		} elseif ($this->ticket_status_id === EE_Ticket::pending) { | 
                                                        |
| 216 | + // ticket not on sale yet  | 
                                                        |
| 217 | + $this->ticket_status_display = $this->ticketsSalesPending();  | 
                                                        |
| 218 | +		} elseif ($this->ticket->min() > $remaining) { | 
                                                        |
| 219 | + // min qty purchasable is less than tickets available  | 
                                                        |
| 220 | + $this->ticket_status_display = $this->notEnoughTicketsAvailable();  | 
                                                        |
| 221 | + }  | 
                                                        |
| 222 | + }  | 
                                                        |
| 223 | +  | 
                                                        |
| 224 | +  | 
                                                        |
| 225 | +  | 
                                                        |
| 226 | + /**  | 
                                                        |
| 227 | + * registrationClosed  | 
                                                        |
| 228 | + */  | 
                                                        |
| 229 | + protected function registrationClosed()  | 
                                                        |
| 230 | +	{ | 
                                                        |
| 231 | + return EEH_HTML::span(  | 
                                                        |
| 232 | + apply_filters(  | 
                                                        |
| 233 | + 'FHEE__ticket_selector_chart_template__ticket_closed_msg',  | 
                                                        |
| 234 | +				__('Closed', 'event_espresso') | 
                                                        |
| 235 | + ),  | 
                                                        |
| 236 | + '', 'sold-out'  | 
                                                        |
| 237 | + );  | 
                                                        |
| 238 | + }  | 
                                                        |
| 239 | +  | 
                                                        |
| 240 | +  | 
                                                        |
| 241 | +  | 
                                                        |
| 242 | + /**  | 
                                                        |
| 243 | + * ticketsSoldOut  | 
                                                        |
| 244 | + */  | 
                                                        |
| 245 | + protected function ticketsSoldOut()  | 
                                                        |
| 246 | +	{ | 
                                                        |
| 247 | + return EEH_HTML::span(  | 
                                                        |
| 248 | + apply_filters(  | 
                                                        |
| 249 | + 'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',  | 
                                                        |
| 250 | +				__('Sold Out', 'event_espresso') | 
                                                        |
| 251 | + ),  | 
                                                        |
| 252 | + '', 'sold-out'  | 
                                                        |
| 253 | + );  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | +  | 
                                                        |
| 256 | +  | 
                                                        |
| 257 | +  | 
                                                        |
| 258 | + /**  | 
                                                        |
| 259 | + * ticketsSalesPending  | 
                                                        |
| 260 | + *  | 
                                                        |
| 261 | + * @throws EE_Error  | 
                                                        |
| 262 | + */  | 
                                                        |
| 263 | + protected function ticketsSalesPending()  | 
                                                        |
| 264 | +	{ | 
                                                        |
| 265 | + return EEH_HTML::span(  | 
                                                        |
| 266 | + EEH_HTML::span(  | 
                                                        |
| 267 | + apply_filters(  | 
                                                        |
| 268 | + 'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',  | 
                                                        |
| 269 | +					__('Goes On Sale', 'event_espresso') | 
                                                        |
| 270 | + ),  | 
                                                        |
| 271 | + '', 'ticket-pending'  | 
                                                        |
| 272 | + )  | 
                                                        |
| 273 | + . EEH_HTML::br()  | 
                                                        |
| 274 | + . EEH_HTML::span(  | 
                                                        |
| 275 | + $this->ticket->get_i18n_datetime(  | 
                                                        |
| 276 | + 'TKT_start_date',  | 
                                                        |
| 277 | + apply_filters(  | 
                                                        |
| 278 | + 'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',  | 
                                                        |
| 279 | + $this->date_format  | 
                                                        |
| 280 | + )  | 
                                                        |
| 281 | + ),  | 
                                                        |
| 282 | + '', 'small-text'  | 
                                                        |
| 283 | + ),  | 
                                                        |
| 284 | + '', 'ticket-pending-pg'  | 
                                                        |
| 285 | + );  | 
                                                        |
| 286 | + }  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | +  | 
                                                        |
| 289 | +  | 
                                                        |
| 290 | + /**  | 
                                                        |
| 291 | + * notEnoughTicketsAvailable  | 
                                                        |
| 292 | + */  | 
                                                        |
| 293 | + protected function notEnoughTicketsAvailable()  | 
                                                        |
| 294 | +	{ | 
                                                        |
| 295 | + return EEH_HTML::div(  | 
                                                        |
| 296 | + EEH_HTML::span(  | 
                                                        |
| 297 | + apply_filters(  | 
                                                        |
| 298 | + 'FHEE__ticket_selector_chart_template__ticket_not_available_msg',  | 
                                                        |
| 299 | +					__('Not Available', 'event_espresso') | 
                                                        |
| 300 | + ),  | 
                                                        |
| 301 | + '', 'archived-ticket small-text'  | 
                                                        |
| 302 | + )  | 
                                                        |
| 303 | + . EEH_HTML::br(),  | 
                                                        |
| 304 | + '', 'archived-ticket-pg'  | 
                                                        |
| 305 | + );  | 
                                                        |
| 306 | + }  | 
                                                        |
| 307 | +  | 
                                                        |
| 308 | +  | 
                                                        |
| 309 | +  | 
                                                        |
| 310 | + /**  | 
                                                        |
| 311 | + * setTicketMinAndMax  | 
                                                        |
| 312 | + *  | 
                                                        |
| 313 | + * @param int $remaining  | 
                                                        |
| 314 | + * @return void  | 
                                                        |
| 315 | + * @throws EE_Error  | 
                                                        |
| 316 | + */  | 
                                                        |
| 317 | + protected function setTicketMinAndMax($remaining)  | 
                                                        |
| 318 | +	{ | 
                                                        |
| 319 | + // offer the number of $tickets_remaining or $this->max_attendees, whichever is smaller  | 
                                                        |
| 320 | + $this->max = min($remaining, $this->max_attendees);  | 
                                                        |
| 321 | + // but... we also want to restrict the number of tickets by the ticket max setting,  | 
                                                        |
| 322 | + // however, the max still can't be higher than what was just set above  | 
                                                        |
| 323 | + $this->max = $this->ticket->max() > 0  | 
                                                        |
| 324 | + ? min($this->ticket->max(), $this->max)  | 
                                                        |
| 325 | + : $this->max;  | 
                                                        |
| 326 | + // and we also want to restrict the minimum number of tickets by the ticket min setting  | 
                                                        |
| 327 | + $this->min = $this->ticket->min() > 0  | 
                                                        |
| 328 | + ? $this->ticket->min()  | 
                                                        |
| 329 | + : 0;  | 
                                                        |
| 330 | + // and if the ticket is required, then make sure that min qty is at least 1  | 
                                                        |
| 331 | + $this->min = $this->ticket->required()  | 
                                                        |
| 332 | + ? max($this->min, 1)  | 
                                                        |
| 333 | + : $this->min;  | 
                                                        |
| 334 | + }  | 
                                                        |
| 335 | +  | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | + /**  | 
                                                        |
| 338 | + * Allow plugins to hook in and abort the generation and display of this row to do  | 
                                                        |
| 339 | + * something elseif they want.  | 
                                                        |
| 340 | + * For an addon to abort things, all they have to do is register a filter with this hook, and  | 
                                                        |
| 341 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the  | 
                                                        |
| 342 | + * current row.  | 
                                                        |
| 343 | + *  | 
                                                        |
| 344 | + * @return string|bool  | 
                                                        |
| 345 | + */  | 
                                                        |
| 346 | +	protected function getFilteredRowHtml() { | 
                                                        |
| 347 | + return apply_filters(  | 
                                                        |
| 348 | + 'FHEE__ticket_selector_chart_template__do_ticket_entire_row',  | 
                                                        |
| 349 | + false,  | 
                                                        |
| 350 | + $this->ticket,  | 
                                                        |
| 351 | + $this->max,  | 
                                                        |
| 352 | + $this->min,  | 
                                                        |
| 353 | + $this->required_ticket_sold_out,  | 
                                                        |
| 354 | + $this->ticket_price,  | 
                                                        |
| 355 | + $this->ticket_bundle,  | 
                                                        |
| 356 | + $this->ticket_status_html,  | 
                                                        |
| 357 | + $this->status_class,  | 
                                                        |
| 358 | + $this  | 
                                                        |
| 359 | + );  | 
                                                        |
| 360 | + }  | 
                                                        |
| 361 | +  | 
                                                        |
| 362 | +  | 
                                                        |
| 363 | +  | 
                                                        |
| 364 | + /**  | 
                                                        |
| 365 | + * Allow plugins to hook in and abort the generation and display of the contents of this  | 
                                                        |
| 366 | + * row to do something elseif they want.  | 
                                                        |
| 367 | + * For an addon to abort things, all they have to do is register a filter with this hook, and  | 
                                                        |
| 368 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the  | 
                                                        |
| 369 | + * current row.  | 
                                                        |
| 370 | + *  | 
                                                        |
| 371 | + * @return string|bool  | 
                                                        |
| 372 | + */  | 
                                                        |
| 373 | + protected function getFilteredRowContents()  | 
                                                        |
| 374 | +	{ | 
                                                        |
| 375 | + return apply_filters(  | 
                                                        |
| 376 | + 'FHEE__ticket_selector_chart_template__do_ticket_inside_row',  | 
                                                        |
| 377 | + false,  | 
                                                        |
| 378 | + $this->ticket,  | 
                                                        |
| 379 | + $this->max,  | 
                                                        |
| 380 | + $this->min,  | 
                                                        |
| 381 | + $this->required_ticket_sold_out,  | 
                                                        |
| 382 | + $this->ticket_price,  | 
                                                        |
| 383 | + $this->ticket_bundle,  | 
                                                        |
| 384 | + $this->ticket_status_html,  | 
                                                        |
| 385 | + $this->status_class,  | 
                                                        |
| 386 | + $this  | 
                                                        |
| 387 | + );  | 
                                                        |
| 388 | + }  | 
                                                        |
| 389 | 389 | |
| 390 | 390 | }  | 
                                                        
| 391 | 391 | // End of file TicketSelectorRow.php  | 
                                                        
@@ -17,7 +17,7 @@ discard block  | 
                                                    ||
| 17 | 17 | use WP_Post;  | 
                                                        
| 18 | 18 | |
| 19 | 19 |  if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { | 
                                                        
| 20 | - exit( 'No direct script access allowed' );  | 
                                                        |
| 20 | + exit( 'No direct script access allowed' );  | 
                                                        |
| 21 | 21 | }  | 
                                                        
| 22 | 22 | |
| 23 | 23 | |
@@ -34,688 +34,688 @@ discard block  | 
                                                    ||
| 34 | 34 | class DisplayTicketSelector  | 
                                                        
| 35 | 35 |  { | 
                                                        
| 36 | 36 | |
| 37 | - /**  | 
                                                        |
| 38 | - * event that ticket selector is being generated for  | 
                                                        |
| 39 | - *  | 
                                                        |
| 40 | - * @access protected  | 
                                                        |
| 41 | - * @var EE_Event $event  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - protected $event;  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /**  | 
                                                        |
| 46 | - * Used to flag when the ticket selector is being called from an external iframe.  | 
                                                        |
| 47 | - *  | 
                                                        |
| 48 | - * @var bool $iframe  | 
                                                        |
| 49 | - */  | 
                                                        |
| 50 | - protected $iframe = false;  | 
                                                        |
| 51 | -  | 
                                                        |
| 52 | - /**  | 
                                                        |
| 53 | - * max attendees that can register for event at one time  | 
                                                        |
| 54 | - *  | 
                                                        |
| 55 | - * @var int $max_attendees  | 
                                                        |
| 56 | - */  | 
                                                        |
| 57 | - private $max_attendees = EE_INF;  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - /**  | 
                                                        |
| 60 | - *@var string $date_format  | 
                                                        |
| 61 | - */  | 
                                                        |
| 62 | - private $date_format;  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | - /**  | 
                                                        |
| 65 | - *@var string $time_format  | 
                                                        |
| 66 | - */  | 
                                                        |
| 67 | - private $time_format;  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | - /**  | 
                                                        |
| 72 | - * DisplayTicketSelector constructor.  | 
                                                        |
| 73 | - */  | 
                                                        |
| 74 | - public function __construct()  | 
                                                        |
| 75 | -    { | 
                                                        |
| 76 | - $this->date_format = apply_filters(  | 
                                                        |
| 77 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',  | 
                                                        |
| 78 | -            get_option('date_format') | 
                                                        |
| 79 | - );  | 
                                                        |
| 80 | - $this->time_format = apply_filters(  | 
                                                        |
| 81 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',  | 
                                                        |
| 82 | -            get_option('time_format') | 
                                                        |
| 83 | - );  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - /**  | 
                                                        |
| 89 | - * @param boolean $iframe  | 
                                                        |
| 90 | - */  | 
                                                        |
| 91 | - public function setIframe( $iframe = true )  | 
                                                        |
| 92 | -    { | 
                                                        |
| 93 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );  | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | -  | 
                                                        |
| 97 | - /**  | 
                                                        |
| 98 | - * finds and sets the \EE_Event object for use throughout class  | 
                                                        |
| 99 | - *  | 
                                                        |
| 100 | - * @param mixed $event  | 
                                                        |
| 101 | - * @return bool  | 
                                                        |
| 102 | - * @throws EE_Error  | 
                                                        |
| 103 | - */  | 
                                                        |
| 104 | - protected function setEvent( $event = null )  | 
                                                        |
| 105 | -    { | 
                                                        |
| 106 | -        if ( $event === null ) { | 
                                                        |
| 107 | - global $post;  | 
                                                        |
| 108 | - $event = $post;  | 
                                                        |
| 109 | - }  | 
                                                        |
| 110 | -        if ( $event instanceof EE_Event ) { | 
                                                        |
| 111 | - $this->event = $event;  | 
                                                        |
| 112 | -        } elseif ( $event instanceof WP_Post ) { | 
                                                        |
| 113 | -            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { | 
                                                        |
| 114 | - $this->event = $event->EE_Event;  | 
                                                        |
| 115 | -            } elseif ( $event->post_type === 'espresso_events' ) { | 
                                                        |
| 116 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );  | 
                                                        |
| 117 | - $this->event = $event->EE_Event;  | 
                                                        |
| 118 | - }  | 
                                                        |
| 119 | -        } else { | 
                                                        |
| 120 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );  | 
                                                        |
| 121 | - $dev_msg = $user_msg . __(  | 
                                                        |
| 122 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',  | 
                                                        |
| 123 | - 'event_espresso'  | 
                                                        |
| 124 | - );  | 
                                                        |
| 125 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );  | 
                                                        |
| 126 | - return false;  | 
                                                        |
| 127 | - }  | 
                                                        |
| 128 | - return true;  | 
                                                        |
| 129 | - }  | 
                                                        |
| 130 | -  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - /**  | 
                                                        |
| 134 | - * @return int  | 
                                                        |
| 135 | - */  | 
                                                        |
| 136 | - public function getMaxAttendees()  | 
                                                        |
| 137 | -    { | 
                                                        |
| 138 | - return $this->max_attendees;  | 
                                                        |
| 139 | - }  | 
                                                        |
| 140 | -  | 
                                                        |
| 141 | -  | 
                                                        |
| 142 | -  | 
                                                        |
| 143 | - /**  | 
                                                        |
| 144 | - * @param int $max_attendees  | 
                                                        |
| 145 | - */  | 
                                                        |
| 146 | - public function setMaxAttendees($max_attendees)  | 
                                                        |
| 147 | -    { | 
                                                        |
| 148 | - $this->max_attendees = absint(  | 
                                                        |
| 149 | - apply_filters(  | 
                                                        |
| 150 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',  | 
                                                        |
| 151 | - $max_attendees  | 
                                                        |
| 152 | - )  | 
                                                        |
| 153 | - );  | 
                                                        |
| 154 | - }  | 
                                                        |
| 155 | -  | 
                                                        |
| 156 | -  | 
                                                        |
| 157 | -  | 
                                                        |
| 158 | - /**  | 
                                                        |
| 159 | - * creates buttons for selecting number of attendees for an event  | 
                                                        |
| 160 | - *  | 
                                                        |
| 161 | - * @param WP_Post|int $event  | 
                                                        |
| 162 | - * @param bool $view_details  | 
                                                        |
| 163 | - * @return string  | 
                                                        |
| 164 | - * @throws EE_Error  | 
                                                        |
| 165 | - */  | 
                                                        |
| 166 | - public function display( $event = null, $view_details = false )  | 
                                                        |
| 167 | -    { | 
                                                        |
| 168 | - // reset filter for displaying submit button  | 
                                                        |
| 169 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );  | 
                                                        |
| 170 | - // poke and prod incoming event till it tells us what it is  | 
                                                        |
| 171 | -        if ( ! $this->setEvent( $event ) ) { | 
                                                        |
| 172 | - return false;  | 
                                                        |
| 173 | - }  | 
                                                        |
| 174 | - // begin gathering template arguments by getting event status  | 
                                                        |
| 175 | - $template_args = array( 'event_status' => $this->event->get_active_status() );  | 
                                                        |
| 176 | -        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { | 
                                                        |
| 177 | - return ! is_single() ? $this->displayViewDetailsButton() : '';  | 
                                                        |
| 178 | - }  | 
                                                        |
| 179 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns  | 
                                                        |
| 180 | - $this->setMaxAttendees($this->event->additional_limit());  | 
                                                        |
| 181 | -        if ($this->getMaxAttendees() < 1) { | 
                                                        |
| 182 | - return $this->ticketSalesClosedMessage();  | 
                                                        |
| 183 | - }  | 
                                                        |
| 184 | - // is the event expired ?  | 
                                                        |
| 185 | - $template_args['event_is_expired'] = $this->event->is_expired();  | 
                                                        |
| 186 | -        if ( $template_args[ 'event_is_expired' ] ) { | 
                                                        |
| 187 | - return $this->expiredEventMessage();  | 
                                                        |
| 188 | - }  | 
                                                        |
| 189 | - // get all tickets for this event ordered by the datetime  | 
                                                        |
| 190 | - $tickets = $this->getTickets();  | 
                                                        |
| 191 | -        if (count($tickets) < 1) { | 
                                                        |
| 192 | - return $this->noTicketAvailableMessage();  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | -        if (EED_Events_Archive::is_iframe()){ | 
                                                        |
| 195 | - $this->setIframe();  | 
                                                        |
| 196 | - }  | 
                                                        |
| 197 | - // redirecting to another site for registration ??  | 
                                                        |
| 198 | - $external_url = (string) $this->event->external_url();  | 
                                                        |
| 199 | - // if redirecting to another site for registration, then we don't load the TS  | 
                                                        |
| 200 | - $ticket_selector = $external_url  | 
                                                        |
| 201 | - ? $this->externalEventRegistration()  | 
                                                        |
| 202 | - : $this->loadTicketSelector($tickets,$template_args);  | 
                                                        |
| 203 | - // now set up the form (but not for the admin)  | 
                                                        |
| 204 | - $ticket_selector = ! is_admin()  | 
                                                        |
| 205 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector  | 
                                                        |
| 206 | - : $ticket_selector;  | 
                                                        |
| 207 | - // submit button and form close tag  | 
                                                        |
| 208 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';  | 
                                                        |
| 209 | - return $ticket_selector;  | 
                                                        |
| 210 | - }  | 
                                                        |
| 211 | -  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | -  | 
                                                        |
| 214 | - /**  | 
                                                        |
| 215 | - * displayTicketSelector  | 
                                                        |
| 216 | - * examines the event properties and determines whether a Ticket Selector should be displayed  | 
                                                        |
| 217 | - *  | 
                                                        |
| 218 | - * @param WP_Post|int $event  | 
                                                        |
| 219 | - * @param string $_event_active_status  | 
                                                        |
| 220 | - * @param bool $view_details  | 
                                                        |
| 221 | - * @return bool  | 
                                                        |
| 222 | - * @throws EE_Error  | 
                                                        |
| 223 | - */  | 
                                                        |
| 224 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)  | 
                                                        |
| 225 | -    { | 
                                                        |
| 226 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;  | 
                                                        |
| 227 | - return ! is_admin()  | 
                                                        |
| 228 | - && (  | 
                                                        |
| 229 | - ! $this->event->display_ticket_selector()  | 
                                                        |
| 230 | - || $view_details  | 
                                                        |
| 231 | - || post_password_required($event_post)  | 
                                                        |
| 232 | - || (  | 
                                                        |
| 233 | - $_event_active_status !== EE_Datetime::active  | 
                                                        |
| 234 | - && $_event_active_status !== EE_Datetime::upcoming  | 
                                                        |
| 235 | - && $_event_active_status !== EE_Datetime::sold_out  | 
                                                        |
| 236 | - && ! (  | 
                                                        |
| 237 | - $_event_active_status === EE_Datetime::inactive  | 
                                                        |
| 238 | - && is_user_logged_in()  | 
                                                        |
| 239 | - )  | 
                                                        |
| 240 | - )  | 
                                                        |
| 241 | - );  | 
                                                        |
| 242 | - }  | 
                                                        |
| 243 | -  | 
                                                        |
| 244 | -  | 
                                                        |
| 245 | -  | 
                                                        |
| 246 | - /**  | 
                                                        |
| 247 | - * noTicketAvailableMessage  | 
                                                        |
| 248 | - * notice displayed if event is expired  | 
                                                        |
| 249 | - *  | 
                                                        |
| 250 | - * @return string  | 
                                                        |
| 251 | - * @throws EE_Error  | 
                                                        |
| 252 | - */  | 
                                                        |
| 253 | - protected function expiredEventMessage()  | 
                                                        |
| 254 | -    { | 
                                                        |
| 255 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(  | 
                                                        |
| 256 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.',  | 
                                                        |
| 257 | - 'event_espresso'  | 
                                                        |
| 258 | - ) . '</span></div><!-- .ee-event-expired-notice -->';  | 
                                                        |
| 259 | - }  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | -  | 
                                                        |
| 262 | -  | 
                                                        |
| 263 | - /**  | 
                                                        |
| 264 | - * noTicketAvailableMessage  | 
                                                        |
| 265 | - * notice displayed if event has no more tickets available  | 
                                                        |
| 266 | - *  | 
                                                        |
| 267 | - * @return string  | 
                                                        |
| 268 | - * @throws EE_Error  | 
                                                        |
| 269 | - */  | 
                                                        |
| 270 | - protected function noTicketAvailableMessage()  | 
                                                        |
| 271 | -    { | 
                                                        |
| 272 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );  | 
                                                        |
| 273 | -        if (current_user_can('edit_post', $this->event->ID())) { | 
                                                        |
| 274 | - $no_ticket_available_msg .= sprintf(  | 
                                                        |
| 275 | - esc_html__(  | 
                                                        |
| 276 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',  | 
                                                        |
| 277 | - 'event_espresso'  | 
                                                        |
| 278 | - ),  | 
                                                        |
| 279 | - '<div class="ee-attention" style="text-align: left;"><b>',  | 
                                                        |
| 280 | - '</b><br />',  | 
                                                        |
| 281 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',  | 
                                                        |
| 282 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'  | 
                                                        |
| 283 | - );  | 
                                                        |
| 284 | - }  | 
                                                        |
| 285 | - return '  | 
                                                        |
| 37 | + /**  | 
                                                        |
| 38 | + * event that ticket selector is being generated for  | 
                                                        |
| 39 | + *  | 
                                                        |
| 40 | + * @access protected  | 
                                                        |
| 41 | + * @var EE_Event $event  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + protected $event;  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /**  | 
                                                        |
| 46 | + * Used to flag when the ticket selector is being called from an external iframe.  | 
                                                        |
| 47 | + *  | 
                                                        |
| 48 | + * @var bool $iframe  | 
                                                        |
| 49 | + */  | 
                                                        |
| 50 | + protected $iframe = false;  | 
                                                        |
| 51 | +  | 
                                                        |
| 52 | + /**  | 
                                                        |
| 53 | + * max attendees that can register for event at one time  | 
                                                        |
| 54 | + *  | 
                                                        |
| 55 | + * @var int $max_attendees  | 
                                                        |
| 56 | + */  | 
                                                        |
| 57 | + private $max_attendees = EE_INF;  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + /**  | 
                                                        |
| 60 | + *@var string $date_format  | 
                                                        |
| 61 | + */  | 
                                                        |
| 62 | + private $date_format;  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | + /**  | 
                                                        |
| 65 | + *@var string $time_format  | 
                                                        |
| 66 | + */  | 
                                                        |
| 67 | + private $time_format;  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | + /**  | 
                                                        |
| 72 | + * DisplayTicketSelector constructor.  | 
                                                        |
| 73 | + */  | 
                                                        |
| 74 | + public function __construct()  | 
                                                        |
| 75 | +	{ | 
                                                        |
| 76 | + $this->date_format = apply_filters(  | 
                                                        |
| 77 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',  | 
                                                        |
| 78 | +			get_option('date_format') | 
                                                        |
| 79 | + );  | 
                                                        |
| 80 | + $this->time_format = apply_filters(  | 
                                                        |
| 81 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',  | 
                                                        |
| 82 | +			get_option('time_format') | 
                                                        |
| 83 | + );  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + /**  | 
                                                        |
| 89 | + * @param boolean $iframe  | 
                                                        |
| 90 | + */  | 
                                                        |
| 91 | + public function setIframe( $iframe = true )  | 
                                                        |
| 92 | +	{ | 
                                                        |
| 93 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | +  | 
                                                        |
| 97 | + /**  | 
                                                        |
| 98 | + * finds and sets the \EE_Event object for use throughout class  | 
                                                        |
| 99 | + *  | 
                                                        |
| 100 | + * @param mixed $event  | 
                                                        |
| 101 | + * @return bool  | 
                                                        |
| 102 | + * @throws EE_Error  | 
                                                        |
| 103 | + */  | 
                                                        |
| 104 | + protected function setEvent( $event = null )  | 
                                                        |
| 105 | +	{ | 
                                                        |
| 106 | +		if ( $event === null ) { | 
                                                        |
| 107 | + global $post;  | 
                                                        |
| 108 | + $event = $post;  | 
                                                        |
| 109 | + }  | 
                                                        |
| 110 | +		if ( $event instanceof EE_Event ) { | 
                                                        |
| 111 | + $this->event = $event;  | 
                                                        |
| 112 | +		} elseif ( $event instanceof WP_Post ) { | 
                                                        |
| 113 | +			if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { | 
                                                        |
| 114 | + $this->event = $event->EE_Event;  | 
                                                        |
| 115 | +			} elseif ( $event->post_type === 'espresso_events' ) { | 
                                                        |
| 116 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );  | 
                                                        |
| 117 | + $this->event = $event->EE_Event;  | 
                                                        |
| 118 | + }  | 
                                                        |
| 119 | +		} else { | 
                                                        |
| 120 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );  | 
                                                        |
| 121 | + $dev_msg = $user_msg . __(  | 
                                                        |
| 122 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',  | 
                                                        |
| 123 | + 'event_espresso'  | 
                                                        |
| 124 | + );  | 
                                                        |
| 125 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );  | 
                                                        |
| 126 | + return false;  | 
                                                        |
| 127 | + }  | 
                                                        |
| 128 | + return true;  | 
                                                        |
| 129 | + }  | 
                                                        |
| 130 | +  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + /**  | 
                                                        |
| 134 | + * @return int  | 
                                                        |
| 135 | + */  | 
                                                        |
| 136 | + public function getMaxAttendees()  | 
                                                        |
| 137 | +	{ | 
                                                        |
| 138 | + return $this->max_attendees;  | 
                                                        |
| 139 | + }  | 
                                                        |
| 140 | +  | 
                                                        |
| 141 | +  | 
                                                        |
| 142 | +  | 
                                                        |
| 143 | + /**  | 
                                                        |
| 144 | + * @param int $max_attendees  | 
                                                        |
| 145 | + */  | 
                                                        |
| 146 | + public function setMaxAttendees($max_attendees)  | 
                                                        |
| 147 | +	{ | 
                                                        |
| 148 | + $this->max_attendees = absint(  | 
                                                        |
| 149 | + apply_filters(  | 
                                                        |
| 150 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',  | 
                                                        |
| 151 | + $max_attendees  | 
                                                        |
| 152 | + )  | 
                                                        |
| 153 | + );  | 
                                                        |
| 154 | + }  | 
                                                        |
| 155 | +  | 
                                                        |
| 156 | +  | 
                                                        |
| 157 | +  | 
                                                        |
| 158 | + /**  | 
                                                        |
| 159 | + * creates buttons for selecting number of attendees for an event  | 
                                                        |
| 160 | + *  | 
                                                        |
| 161 | + * @param WP_Post|int $event  | 
                                                        |
| 162 | + * @param bool $view_details  | 
                                                        |
| 163 | + * @return string  | 
                                                        |
| 164 | + * @throws EE_Error  | 
                                                        |
| 165 | + */  | 
                                                        |
| 166 | + public function display( $event = null, $view_details = false )  | 
                                                        |
| 167 | +	{ | 
                                                        |
| 168 | + // reset filter for displaying submit button  | 
                                                        |
| 169 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );  | 
                                                        |
| 170 | + // poke and prod incoming event till it tells us what it is  | 
                                                        |
| 171 | +		if ( ! $this->setEvent( $event ) ) { | 
                                                        |
| 172 | + return false;  | 
                                                        |
| 173 | + }  | 
                                                        |
| 174 | + // begin gathering template arguments by getting event status  | 
                                                        |
| 175 | + $template_args = array( 'event_status' => $this->event->get_active_status() );  | 
                                                        |
| 176 | +		if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { | 
                                                        |
| 177 | + return ! is_single() ? $this->displayViewDetailsButton() : '';  | 
                                                        |
| 178 | + }  | 
                                                        |
| 179 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns  | 
                                                        |
| 180 | + $this->setMaxAttendees($this->event->additional_limit());  | 
                                                        |
| 181 | +		if ($this->getMaxAttendees() < 1) { | 
                                                        |
| 182 | + return $this->ticketSalesClosedMessage();  | 
                                                        |
| 183 | + }  | 
                                                        |
| 184 | + // is the event expired ?  | 
                                                        |
| 185 | + $template_args['event_is_expired'] = $this->event->is_expired();  | 
                                                        |
| 186 | +		if ( $template_args[ 'event_is_expired' ] ) { | 
                                                        |
| 187 | + return $this->expiredEventMessage();  | 
                                                        |
| 188 | + }  | 
                                                        |
| 189 | + // get all tickets for this event ordered by the datetime  | 
                                                        |
| 190 | + $tickets = $this->getTickets();  | 
                                                        |
| 191 | +		if (count($tickets) < 1) { | 
                                                        |
| 192 | + return $this->noTicketAvailableMessage();  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | +		if (EED_Events_Archive::is_iframe()){ | 
                                                        |
| 195 | + $this->setIframe();  | 
                                                        |
| 196 | + }  | 
                                                        |
| 197 | + // redirecting to another site for registration ??  | 
                                                        |
| 198 | + $external_url = (string) $this->event->external_url();  | 
                                                        |
| 199 | + // if redirecting to another site for registration, then we don't load the TS  | 
                                                        |
| 200 | + $ticket_selector = $external_url  | 
                                                        |
| 201 | + ? $this->externalEventRegistration()  | 
                                                        |
| 202 | + : $this->loadTicketSelector($tickets,$template_args);  | 
                                                        |
| 203 | + // now set up the form (but not for the admin)  | 
                                                        |
| 204 | + $ticket_selector = ! is_admin()  | 
                                                        |
| 205 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector  | 
                                                        |
| 206 | + : $ticket_selector;  | 
                                                        |
| 207 | + // submit button and form close tag  | 
                                                        |
| 208 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';  | 
                                                        |
| 209 | + return $ticket_selector;  | 
                                                        |
| 210 | + }  | 
                                                        |
| 211 | +  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | +  | 
                                                        |
| 214 | + /**  | 
                                                        |
| 215 | + * displayTicketSelector  | 
                                                        |
| 216 | + * examines the event properties and determines whether a Ticket Selector should be displayed  | 
                                                        |
| 217 | + *  | 
                                                        |
| 218 | + * @param WP_Post|int $event  | 
                                                        |
| 219 | + * @param string $_event_active_status  | 
                                                        |
| 220 | + * @param bool $view_details  | 
                                                        |
| 221 | + * @return bool  | 
                                                        |
| 222 | + * @throws EE_Error  | 
                                                        |
| 223 | + */  | 
                                                        |
| 224 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)  | 
                                                        |
| 225 | +	{ | 
                                                        |
| 226 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;  | 
                                                        |
| 227 | + return ! is_admin()  | 
                                                        |
| 228 | + && (  | 
                                                        |
| 229 | + ! $this->event->display_ticket_selector()  | 
                                                        |
| 230 | + || $view_details  | 
                                                        |
| 231 | + || post_password_required($event_post)  | 
                                                        |
| 232 | + || (  | 
                                                        |
| 233 | + $_event_active_status !== EE_Datetime::active  | 
                                                        |
| 234 | + && $_event_active_status !== EE_Datetime::upcoming  | 
                                                        |
| 235 | + && $_event_active_status !== EE_Datetime::sold_out  | 
                                                        |
| 236 | + && ! (  | 
                                                        |
| 237 | + $_event_active_status === EE_Datetime::inactive  | 
                                                        |
| 238 | + && is_user_logged_in()  | 
                                                        |
| 239 | + )  | 
                                                        |
| 240 | + )  | 
                                                        |
| 241 | + );  | 
                                                        |
| 242 | + }  | 
                                                        |
| 243 | +  | 
                                                        |
| 244 | +  | 
                                                        |
| 245 | +  | 
                                                        |
| 246 | + /**  | 
                                                        |
| 247 | + * noTicketAvailableMessage  | 
                                                        |
| 248 | + * notice displayed if event is expired  | 
                                                        |
| 249 | + *  | 
                                                        |
| 250 | + * @return string  | 
                                                        |
| 251 | + * @throws EE_Error  | 
                                                        |
| 252 | + */  | 
                                                        |
| 253 | + protected function expiredEventMessage()  | 
                                                        |
| 254 | +	{ | 
                                                        |
| 255 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(  | 
                                                        |
| 256 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.',  | 
                                                        |
| 257 | + 'event_espresso'  | 
                                                        |
| 258 | + ) . '</span></div><!-- .ee-event-expired-notice -->';  | 
                                                        |
| 259 | + }  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | +  | 
                                                        |
| 262 | +  | 
                                                        |
| 263 | + /**  | 
                                                        |
| 264 | + * noTicketAvailableMessage  | 
                                                        |
| 265 | + * notice displayed if event has no more tickets available  | 
                                                        |
| 266 | + *  | 
                                                        |
| 267 | + * @return string  | 
                                                        |
| 268 | + * @throws EE_Error  | 
                                                        |
| 269 | + */  | 
                                                        |
| 270 | + protected function noTicketAvailableMessage()  | 
                                                        |
| 271 | +	{ | 
                                                        |
| 272 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );  | 
                                                        |
| 273 | +		if (current_user_can('edit_post', $this->event->ID())) { | 
                                                        |
| 274 | + $no_ticket_available_msg .= sprintf(  | 
                                                        |
| 275 | + esc_html__(  | 
                                                        |
| 276 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',  | 
                                                        |
| 277 | + 'event_espresso'  | 
                                                        |
| 278 | + ),  | 
                                                        |
| 279 | + '<div class="ee-attention" style="text-align: left;"><b>',  | 
                                                        |
| 280 | + '</b><br />',  | 
                                                        |
| 281 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',  | 
                                                        |
| 282 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'  | 
                                                        |
| 283 | + );  | 
                                                        |
| 284 | + }  | 
                                                        |
| 285 | + return '  | 
                                                        |
| 286 | 286 | <div class="ee-event-expired-notice">  | 
                                                        
| 287 | 287 | <span class="important-notice">' . $no_ticket_available_msg . '</span>  | 
                                                        
| 288 | 288 | </div><!-- .ee-event-expired-notice -->';  | 
                                                        
| 289 | - }  | 
                                                        |
| 290 | -  | 
                                                        |
| 291 | -  | 
                                                        |
| 292 | -  | 
                                                        |
| 293 | - /**  | 
                                                        |
| 294 | - * ticketSalesClosed  | 
                                                        |
| 295 | - * notice displayed if event ticket sales are turned off  | 
                                                        |
| 296 | - *  | 
                                                        |
| 297 | - * @return string  | 
                                                        |
| 298 | - * @throws EE_Error  | 
                                                        |
| 299 | - */  | 
                                                        |
| 300 | - protected function ticketSalesClosedMessage()  | 
                                                        |
| 301 | -    { | 
                                                        |
| 302 | - $sales_closed_msg = esc_html__(  | 
                                                        |
| 303 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',  | 
                                                        |
| 304 | - 'event_espresso'  | 
                                                        |
| 305 | - );  | 
                                                        |
| 306 | -        if (current_user_can('edit_post', $this->event->ID())) { | 
                                                        |
| 307 | - $sales_closed_msg .= sprintf(  | 
                                                        |
| 308 | - esc_html__(  | 
                                                        |
| 309 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',  | 
                                                        |
| 310 | - 'event_espresso'  | 
                                                        |
| 311 | - ),  | 
                                                        |
| 312 | - '<div class="ee-attention" style="text-align: left;"><b>',  | 
                                                        |
| 313 | - '</b><br />',  | 
                                                        |
| 314 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',  | 
                                                        |
| 315 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'  | 
                                                        |
| 316 | - );  | 
                                                        |
| 317 | - }  | 
                                                        |
| 318 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';  | 
                                                        |
| 319 | - }  | 
                                                        |
| 320 | -  | 
                                                        |
| 321 | -  | 
                                                        |
| 322 | -  | 
                                                        |
| 323 | - /**  | 
                                                        |
| 324 | - * getTickets  | 
                                                        |
| 325 | - *  | 
                                                        |
| 326 | - * @return \EE_Base_Class[]|\EE_Ticket[]  | 
                                                        |
| 327 | - * @throws EE_Error  | 
                                                        |
| 328 | - */  | 
                                                        |
| 329 | - protected function getTickets()  | 
                                                        |
| 330 | -    { | 
                                                        |
| 331 | - $ticket_query_args = array(  | 
                                                        |
| 332 | -            array('Datetime.EVT_ID' => $this->event->ID()), | 
                                                        |
| 333 | - 'order_by' => array(  | 
                                                        |
| 334 | - 'TKT_order' => 'ASC',  | 
                                                        |
| 335 | - 'TKT_required' => 'DESC',  | 
                                                        |
| 336 | - 'TKT_start_date' => 'ASC',  | 
                                                        |
| 337 | - 'TKT_end_date' => 'ASC',  | 
                                                        |
| 338 | - 'Datetime.DTT_EVT_start' => 'DESC',  | 
                                                        |
| 339 | - ),  | 
                                                        |
| 340 | - );  | 
                                                        |
| 341 | - if (  | 
                                                        |
| 342 | - ! (  | 
                                                        |
| 343 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config  | 
                                                        |
| 344 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets  | 
                                                        |
| 345 | - )  | 
                                                        |
| 346 | -        ) { | 
                                                        |
| 347 | - //use the correct applicable time query depending on what version of core is being run.  | 
                                                        |
| 348 | -            $current_time = method_exists('EEM_Datetime', 'current_time_for_query') | 
                                                        |
| 349 | - ? time()  | 
                                                        |
| 350 | -                : current_time('timestamp'); | 
                                                        |
| 351 | -            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); | 
                                                        |
| 352 | - }  | 
                                                        |
| 353 | - return EEM_Ticket::instance()->get_all($ticket_query_args);  | 
                                                        |
| 354 | - }  | 
                                                        |
| 355 | -  | 
                                                        |
| 356 | -  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | - /**  | 
                                                        |
| 359 | - * loadTicketSelector  | 
                                                        |
| 360 | - * begins to assemble template arguments  | 
                                                        |
| 361 | - * and decides whether to load a "simple" ticket selector, or the standard  | 
                                                        |
| 362 | - *  | 
                                                        |
| 363 | - * @param \EE_Ticket[] $tickets  | 
                                                        |
| 364 | - * @param array $template_args  | 
                                                        |
| 365 | - * @return string  | 
                                                        |
| 366 | - * @throws EE_Error  | 
                                                        |
| 367 | - */  | 
                                                        |
| 368 | - protected function loadTicketSelector(array $tickets, array $template_args)  | 
                                                        |
| 369 | -    { | 
                                                        |
| 370 | - $template_args['event'] = $this->event;  | 
                                                        |
| 371 | - $template_args['EVT_ID'] = $this->event->ID();  | 
                                                        |
| 372 | - $template_args['event_is_expired'] = $this->event->is_expired();  | 
                                                        |
| 373 | - $template_args['max_atndz'] = $this->getMaxAttendees();  | 
                                                        |
| 374 | - $template_args['date_format'] = $this->date_format;  | 
                                                        |
| 375 | - $template_args['time_format'] = $this->time_format;  | 
                                                        |
| 376 | - /**  | 
                                                        |
| 377 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected  | 
                                                        |
| 378 | - *  | 
                                                        |
| 379 | - * @since 4.9.13  | 
                                                        |
| 380 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to  | 
                                                        |
| 381 | - * @param int $EVT_ID The Event ID  | 
                                                        |
| 382 | - */  | 
                                                        |
| 383 | - $template_args['anchor_id'] = apply_filters(  | 
                                                        |
| 384 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id',  | 
                                                        |
| 385 | - '#tkt-slctr-tbl-' . $this->event->ID(),  | 
                                                        |
| 386 | - $this->event->ID()  | 
                                                        |
| 387 | - );  | 
                                                        |
| 388 | - $template_args['tickets'] = $tickets;  | 
                                                        |
| 389 | - $template_args['ticket_count'] = count($tickets);  | 
                                                        |
| 390 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);  | 
                                                        |
| 391 | - return $ticket_selector instanceof TicketSelectorSimple  | 
                                                        |
| 392 | - ? $ticket_selector  | 
                                                        |
| 393 | - : new TicketSelectorStandard(  | 
                                                        |
| 394 | - $this->event,  | 
                                                        |
| 395 | - $tickets,  | 
                                                        |
| 396 | - $this->getMaxAttendees(),  | 
                                                        |
| 397 | - $template_args,  | 
                                                        |
| 398 | - $this->date_format,  | 
                                                        |
| 399 | - $this->time_format  | 
                                                        |
| 400 | - );  | 
                                                        |
| 401 | - }  | 
                                                        |
| 402 | -  | 
                                                        |
| 403 | -  | 
                                                        |
| 404 | -  | 
                                                        |
| 405 | - /**  | 
                                                        |
| 406 | - * simpleTicketSelector  | 
                                                        |
| 407 | - * there's one ticket, and max attendees is set to one,  | 
                                                        |
| 408 | - * so if the event is free, then this is a "simple" ticket selector  | 
                                                        |
| 409 | - * a.k.a. "Dude Where's my Ticket Selector?"  | 
                                                        |
| 410 | - *  | 
                                                        |
| 411 | - * @param \EE_Ticket[] $tickets  | 
                                                        |
| 412 | - * @param array $template_args  | 
                                                        |
| 413 | - * @return string  | 
                                                        |
| 414 | - * @throws EE_Error  | 
                                                        |
| 415 | - */  | 
                                                        |
| 416 | - protected function simpleTicketSelector($tickets, array $template_args)  | 
                                                        |
| 417 | -    { | 
                                                        |
| 418 | - // if there is only ONE ticket with a max qty of ONE  | 
                                                        |
| 419 | -        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { | 
                                                        |
| 420 | - return '';  | 
                                                        |
| 421 | - }  | 
                                                        |
| 422 | - /** @var \EE_Ticket $ticket */  | 
                                                        |
| 423 | - $ticket = reset($tickets);  | 
                                                        |
| 424 | - // if the ticket is free... then not much need for the ticket selector  | 
                                                        |
| 425 | - if (  | 
                                                        |
| 426 | - apply_filters(  | 
                                                        |
| 427 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector',  | 
                                                        |
| 428 | - $ticket->is_free(),  | 
                                                        |
| 429 | - $this->event->ID()  | 
                                                        |
| 430 | - )  | 
                                                        |
| 431 | -        ) { | 
                                                        |
| 432 | - return new TicketSelectorSimple(  | 
                                                        |
| 433 | - $this->event,  | 
                                                        |
| 434 | - $ticket,  | 
                                                        |
| 435 | - $this->getMaxAttendees(),  | 
                                                        |
| 436 | - $template_args  | 
                                                        |
| 437 | - );  | 
                                                        |
| 438 | - }  | 
                                                        |
| 439 | - return '';  | 
                                                        |
| 440 | - }  | 
                                                        |
| 441 | -  | 
                                                        |
| 442 | -  | 
                                                        |
| 443 | -  | 
                                                        |
| 444 | - /**  | 
                                                        |
| 445 | - * externalEventRegistration  | 
                                                        |
| 446 | - *  | 
                                                        |
| 447 | - * @return string  | 
                                                        |
| 448 | - */  | 
                                                        |
| 449 | - public function externalEventRegistration()  | 
                                                        |
| 450 | -    { | 
                                                        |
| 451 | - // if not we still need to trigger the display of the submit button  | 
                                                        |
| 452 | -        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 453 | - //display notice to admin that registration is external  | 
                                                        |
| 454 | - return is_admin()  | 
                                                        |
| 455 | - ? esc_html__(  | 
                                                        |
| 456 | - 'Registration is at an external URL for this event.',  | 
                                                        |
| 457 | - 'event_espresso'  | 
                                                        |
| 458 | - )  | 
                                                        |
| 459 | - : '';  | 
                                                        |
| 460 | - }  | 
                                                        |
| 461 | -  | 
                                                        |
| 462 | -  | 
                                                        |
| 463 | -  | 
                                                        |
| 464 | - /**  | 
                                                        |
| 465 | - * formOpen  | 
                                                        |
| 466 | - *  | 
                                                        |
| 467 | - * @param int $ID  | 
                                                        |
| 468 | - * @param string $external_url  | 
                                                        |
| 469 | - * @return string  | 
                                                        |
| 470 | - */  | 
                                                        |
| 471 | - public function formOpen( $ID = 0, $external_url = '' )  | 
                                                        |
| 472 | -    { | 
                                                        |
| 473 | - // if redirecting, we don't need any anything else  | 
                                                        |
| 474 | -        if ( $external_url ) { | 
                                                        |
| 475 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';  | 
                                                        |
| 476 | - // open link in new window ?  | 
                                                        |
| 477 | - $html .= apply_filters(  | 
                                                        |
| 478 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',  | 
                                                        |
| 479 | - EED_Events_Archive::is_iframe()  | 
                                                        |
| 480 | - )  | 
                                                        |
| 481 | - ? ' target="_blank"'  | 
                                                        |
| 482 | - : '';  | 
                                                        |
| 483 | - $html .= '>';  | 
                                                        |
| 484 | - $query_args = EEH_URL::get_query_string( $external_url );  | 
                                                        |
| 485 | -            foreach ( (array)$query_args as $query_arg => $value ) { | 
                                                        |
| 486 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';  | 
                                                        |
| 487 | - }  | 
                                                        |
| 488 | - return $html;  | 
                                                        |
| 489 | - }  | 
                                                        |
| 490 | - // if there is no submit button, then don't start building a form  | 
                                                        |
| 491 | - // because the "View Details" button will build its own form  | 
                                                        |
| 492 | -        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { | 
                                                        |
| 493 | - return '';  | 
                                                        |
| 494 | - }  | 
                                                        |
| 495 | - $checkout_url = EEH_Event_View::event_link_url( $ID );  | 
                                                        |
| 496 | -        if ( ! $checkout_url ) { | 
                                                        |
| 497 | - EE_Error::add_error(  | 
                                                        |
| 498 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 499 | - __FILE__,  | 
                                                        |
| 500 | - __FUNCTION__,  | 
                                                        |
| 501 | - __LINE__  | 
                                                        |
| 502 | - );  | 
                                                        |
| 503 | - }  | 
                                                        |
| 504 | - // set no cache headers and constants  | 
                                                        |
| 505 | - EE_System::do_not_cache();  | 
                                                        |
| 506 | - $extra_params = $this->iframe ? ' target="_blank"' : '';  | 
                                                        |
| 507 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';  | 
                                                        |
| 508 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';  | 
                                                        |
| 509 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );  | 
                                                        |
| 510 | - return $html;  | 
                                                        |
| 511 | - }  | 
                                                        |
| 512 | -  | 
                                                        |
| 513 | -  | 
                                                        |
| 514 | -  | 
                                                        |
| 515 | - /**  | 
                                                        |
| 516 | - * displaySubmitButton  | 
                                                        |
| 517 | - *  | 
                                                        |
| 518 | - * @param string $external_url  | 
                                                        |
| 519 | - * @return string  | 
                                                        |
| 520 | - * @throws EE_Error  | 
                                                        |
| 521 | - */  | 
                                                        |
| 522 | - public function displaySubmitButton($external_url = '')  | 
                                                        |
| 523 | -    { | 
                                                        |
| 524 | - $html = '';  | 
                                                        |
| 525 | -        if ( ! is_admin()) { | 
                                                        |
| 526 | - // standard TS displayed with submit button, ie: "Register Now"  | 
                                                        |
| 527 | -            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { | 
                                                        |
| 528 | - $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 529 | - $html .= empty($external_url)  | 
                                                        |
| 530 | - ? $this->ticketSelectorEndDiv()  | 
                                                        |
| 531 | - : $this->clearTicketSelector();  | 
                                                        |
| 532 | - $html .= '<br/>' . $this->formClose();  | 
                                                        |
| 533 | -            } elseif ($this->getMaxAttendees() === 1) { | 
                                                        |
| 534 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)  | 
                                                        |
| 535 | -                if ($this->event->is_sold_out()) { | 
                                                        |
| 536 | - // then instead of a View Details or Submit button, just display a "Sold Out" message  | 
                                                        |
| 537 | - $html .= apply_filters(  | 
                                                        |
| 538 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',  | 
                                                        |
| 539 | - sprintf(  | 
                                                        |
| 540 | - __(  | 
                                                        |
| 541 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',  | 
                                                        |
| 542 | - 'event_espresso'  | 
                                                        |
| 543 | - ),  | 
                                                        |
| 544 | - '<p class="no-ticket-selector-msg clear-float">',  | 
                                                        |
| 545 | - $this->event->name(),  | 
                                                        |
| 546 | - '</p>',  | 
                                                        |
| 547 | - '<br />'  | 
                                                        |
| 548 | - ),  | 
                                                        |
| 549 | - $this->event  | 
                                                        |
| 550 | - );  | 
                                                        |
| 551 | - if (  | 
                                                        |
| 552 | - apply_filters(  | 
                                                        |
| 553 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',  | 
                                                        |
| 554 | - false,  | 
                                                        |
| 555 | - $this->event  | 
                                                        |
| 556 | - )  | 
                                                        |
| 557 | -                    ) { | 
                                                        |
| 558 | - $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 559 | - }  | 
                                                        |
| 560 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content  | 
                                                        |
| 561 | - $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 562 | - } elseif (  | 
                                                        |
| 563 | -                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) | 
                                                        |
| 564 | - && ! is_single()  | 
                                                        |
| 565 | -                ) { | 
                                                        |
| 566 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,  | 
                                                        |
| 567 | - // but no tickets are available, so display event's "View Details" button.  | 
                                                        |
| 568 | - // it is being viewed via somewhere other than a single post  | 
                                                        |
| 569 | - $html .= $this->displayViewDetailsButton(true);  | 
                                                        |
| 570 | -                } else { | 
                                                        |
| 571 | - $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 572 | - }  | 
                                                        |
| 573 | -            } elseif (is_archive()) { | 
                                                        |
| 574 | - // event list, no tickets available so display event's "View Details" button  | 
                                                        |
| 575 | - $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 576 | - $html .= $this->displayViewDetailsButton();  | 
                                                        |
| 577 | -            } else { | 
                                                        |
| 578 | - if (  | 
                                                        |
| 579 | - apply_filters(  | 
                                                        |
| 580 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',  | 
                                                        |
| 581 | - false,  | 
                                                        |
| 582 | - $this->event  | 
                                                        |
| 583 | - )  | 
                                                        |
| 584 | -                ) { | 
                                                        |
| 585 | - $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 586 | - }  | 
                                                        |
| 587 | - // no submit or view details button, and no additional content  | 
                                                        |
| 588 | - $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 589 | - }  | 
                                                        |
| 590 | -            if ( ! $this->iframe && ! is_archive()) { | 
                                                        |
| 591 | -                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); | 
                                                        |
| 592 | - }  | 
                                                        |
| 593 | - }  | 
                                                        |
| 594 | - return apply_filters(  | 
                                                        |
| 595 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',  | 
                                                        |
| 596 | - $html,  | 
                                                        |
| 597 | - $this->event  | 
                                                        |
| 598 | - );  | 
                                                        |
| 599 | - }  | 
                                                        |
| 600 | -  | 
                                                        |
| 601 | -  | 
                                                        |
| 602 | -  | 
                                                        |
| 603 | - /**  | 
                                                        |
| 604 | - * @return string  | 
                                                        |
| 605 | - * @throws EE_Error  | 
                                                        |
| 606 | - */  | 
                                                        |
| 607 | - public function displayRegisterNowButton()  | 
                                                        |
| 608 | -    { | 
                                                        |
| 609 | - $btn_text = apply_filters(  | 
                                                        |
| 610 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',  | 
                                                        |
| 611 | -            __('Register Now', 'event_espresso'), | 
                                                        |
| 612 | - $this->event  | 
                                                        |
| 613 | - );  | 
                                                        |
| 614 | - $external_url = $this->event->external_url();  | 
                                                        |
| 615 | - $html = EEH_HTML::div(  | 
                                                        |
| 616 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'  | 
                                                        |
| 617 | - );  | 
                                                        |
| 618 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';  | 
                                                        |
| 619 | - $html .= ' class="ticket-selector-submit-btn ';  | 
                                                        |
| 620 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';  | 
                                                        |
| 621 | - $html .= ' type="submit" value="' . $btn_text . '" />';  | 
                                                        |
| 622 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';  | 
                                                        |
| 623 | - $html .= apply_filters(  | 
                                                        |
| 624 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',  | 
                                                        |
| 625 | - '',  | 
                                                        |
| 626 | - $this->event  | 
                                                        |
| 627 | - );  | 
                                                        |
| 628 | - return $html;  | 
                                                        |
| 629 | - }  | 
                                                        |
| 630 | -  | 
                                                        |
| 631 | -  | 
                                                        |
| 632 | - /**  | 
                                                        |
| 633 | - * displayViewDetailsButton  | 
                                                        |
| 634 | - *  | 
                                                        |
| 635 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event  | 
                                                        |
| 636 | - * (ie: $_max_atndz === 1) where there are no available tickets,  | 
                                                        |
| 637 | - * either because they are sold out, expired, or not yet on sale.  | 
                                                        |
| 638 | - * In this case, we need to close the form BEFORE adding any closing divs  | 
                                                        |
| 639 | - * @return string  | 
                                                        |
| 640 | - * @throws EE_Error  | 
                                                        |
| 641 | - */  | 
                                                        |
| 642 | - public function displayViewDetailsButton( $DWMTS = false )  | 
                                                        |
| 643 | -    { | 
                                                        |
| 644 | -        if ( ! $this->event->get_permalink() ) { | 
                                                        |
| 645 | - EE_Error::add_error(  | 
                                                        |
| 646 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 647 | - __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 648 | - );  | 
                                                        |
| 649 | - }  | 
                                                        |
| 650 | - $view_details_btn = '<form method="POST" action="';  | 
                                                        |
| 651 | - $view_details_btn .= apply_filters(  | 
                                                        |
| 652 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',  | 
                                                        |
| 653 | - $this->event->get_permalink(),  | 
                                                        |
| 654 | - $this->event  | 
                                                        |
| 655 | - );  | 
                                                        |
| 656 | - $view_details_btn .= '"';  | 
                                                        |
| 657 | - // open link in new window ?  | 
                                                        |
| 658 | - $view_details_btn .= apply_filters(  | 
                                                        |
| 659 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',  | 
                                                        |
| 660 | - EED_Events_Archive::is_iframe()  | 
                                                        |
| 661 | - )  | 
                                                        |
| 662 | - ? ' target="_blank"'  | 
                                                        |
| 663 | - : '';  | 
                                                        |
| 664 | - $view_details_btn .='>';  | 
                                                        |
| 665 | - $btn_text = apply_filters(  | 
                                                        |
| 666 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',  | 
                                                        |
| 667 | -            esc_html__('View Details', 'event_espresso'), | 
                                                        |
| 668 | - $this->event  | 
                                                        |
| 669 | - );  | 
                                                        |
| 670 | - $view_details_btn .= '<input id="ticket-selector-submit-'  | 
                                                        |
| 671 | - . $this->event->ID()  | 
                                                        |
| 672 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'  | 
                                                        |
| 673 | - . $btn_text  | 
                                                        |
| 674 | - . '" />';  | 
                                                        |
| 675 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );  | 
                                                        |
| 676 | -        if ($DWMTS) { | 
                                                        |
| 677 | - $view_details_btn .= $this->formClose();  | 
                                                        |
| 678 | - $view_details_btn .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 679 | - $view_details_btn .= '<br/>';  | 
                                                        |
| 680 | -        } else { | 
                                                        |
| 681 | - $view_details_btn .= $this->clearTicketSelector();  | 
                                                        |
| 682 | - $view_details_btn .= '<br/>';  | 
                                                        |
| 683 | - $view_details_btn .= $this->formClose();  | 
                                                        |
| 684 | - }  | 
                                                        |
| 685 | - return $view_details_btn;  | 
                                                        |
| 686 | - }  | 
                                                        |
| 687 | -  | 
                                                        |
| 688 | -  | 
                                                        |
| 689 | -  | 
                                                        |
| 690 | - /**  | 
                                                        |
| 691 | - * @return string  | 
                                                        |
| 692 | - */  | 
                                                        |
| 693 | - public function ticketSelectorEndDiv()  | 
                                                        |
| 694 | -    { | 
                                                        |
| 695 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';  | 
                                                        |
| 696 | - }  | 
                                                        |
| 697 | -  | 
                                                        |
| 698 | -  | 
                                                        |
| 699 | -  | 
                                                        |
| 700 | - /**  | 
                                                        |
| 701 | - * @return string  | 
                                                        |
| 702 | - */  | 
                                                        |
| 703 | - public function clearTicketSelector()  | 
                                                        |
| 704 | -    { | 
                                                        |
| 705 | - // standard TS displayed, appears after a "Register Now" or "view Details" button  | 
                                                        |
| 706 | - return '<div class="clear"></div><!-- clearTicketSelector -->';  | 
                                                        |
| 707 | - }  | 
                                                        |
| 708 | -  | 
                                                        |
| 709 | -  | 
                                                        |
| 710 | -  | 
                                                        |
| 711 | - /**  | 
                                                        |
| 712 | - * @access public  | 
                                                        |
| 713 | - * @return string  | 
                                                        |
| 714 | - */  | 
                                                        |
| 715 | - public function formClose()  | 
                                                        |
| 716 | -    { | 
                                                        |
| 717 | - return '</form>';  | 
                                                        |
| 718 | - }  | 
                                                        |
| 289 | + }  | 
                                                        |
| 290 | +  | 
                                                        |
| 291 | +  | 
                                                        |
| 292 | +  | 
                                                        |
| 293 | + /**  | 
                                                        |
| 294 | + * ticketSalesClosed  | 
                                                        |
| 295 | + * notice displayed if event ticket sales are turned off  | 
                                                        |
| 296 | + *  | 
                                                        |
| 297 | + * @return string  | 
                                                        |
| 298 | + * @throws EE_Error  | 
                                                        |
| 299 | + */  | 
                                                        |
| 300 | + protected function ticketSalesClosedMessage()  | 
                                                        |
| 301 | +	{ | 
                                                        |
| 302 | + $sales_closed_msg = esc_html__(  | 
                                                        |
| 303 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',  | 
                                                        |
| 304 | + 'event_espresso'  | 
                                                        |
| 305 | + );  | 
                                                        |
| 306 | +		if (current_user_can('edit_post', $this->event->ID())) { | 
                                                        |
| 307 | + $sales_closed_msg .= sprintf(  | 
                                                        |
| 308 | + esc_html__(  | 
                                                        |
| 309 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',  | 
                                                        |
| 310 | + 'event_espresso'  | 
                                                        |
| 311 | + ),  | 
                                                        |
| 312 | + '<div class="ee-attention" style="text-align: left;"><b>',  | 
                                                        |
| 313 | + '</b><br />',  | 
                                                        |
| 314 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',  | 
                                                        |
| 315 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'  | 
                                                        |
| 316 | + );  | 
                                                        |
| 317 | + }  | 
                                                        |
| 318 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';  | 
                                                        |
| 319 | + }  | 
                                                        |
| 320 | +  | 
                                                        |
| 321 | +  | 
                                                        |
| 322 | +  | 
                                                        |
| 323 | + /**  | 
                                                        |
| 324 | + * getTickets  | 
                                                        |
| 325 | + *  | 
                                                        |
| 326 | + * @return \EE_Base_Class[]|\EE_Ticket[]  | 
                                                        |
| 327 | + * @throws EE_Error  | 
                                                        |
| 328 | + */  | 
                                                        |
| 329 | + protected function getTickets()  | 
                                                        |
| 330 | +	{ | 
                                                        |
| 331 | + $ticket_query_args = array(  | 
                                                        |
| 332 | +			array('Datetime.EVT_ID' => $this->event->ID()), | 
                                                        |
| 333 | + 'order_by' => array(  | 
                                                        |
| 334 | + 'TKT_order' => 'ASC',  | 
                                                        |
| 335 | + 'TKT_required' => 'DESC',  | 
                                                        |
| 336 | + 'TKT_start_date' => 'ASC',  | 
                                                        |
| 337 | + 'TKT_end_date' => 'ASC',  | 
                                                        |
| 338 | + 'Datetime.DTT_EVT_start' => 'DESC',  | 
                                                        |
| 339 | + ),  | 
                                                        |
| 340 | + );  | 
                                                        |
| 341 | + if (  | 
                                                        |
| 342 | + ! (  | 
                                                        |
| 343 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config  | 
                                                        |
| 344 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets  | 
                                                        |
| 345 | + )  | 
                                                        |
| 346 | +		) { | 
                                                        |
| 347 | + //use the correct applicable time query depending on what version of core is being run.  | 
                                                        |
| 348 | +			$current_time = method_exists('EEM_Datetime', 'current_time_for_query') | 
                                                        |
| 349 | + ? time()  | 
                                                        |
| 350 | +				: current_time('timestamp'); | 
                                                        |
| 351 | +			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | + return EEM_Ticket::instance()->get_all($ticket_query_args);  | 
                                                        |
| 354 | + }  | 
                                                        |
| 355 | +  | 
                                                        |
| 356 | +  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | + /**  | 
                                                        |
| 359 | + * loadTicketSelector  | 
                                                        |
| 360 | + * begins to assemble template arguments  | 
                                                        |
| 361 | + * and decides whether to load a "simple" ticket selector, or the standard  | 
                                                        |
| 362 | + *  | 
                                                        |
| 363 | + * @param \EE_Ticket[] $tickets  | 
                                                        |
| 364 | + * @param array $template_args  | 
                                                        |
| 365 | + * @return string  | 
                                                        |
| 366 | + * @throws EE_Error  | 
                                                        |
| 367 | + */  | 
                                                        |
| 368 | + protected function loadTicketSelector(array $tickets, array $template_args)  | 
                                                        |
| 369 | +	{ | 
                                                        |
| 370 | + $template_args['event'] = $this->event;  | 
                                                        |
| 371 | + $template_args['EVT_ID'] = $this->event->ID();  | 
                                                        |
| 372 | + $template_args['event_is_expired'] = $this->event->is_expired();  | 
                                                        |
| 373 | + $template_args['max_atndz'] = $this->getMaxAttendees();  | 
                                                        |
| 374 | + $template_args['date_format'] = $this->date_format;  | 
                                                        |
| 375 | + $template_args['time_format'] = $this->time_format;  | 
                                                        |
| 376 | + /**  | 
                                                        |
| 377 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected  | 
                                                        |
| 378 | + *  | 
                                                        |
| 379 | + * @since 4.9.13  | 
                                                        |
| 380 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to  | 
                                                        |
| 381 | + * @param int $EVT_ID The Event ID  | 
                                                        |
| 382 | + */  | 
                                                        |
| 383 | + $template_args['anchor_id'] = apply_filters(  | 
                                                        |
| 384 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id',  | 
                                                        |
| 385 | + '#tkt-slctr-tbl-' . $this->event->ID(),  | 
                                                        |
| 386 | + $this->event->ID()  | 
                                                        |
| 387 | + );  | 
                                                        |
| 388 | + $template_args['tickets'] = $tickets;  | 
                                                        |
| 389 | + $template_args['ticket_count'] = count($tickets);  | 
                                                        |
| 390 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);  | 
                                                        |
| 391 | + return $ticket_selector instanceof TicketSelectorSimple  | 
                                                        |
| 392 | + ? $ticket_selector  | 
                                                        |
| 393 | + : new TicketSelectorStandard(  | 
                                                        |
| 394 | + $this->event,  | 
                                                        |
| 395 | + $tickets,  | 
                                                        |
| 396 | + $this->getMaxAttendees(),  | 
                                                        |
| 397 | + $template_args,  | 
                                                        |
| 398 | + $this->date_format,  | 
                                                        |
| 399 | + $this->time_format  | 
                                                        |
| 400 | + );  | 
                                                        |
| 401 | + }  | 
                                                        |
| 402 | +  | 
                                                        |
| 403 | +  | 
                                                        |
| 404 | +  | 
                                                        |
| 405 | + /**  | 
                                                        |
| 406 | + * simpleTicketSelector  | 
                                                        |
| 407 | + * there's one ticket, and max attendees is set to one,  | 
                                                        |
| 408 | + * so if the event is free, then this is a "simple" ticket selector  | 
                                                        |
| 409 | + * a.k.a. "Dude Where's my Ticket Selector?"  | 
                                                        |
| 410 | + *  | 
                                                        |
| 411 | + * @param \EE_Ticket[] $tickets  | 
                                                        |
| 412 | + * @param array $template_args  | 
                                                        |
| 413 | + * @return string  | 
                                                        |
| 414 | + * @throws EE_Error  | 
                                                        |
| 415 | + */  | 
                                                        |
| 416 | + protected function simpleTicketSelector($tickets, array $template_args)  | 
                                                        |
| 417 | +	{ | 
                                                        |
| 418 | + // if there is only ONE ticket with a max qty of ONE  | 
                                                        |
| 419 | +		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { | 
                                                        |
| 420 | + return '';  | 
                                                        |
| 421 | + }  | 
                                                        |
| 422 | + /** @var \EE_Ticket $ticket */  | 
                                                        |
| 423 | + $ticket = reset($tickets);  | 
                                                        |
| 424 | + // if the ticket is free... then not much need for the ticket selector  | 
                                                        |
| 425 | + if (  | 
                                                        |
| 426 | + apply_filters(  | 
                                                        |
| 427 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector',  | 
                                                        |
| 428 | + $ticket->is_free(),  | 
                                                        |
| 429 | + $this->event->ID()  | 
                                                        |
| 430 | + )  | 
                                                        |
| 431 | +		) { | 
                                                        |
| 432 | + return new TicketSelectorSimple(  | 
                                                        |
| 433 | + $this->event,  | 
                                                        |
| 434 | + $ticket,  | 
                                                        |
| 435 | + $this->getMaxAttendees(),  | 
                                                        |
| 436 | + $template_args  | 
                                                        |
| 437 | + );  | 
                                                        |
| 438 | + }  | 
                                                        |
| 439 | + return '';  | 
                                                        |
| 440 | + }  | 
                                                        |
| 441 | +  | 
                                                        |
| 442 | +  | 
                                                        |
| 443 | +  | 
                                                        |
| 444 | + /**  | 
                                                        |
| 445 | + * externalEventRegistration  | 
                                                        |
| 446 | + *  | 
                                                        |
| 447 | + * @return string  | 
                                                        |
| 448 | + */  | 
                                                        |
| 449 | + public function externalEventRegistration()  | 
                                                        |
| 450 | +	{ | 
                                                        |
| 451 | + // if not we still need to trigger the display of the submit button  | 
                                                        |
| 452 | +		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 453 | + //display notice to admin that registration is external  | 
                                                        |
| 454 | + return is_admin()  | 
                                                        |
| 455 | + ? esc_html__(  | 
                                                        |
| 456 | + 'Registration is at an external URL for this event.',  | 
                                                        |
| 457 | + 'event_espresso'  | 
                                                        |
| 458 | + )  | 
                                                        |
| 459 | + : '';  | 
                                                        |
| 460 | + }  | 
                                                        |
| 461 | +  | 
                                                        |
| 462 | +  | 
                                                        |
| 463 | +  | 
                                                        |
| 464 | + /**  | 
                                                        |
| 465 | + * formOpen  | 
                                                        |
| 466 | + *  | 
                                                        |
| 467 | + * @param int $ID  | 
                                                        |
| 468 | + * @param string $external_url  | 
                                                        |
| 469 | + * @return string  | 
                                                        |
| 470 | + */  | 
                                                        |
| 471 | + public function formOpen( $ID = 0, $external_url = '' )  | 
                                                        |
| 472 | +	{ | 
                                                        |
| 473 | + // if redirecting, we don't need any anything else  | 
                                                        |
| 474 | +		if ( $external_url ) { | 
                                                        |
| 475 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';  | 
                                                        |
| 476 | + // open link in new window ?  | 
                                                        |
| 477 | + $html .= apply_filters(  | 
                                                        |
| 478 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',  | 
                                                        |
| 479 | + EED_Events_Archive::is_iframe()  | 
                                                        |
| 480 | + )  | 
                                                        |
| 481 | + ? ' target="_blank"'  | 
                                                        |
| 482 | + : '';  | 
                                                        |
| 483 | + $html .= '>';  | 
                                                        |
| 484 | + $query_args = EEH_URL::get_query_string( $external_url );  | 
                                                        |
| 485 | +			foreach ( (array)$query_args as $query_arg => $value ) { | 
                                                        |
| 486 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';  | 
                                                        |
| 487 | + }  | 
                                                        |
| 488 | + return $html;  | 
                                                        |
| 489 | + }  | 
                                                        |
| 490 | + // if there is no submit button, then don't start building a form  | 
                                                        |
| 491 | + // because the "View Details" button will build its own form  | 
                                                        |
| 492 | +		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { | 
                                                        |
| 493 | + return '';  | 
                                                        |
| 494 | + }  | 
                                                        |
| 495 | + $checkout_url = EEH_Event_View::event_link_url( $ID );  | 
                                                        |
| 496 | +		if ( ! $checkout_url ) { | 
                                                        |
| 497 | + EE_Error::add_error(  | 
                                                        |
| 498 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 499 | + __FILE__,  | 
                                                        |
| 500 | + __FUNCTION__,  | 
                                                        |
| 501 | + __LINE__  | 
                                                        |
| 502 | + );  | 
                                                        |
| 503 | + }  | 
                                                        |
| 504 | + // set no cache headers and constants  | 
                                                        |
| 505 | + EE_System::do_not_cache();  | 
                                                        |
| 506 | + $extra_params = $this->iframe ? ' target="_blank"' : '';  | 
                                                        |
| 507 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';  | 
                                                        |
| 508 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';  | 
                                                        |
| 509 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );  | 
                                                        |
| 510 | + return $html;  | 
                                                        |
| 511 | + }  | 
                                                        |
| 512 | +  | 
                                                        |
| 513 | +  | 
                                                        |
| 514 | +  | 
                                                        |
| 515 | + /**  | 
                                                        |
| 516 | + * displaySubmitButton  | 
                                                        |
| 517 | + *  | 
                                                        |
| 518 | + * @param string $external_url  | 
                                                        |
| 519 | + * @return string  | 
                                                        |
| 520 | + * @throws EE_Error  | 
                                                        |
| 521 | + */  | 
                                                        |
| 522 | + public function displaySubmitButton($external_url = '')  | 
                                                        |
| 523 | +	{ | 
                                                        |
| 524 | + $html = '';  | 
                                                        |
| 525 | +		if ( ! is_admin()) { | 
                                                        |
| 526 | + // standard TS displayed with submit button, ie: "Register Now"  | 
                                                        |
| 527 | +			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { | 
                                                        |
| 528 | + $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 529 | + $html .= empty($external_url)  | 
                                                        |
| 530 | + ? $this->ticketSelectorEndDiv()  | 
                                                        |
| 531 | + : $this->clearTicketSelector();  | 
                                                        |
| 532 | + $html .= '<br/>' . $this->formClose();  | 
                                                        |
| 533 | +			} elseif ($this->getMaxAttendees() === 1) { | 
                                                        |
| 534 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)  | 
                                                        |
| 535 | +				if ($this->event->is_sold_out()) { | 
                                                        |
| 536 | + // then instead of a View Details or Submit button, just display a "Sold Out" message  | 
                                                        |
| 537 | + $html .= apply_filters(  | 
                                                        |
| 538 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',  | 
                                                        |
| 539 | + sprintf(  | 
                                                        |
| 540 | + __(  | 
                                                        |
| 541 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',  | 
                                                        |
| 542 | + 'event_espresso'  | 
                                                        |
| 543 | + ),  | 
                                                        |
| 544 | + '<p class="no-ticket-selector-msg clear-float">',  | 
                                                        |
| 545 | + $this->event->name(),  | 
                                                        |
| 546 | + '</p>',  | 
                                                        |
| 547 | + '<br />'  | 
                                                        |
| 548 | + ),  | 
                                                        |
| 549 | + $this->event  | 
                                                        |
| 550 | + );  | 
                                                        |
| 551 | + if (  | 
                                                        |
| 552 | + apply_filters(  | 
                                                        |
| 553 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',  | 
                                                        |
| 554 | + false,  | 
                                                        |
| 555 | + $this->event  | 
                                                        |
| 556 | + )  | 
                                                        |
| 557 | +					) { | 
                                                        |
| 558 | + $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 559 | + }  | 
                                                        |
| 560 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content  | 
                                                        |
| 561 | + $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 562 | + } elseif (  | 
                                                        |
| 563 | +					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) | 
                                                        |
| 564 | + && ! is_single()  | 
                                                        |
| 565 | +				) { | 
                                                        |
| 566 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,  | 
                                                        |
| 567 | + // but no tickets are available, so display event's "View Details" button.  | 
                                                        |
| 568 | + // it is being viewed via somewhere other than a single post  | 
                                                        |
| 569 | + $html .= $this->displayViewDetailsButton(true);  | 
                                                        |
| 570 | +				} else { | 
                                                        |
| 571 | + $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 572 | + }  | 
                                                        |
| 573 | +			} elseif (is_archive()) { | 
                                                        |
| 574 | + // event list, no tickets available so display event's "View Details" button  | 
                                                        |
| 575 | + $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 576 | + $html .= $this->displayViewDetailsButton();  | 
                                                        |
| 577 | +			} else { | 
                                                        |
| 578 | + if (  | 
                                                        |
| 579 | + apply_filters(  | 
                                                        |
| 580 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',  | 
                                                        |
| 581 | + false,  | 
                                                        |
| 582 | + $this->event  | 
                                                        |
| 583 | + )  | 
                                                        |
| 584 | +				) { | 
                                                        |
| 585 | + $html .= $this->displayRegisterNowButton();  | 
                                                        |
| 586 | + }  | 
                                                        |
| 587 | + // no submit or view details button, and no additional content  | 
                                                        |
| 588 | + $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 589 | + }  | 
                                                        |
| 590 | +			if ( ! $this->iframe && ! is_archive()) { | 
                                                        |
| 591 | +				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); | 
                                                        |
| 592 | + }  | 
                                                        |
| 593 | + }  | 
                                                        |
| 594 | + return apply_filters(  | 
                                                        |
| 595 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',  | 
                                                        |
| 596 | + $html,  | 
                                                        |
| 597 | + $this->event  | 
                                                        |
| 598 | + );  | 
                                                        |
| 599 | + }  | 
                                                        |
| 600 | +  | 
                                                        |
| 601 | +  | 
                                                        |
| 602 | +  | 
                                                        |
| 603 | + /**  | 
                                                        |
| 604 | + * @return string  | 
                                                        |
| 605 | + * @throws EE_Error  | 
                                                        |
| 606 | + */  | 
                                                        |
| 607 | + public function displayRegisterNowButton()  | 
                                                        |
| 608 | +	{ | 
                                                        |
| 609 | + $btn_text = apply_filters(  | 
                                                        |
| 610 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',  | 
                                                        |
| 611 | +			__('Register Now', 'event_espresso'), | 
                                                        |
| 612 | + $this->event  | 
                                                        |
| 613 | + );  | 
                                                        |
| 614 | + $external_url = $this->event->external_url();  | 
                                                        |
| 615 | + $html = EEH_HTML::div(  | 
                                                        |
| 616 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'  | 
                                                        |
| 617 | + );  | 
                                                        |
| 618 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';  | 
                                                        |
| 619 | + $html .= ' class="ticket-selector-submit-btn ';  | 
                                                        |
| 620 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';  | 
                                                        |
| 621 | + $html .= ' type="submit" value="' . $btn_text . '" />';  | 
                                                        |
| 622 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';  | 
                                                        |
| 623 | + $html .= apply_filters(  | 
                                                        |
| 624 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',  | 
                                                        |
| 625 | + '',  | 
                                                        |
| 626 | + $this->event  | 
                                                        |
| 627 | + );  | 
                                                        |
| 628 | + return $html;  | 
                                                        |
| 629 | + }  | 
                                                        |
| 630 | +  | 
                                                        |
| 631 | +  | 
                                                        |
| 632 | + /**  | 
                                                        |
| 633 | + * displayViewDetailsButton  | 
                                                        |
| 634 | + *  | 
                                                        |
| 635 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event  | 
                                                        |
| 636 | + * (ie: $_max_atndz === 1) where there are no available tickets,  | 
                                                        |
| 637 | + * either because they are sold out, expired, or not yet on sale.  | 
                                                        |
| 638 | + * In this case, we need to close the form BEFORE adding any closing divs  | 
                                                        |
| 639 | + * @return string  | 
                                                        |
| 640 | + * @throws EE_Error  | 
                                                        |
| 641 | + */  | 
                                                        |
| 642 | + public function displayViewDetailsButton( $DWMTS = false )  | 
                                                        |
| 643 | +	{ | 
                                                        |
| 644 | +		if ( ! $this->event->get_permalink() ) { | 
                                                        |
| 645 | + EE_Error::add_error(  | 
                                                        |
| 646 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 647 | + __FILE__, __FUNCTION__, __LINE__  | 
                                                        |
| 648 | + );  | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | + $view_details_btn = '<form method="POST" action="';  | 
                                                        |
| 651 | + $view_details_btn .= apply_filters(  | 
                                                        |
| 652 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',  | 
                                                        |
| 653 | + $this->event->get_permalink(),  | 
                                                        |
| 654 | + $this->event  | 
                                                        |
| 655 | + );  | 
                                                        |
| 656 | + $view_details_btn .= '"';  | 
                                                        |
| 657 | + // open link in new window ?  | 
                                                        |
| 658 | + $view_details_btn .= apply_filters(  | 
                                                        |
| 659 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',  | 
                                                        |
| 660 | + EED_Events_Archive::is_iframe()  | 
                                                        |
| 661 | + )  | 
                                                        |
| 662 | + ? ' target="_blank"'  | 
                                                        |
| 663 | + : '';  | 
                                                        |
| 664 | + $view_details_btn .='>';  | 
                                                        |
| 665 | + $btn_text = apply_filters(  | 
                                                        |
| 666 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',  | 
                                                        |
| 667 | +			esc_html__('View Details', 'event_espresso'), | 
                                                        |
| 668 | + $this->event  | 
                                                        |
| 669 | + );  | 
                                                        |
| 670 | + $view_details_btn .= '<input id="ticket-selector-submit-'  | 
                                                        |
| 671 | + . $this->event->ID()  | 
                                                        |
| 672 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'  | 
                                                        |
| 673 | + . $btn_text  | 
                                                        |
| 674 | + . '" />';  | 
                                                        |
| 675 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );  | 
                                                        |
| 676 | +		if ($DWMTS) { | 
                                                        |
| 677 | + $view_details_btn .= $this->formClose();  | 
                                                        |
| 678 | + $view_details_btn .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 679 | + $view_details_btn .= '<br/>';  | 
                                                        |
| 680 | +		} else { | 
                                                        |
| 681 | + $view_details_btn .= $this->clearTicketSelector();  | 
                                                        |
| 682 | + $view_details_btn .= '<br/>';  | 
                                                        |
| 683 | + $view_details_btn .= $this->formClose();  | 
                                                        |
| 684 | + }  | 
                                                        |
| 685 | + return $view_details_btn;  | 
                                                        |
| 686 | + }  | 
                                                        |
| 687 | +  | 
                                                        |
| 688 | +  | 
                                                        |
| 689 | +  | 
                                                        |
| 690 | + /**  | 
                                                        |
| 691 | + * @return string  | 
                                                        |
| 692 | + */  | 
                                                        |
| 693 | + public function ticketSelectorEndDiv()  | 
                                                        |
| 694 | +	{ | 
                                                        |
| 695 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';  | 
                                                        |
| 696 | + }  | 
                                                        |
| 697 | +  | 
                                                        |
| 698 | +  | 
                                                        |
| 699 | +  | 
                                                        |
| 700 | + /**  | 
                                                        |
| 701 | + * @return string  | 
                                                        |
| 702 | + */  | 
                                                        |
| 703 | + public function clearTicketSelector()  | 
                                                        |
| 704 | +	{ | 
                                                        |
| 705 | + // standard TS displayed, appears after a "Register Now" or "view Details" button  | 
                                                        |
| 706 | + return '<div class="clear"></div><!-- clearTicketSelector -->';  | 
                                                        |
| 707 | + }  | 
                                                        |
| 708 | +  | 
                                                        |
| 709 | +  | 
                                                        |
| 710 | +  | 
                                                        |
| 711 | + /**  | 
                                                        |
| 712 | + * @access public  | 
                                                        |
| 713 | + * @return string  | 
                                                        |
| 714 | + */  | 
                                                        |
| 715 | + public function formClose()  | 
                                                        |
| 716 | +	{ | 
                                                        |
| 717 | + return '</form>';  | 
                                                        |
| 718 | + }  | 
                                                        |
| 719 | 719 | |
| 720 | 720 | |
| 721 | 721 | |
@@ -16,8 +16,8 @@ discard block  | 
                                                    ||
| 16 | 16 | use EEM_Ticket;  | 
                                                        
| 17 | 17 | use WP_Post;  | 
                                                        
| 18 | 18 | |
| 19 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { | 
                                                        |
| 20 | - exit( 'No direct script access allowed' );  | 
                                                        |
| 19 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
                                                        |
| 20 | +    exit('No direct script access allowed'); | 
                                                        |
| 21 | 21 | }  | 
                                                        
| 22 | 22 | |
| 23 | 23 | |
@@ -88,9 +88,9 @@ discard block  | 
                                                    ||
| 88 | 88 | /**  | 
                                                        
| 89 | 89 | * @param boolean $iframe  | 
                                                        
| 90 | 90 | */  | 
                                                        
| 91 | - public function setIframe( $iframe = true )  | 
                                                        |
| 91 | + public function setIframe($iframe = true)  | 
                                                        |
| 92 | 92 |      { | 
                                                        
| 93 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );  | 
                                                        |
| 93 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);  | 
                                                        |
| 94 | 94 | }  | 
                                                        
| 95 | 95 | |
| 96 | 96 | |
@@ -101,28 +101,28 @@ discard block  | 
                                                    ||
| 101 | 101 | * @return bool  | 
                                                        
| 102 | 102 | * @throws EE_Error  | 
                                                        
| 103 | 103 | */  | 
                                                        
| 104 | - protected function setEvent( $event = null )  | 
                                                        |
| 104 | + protected function setEvent($event = null)  | 
                                                        |
| 105 | 105 |      { | 
                                                        
| 106 | -        if ( $event === null ) { | 
                                                        |
| 106 | +        if ($event === null) { | 
                                                        |
| 107 | 107 | global $post;  | 
                                                        
| 108 | 108 | $event = $post;  | 
                                                        
| 109 | 109 | }  | 
                                                        
| 110 | -        if ( $event instanceof EE_Event ) { | 
                                                        |
| 110 | +        if ($event instanceof EE_Event) { | 
                                                        |
| 111 | 111 | $this->event = $event;  | 
                                                        
| 112 | -        } elseif ( $event instanceof WP_Post ) { | 
                                                        |
| 113 | -            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { | 
                                                        |
| 112 | +        } elseif ($event instanceof WP_Post) { | 
                                                        |
| 113 | +            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { | 
                                                        |
| 114 | 114 | $this->event = $event->EE_Event;  | 
                                                        
| 115 | -            } elseif ( $event->post_type === 'espresso_events' ) { | 
                                                        |
| 116 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );  | 
                                                        |
| 115 | +            } elseif ($event->post_type === 'espresso_events') { | 
                                                        |
| 116 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);  | 
                                                        |
| 117 | 117 | $this->event = $event->EE_Event;  | 
                                                        
| 118 | 118 | }  | 
                                                        
| 119 | 119 |          } else { | 
                                                        
| 120 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );  | 
                                                        |
| 121 | - $dev_msg = $user_msg . __(  | 
                                                        |
| 120 | +            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); | 
                                                        |
| 121 | + $dev_msg = $user_msg.__(  | 
                                                        |
| 122 | 122 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',  | 
                                                        
| 123 | 123 | 'event_espresso'  | 
                                                        
| 124 | 124 | );  | 
                                                        
| 125 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );  | 
                                                        |
| 125 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 126 | 126 | return false;  | 
                                                        
| 127 | 127 | }  | 
                                                        
| 128 | 128 | return true;  | 
                                                        
@@ -163,17 +163,17 @@ discard block  | 
                                                    ||
| 163 | 163 | * @return string  | 
                                                        
| 164 | 164 | * @throws EE_Error  | 
                                                        
| 165 | 165 | */  | 
                                                        
| 166 | - public function display( $event = null, $view_details = false )  | 
                                                        |
| 166 | + public function display($event = null, $view_details = false)  | 
                                                        |
| 167 | 167 |      { | 
                                                        
| 168 | 168 | // reset filter for displaying submit button  | 
                                                        
| 169 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );  | 
                                                        |
| 169 | +        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 170 | 170 | // poke and prod incoming event till it tells us what it is  | 
                                                        
| 171 | -        if ( ! $this->setEvent( $event ) ) { | 
                                                        |
| 171 | +        if ( ! $this->setEvent($event)) { | 
                                                        |
| 172 | 172 | return false;  | 
                                                        
| 173 | 173 | }  | 
                                                        
| 174 | 174 | // begin gathering template arguments by getting event status  | 
                                                        
| 175 | - $template_args = array( 'event_status' => $this->event->get_active_status() );  | 
                                                        |
| 176 | -        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { | 
                                                        |
| 175 | +        $template_args = array('event_status' => $this->event->get_active_status()); | 
                                                        |
| 176 | +        if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) { | 
                                                        |
| 177 | 177 | return ! is_single() ? $this->displayViewDetailsButton() : '';  | 
                                                        
| 178 | 178 | }  | 
                                                        
| 179 | 179 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns  | 
                                                        
@@ -183,7 +183,7 @@ discard block  | 
                                                    ||
| 183 | 183 | }  | 
                                                        
| 184 | 184 | // is the event expired ?  | 
                                                        
| 185 | 185 | $template_args['event_is_expired'] = $this->event->is_expired();  | 
                                                        
| 186 | -        if ( $template_args[ 'event_is_expired' ] ) { | 
                                                        |
| 186 | +        if ($template_args['event_is_expired']) { | 
                                                        |
| 187 | 187 | return $this->expiredEventMessage();  | 
                                                        
| 188 | 188 | }  | 
                                                        
| 189 | 189 | // get all tickets for this event ordered by the datetime  | 
                                                        
@@ -191,7 +191,7 @@ discard block  | 
                                                    ||
| 191 | 191 |          if (count($tickets) < 1) { | 
                                                        
| 192 | 192 | return $this->noTicketAvailableMessage();  | 
                                                        
| 193 | 193 | }  | 
                                                        
| 194 | -        if (EED_Events_Archive::is_iframe()){ | 
                                                        |
| 194 | +        if (EED_Events_Archive::is_iframe()) { | 
                                                        |
| 195 | 195 | $this->setIframe();  | 
                                                        
| 196 | 196 | }  | 
                                                        
| 197 | 197 | // redirecting to another site for registration ??  | 
                                                        
@@ -199,10 +199,10 @@ discard block  | 
                                                    ||
| 199 | 199 | // if redirecting to another site for registration, then we don't load the TS  | 
                                                        
| 200 | 200 | $ticket_selector = $external_url  | 
                                                        
| 201 | 201 | ? $this->externalEventRegistration()  | 
                                                        
| 202 | - : $this->loadTicketSelector($tickets,$template_args);  | 
                                                        |
| 202 | + : $this->loadTicketSelector($tickets, $template_args);  | 
                                                        |
| 203 | 203 | // now set up the form (but not for the admin)  | 
                                                        
| 204 | 204 | $ticket_selector = ! is_admin()  | 
                                                        
| 205 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector  | 
                                                        |
| 205 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector  | 
                                                        |
| 206 | 206 | : $ticket_selector;  | 
                                                        
| 207 | 207 | // submit button and form close tag  | 
                                                        
| 208 | 208 | $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';  | 
                                                        
@@ -252,10 +252,10 @@ discard block  | 
                                                    ||
| 252 | 252 | */  | 
                                                        
| 253 | 253 | protected function expiredEventMessage()  | 
                                                        
| 254 | 254 |      { | 
                                                        
| 255 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(  | 
                                                        |
| 255 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(  | 
                                                        |
| 256 | 256 | 'We\'re sorry, but all tickets sales have ended because the event is expired.',  | 
                                                        
| 257 | 257 | 'event_espresso'  | 
                                                        
| 258 | - ) . '</span></div><!-- .ee-event-expired-notice -->';  | 
                                                        |
| 258 | + ).'</span></div><!-- .ee-event-expired-notice -->';  | 
                                                        |
| 259 | 259 | }  | 
                                                        
| 260 | 260 | |
| 261 | 261 | |
@@ -269,7 +269,7 @@ discard block  | 
                                                    ||
| 269 | 269 | */  | 
                                                        
| 270 | 270 | protected function noTicketAvailableMessage()  | 
                                                        
| 271 | 271 |      { | 
                                                        
| 272 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );  | 
                                                        |
| 272 | +        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); | 
                                                        |
| 273 | 273 |          if (current_user_can('edit_post', $this->event->ID())) { | 
                                                        
| 274 | 274 | $no_ticket_available_msg .= sprintf(  | 
                                                        
| 275 | 275 | esc_html__(  | 
                                                        
@@ -284,7 +284,7 @@ discard block  | 
                                                    ||
| 284 | 284 | }  | 
                                                        
| 285 | 285 | return '  | 
                                                        
| 286 | 286 | <div class="ee-event-expired-notice">  | 
                                                        
| 287 | - <span class="important-notice">' . $no_ticket_available_msg . '</span>  | 
                                                        |
| 287 | + <span class="important-notice">' . $no_ticket_available_msg.'</span>  | 
                                                        |
| 288 | 288 | </div><!-- .ee-event-expired-notice -->';  | 
                                                        
| 289 | 289 | }  | 
                                                        
| 290 | 290 | |
@@ -315,7 +315,7 @@ discard block  | 
                                                    ||
| 315 | 315 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'  | 
                                                        
| 316 | 316 | );  | 
                                                        
| 317 | 317 | }  | 
                                                        
| 318 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';  | 
                                                        |
| 318 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';  | 
                                                        |
| 319 | 319 | }  | 
                                                        
| 320 | 320 | |
| 321 | 321 | |
@@ -382,12 +382,12 @@ discard block  | 
                                                    ||
| 382 | 382 | */  | 
                                                        
| 383 | 383 | $template_args['anchor_id'] = apply_filters(  | 
                                                        
| 384 | 384 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id',  | 
                                                        
| 385 | - '#tkt-slctr-tbl-' . $this->event->ID(),  | 
                                                        |
| 385 | + '#tkt-slctr-tbl-'.$this->event->ID(),  | 
                                                        |
| 386 | 386 | $this->event->ID()  | 
                                                        
| 387 | 387 | );  | 
                                                        
| 388 | 388 | $template_args['tickets'] = $tickets;  | 
                                                        
| 389 | 389 | $template_args['ticket_count'] = count($tickets);  | 
                                                        
| 390 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);  | 
                                                        |
| 390 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);  | 
                                                        |
| 391 | 391 | return $ticket_selector instanceof TicketSelectorSimple  | 
                                                        
| 392 | 392 | ? $ticket_selector  | 
                                                        
| 393 | 393 | : new TicketSelectorStandard(  | 
                                                        
@@ -468,11 +468,11 @@ discard block  | 
                                                    ||
| 468 | 468 | * @param string $external_url  | 
                                                        
| 469 | 469 | * @return string  | 
                                                        
| 470 | 470 | */  | 
                                                        
| 471 | - public function formOpen( $ID = 0, $external_url = '' )  | 
                                                        |
| 471 | + public function formOpen($ID = 0, $external_url = '')  | 
                                                        |
| 472 | 472 |      { | 
                                                        
| 473 | 473 | // if redirecting, we don't need any anything else  | 
                                                        
| 474 | -        if ( $external_url ) { | 
                                                        |
| 475 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';  | 
                                                        |
| 474 | +        if ($external_url) { | 
                                                        |
| 475 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"';  | 
                                                        |
| 476 | 476 | // open link in new window ?  | 
                                                        
| 477 | 477 | $html .= apply_filters(  | 
                                                        
| 478 | 478 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',  | 
                                                        
@@ -481,21 +481,21 @@ discard block  | 
                                                    ||
| 481 | 481 | ? ' target="_blank"'  | 
                                                        
| 482 | 482 | : '';  | 
                                                        
| 483 | 483 | $html .= '>';  | 
                                                        
| 484 | - $query_args = EEH_URL::get_query_string( $external_url );  | 
                                                        |
| 485 | -            foreach ( (array)$query_args as $query_arg => $value ) { | 
                                                        |
| 486 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';  | 
                                                        |
| 484 | + $query_args = EEH_URL::get_query_string($external_url);  | 
                                                        |
| 485 | +            foreach ((array) $query_args as $query_arg => $value) { | 
                                                        |
| 486 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';  | 
                                                        |
| 487 | 487 | }  | 
                                                        
| 488 | 488 | return $html;  | 
                                                        
| 489 | 489 | }  | 
                                                        
| 490 | 490 | // if there is no submit button, then don't start building a form  | 
                                                        
| 491 | 491 | // because the "View Details" button will build its own form  | 
                                                        
| 492 | -        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { | 
                                                        |
| 492 | +        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { | 
                                                        |
| 493 | 493 | return '';  | 
                                                        
| 494 | 494 | }  | 
                                                        
| 495 | - $checkout_url = EEH_Event_View::event_link_url( $ID );  | 
                                                        |
| 496 | -        if ( ! $checkout_url ) { | 
                                                        |
| 495 | + $checkout_url = EEH_Event_View::event_link_url($ID);  | 
                                                        |
| 496 | +        if ( ! $checkout_url) { | 
                                                        |
| 497 | 497 | EE_Error::add_error(  | 
                                                        
| 498 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 498 | +                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), | 
                                                        |
| 499 | 499 | __FILE__,  | 
                                                        
| 500 | 500 | __FUNCTION__,  | 
                                                        
| 501 | 501 | __LINE__  | 
                                                        
@@ -504,9 +504,9 @@ discard block  | 
                                                    ||
| 504 | 504 | // set no cache headers and constants  | 
                                                        
| 505 | 505 | EE_System::do_not_cache();  | 
                                                        
| 506 | 506 | $extra_params = $this->iframe ? ' target="_blank"' : '';  | 
                                                        
| 507 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';  | 
                                                        |
| 507 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';  | 
                                                        |
| 508 | 508 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';  | 
                                                        
| 509 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );  | 
                                                        |
| 509 | +        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); | 
                                                        |
| 510 | 510 | return $html;  | 
                                                        
| 511 | 511 | }  | 
                                                        
| 512 | 512 | |
@@ -529,7 +529,7 @@ discard block  | 
                                                    ||
| 529 | 529 | $html .= empty($external_url)  | 
                                                        
| 530 | 530 | ? $this->ticketSelectorEndDiv()  | 
                                                        
| 531 | 531 | : $this->clearTicketSelector();  | 
                                                        
| 532 | - $html .= '<br/>' . $this->formClose();  | 
                                                        |
| 532 | + $html .= '<br/>'.$this->formClose();  | 
                                                        |
| 533 | 533 |              } elseif ($this->getMaxAttendees() === 1) { | 
                                                        
| 534 | 534 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)  | 
                                                        
| 535 | 535 |                  if ($this->event->is_sold_out()) { | 
                                                        
@@ -558,7 +558,7 @@ discard block  | 
                                                    ||
| 558 | 558 | $html .= $this->displayRegisterNowButton();  | 
                                                        
| 559 | 559 | }  | 
                                                        
| 560 | 560 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content  | 
                                                        
| 561 | - $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 561 | + $html .= $this->ticketSelectorEndDiv();  | 
                                                        |
| 562 | 562 | } elseif (  | 
                                                        
| 563 | 563 |                      apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) | 
                                                        
| 564 | 564 | && ! is_single()  | 
                                                        
@@ -613,13 +613,13 @@ discard block  | 
                                                    ||
| 613 | 613 | );  | 
                                                        
| 614 | 614 | $external_url = $this->event->external_url();  | 
                                                        
| 615 | 615 | $html = EEH_HTML::div(  | 
                                                        
| 616 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'  | 
                                                        |
| 616 | + '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap'  | 
                                                        |
| 617 | 617 | );  | 
                                                        
| 618 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';  | 
                                                        |
| 618 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';  | 
                                                        |
| 619 | 619 | $html .= ' class="ticket-selector-submit-btn ';  | 
                                                        
| 620 | 620 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';  | 
                                                        
| 621 | - $html .= ' type="submit" value="' . $btn_text . '" />';  | 
                                                        |
| 622 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';  | 
                                                        |
| 621 | + $html .= ' type="submit" value="'.$btn_text.'" />';  | 
                                                        |
| 622 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';  | 
                                                        |
| 623 | 623 | $html .= apply_filters(  | 
                                                        
| 624 | 624 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',  | 
                                                        
| 625 | 625 | '',  | 
                                                        
@@ -639,11 +639,11 @@ discard block  | 
                                                    ||
| 639 | 639 | * @return string  | 
                                                        
| 640 | 640 | * @throws EE_Error  | 
                                                        
| 641 | 641 | */  | 
                                                        
| 642 | - public function displayViewDetailsButton( $DWMTS = false )  | 
                                                        |
| 642 | + public function displayViewDetailsButton($DWMTS = false)  | 
                                                        |
| 643 | 643 |      { | 
                                                        
| 644 | -        if ( ! $this->event->get_permalink() ) { | 
                                                        |
| 644 | +        if ( ! $this->event->get_permalink()) { | 
                                                        |
| 645 | 645 | EE_Error::add_error(  | 
                                                        
| 646 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),  | 
                                                        |
| 646 | +                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), | 
                                                        |
| 647 | 647 | __FILE__, __FUNCTION__, __LINE__  | 
                                                        
| 648 | 648 | );  | 
                                                        
| 649 | 649 | }  | 
                                                        
@@ -661,7 +661,7 @@ discard block  | 
                                                    ||
| 661 | 661 | )  | 
                                                        
| 662 | 662 | ? ' target="_blank"'  | 
                                                        
| 663 | 663 | : '';  | 
                                                        
| 664 | - $view_details_btn .='>';  | 
                                                        |
| 664 | + $view_details_btn .= '>';  | 
                                                        |
| 665 | 665 | $btn_text = apply_filters(  | 
                                                        
| 666 | 666 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',  | 
                                                        
| 667 | 667 |              esc_html__('View Details', 'event_espresso'), | 
                                                        
@@ -672,7 +672,7 @@ discard block  | 
                                                    ||
| 672 | 672 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'  | 
                                                        
| 673 | 673 | . $btn_text  | 
                                                        
| 674 | 674 | . '" />';  | 
                                                        
| 675 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );  | 
                                                        |
| 675 | +        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); | 
                                                        |
| 676 | 676 |          if ($DWMTS) { | 
                                                        
| 677 | 677 | $view_details_btn .= $this->formClose();  | 
                                                        
| 678 | 678 | $view_details_btn .= $this->ticketSelectorEndDiv();  | 
                                                        
@@ -692,7 +692,7 @@ discard block  | 
                                                    ||
| 692 | 692 | */  | 
                                                        
| 693 | 693 | public function ticketSelectorEndDiv()  | 
                                                        
| 694 | 694 |      { | 
                                                        
| 695 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';  | 
                                                        |
| 695 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';  | 
                                                        |
| 696 | 696 | }  | 
                                                        
| 697 | 697 | |
| 698 | 698 | |
@@ -12,13 +12,13 @@ discard block  | 
                                                    ||
| 12 | 12 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>  | 
                                                        
| 13 | 13 | <?php  | 
                                                        
| 14 | 14 |  if ( $ticket instanceof EE_Ticket ) { | 
                                                        
| 15 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );  | 
                                                        |
| 16 | - $ticket_description .= ! empty( $ticket_description )  | 
                                                        |
| 17 | - ? '<br />' . $ticket_status_display  | 
                                                        |
| 18 | - : $ticket_status_display;  | 
                                                        |
| 19 | -    if (strpos( $ticket_description, '<div' ) === false) { | 
                                                        |
| 20 | -        $ticket_description = "<p>{$ticket_description}</p>"; | 
                                                        |
| 21 | - }  | 
                                                        |
| 15 | + do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );  | 
                                                        |
| 16 | + $ticket_description .= ! empty( $ticket_description )  | 
                                                        |
| 17 | + ? '<br />' . $ticket_status_display  | 
                                                        |
| 18 | + : $ticket_status_display;  | 
                                                        |
| 19 | +	if (strpos( $ticket_description, '<div' ) === false) { | 
                                                        |
| 20 | +		$ticket_description = "<p>{$ticket_description}</p>"; | 
                                                        |
| 21 | + }  | 
                                                        |
| 22 | 22 | ?>  | 
                                                        
| 23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">  | 
                                                        
| 24 | 24 | <div class="no-tkt-slctr-ticket-content-dv">  | 
                                                        
@@ -28,6 +28,6 @@ discard block  | 
                                                    ||
| 28 | 28 | <?php } ?>  | 
                                                        
| 29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv -->  | 
                                                        
| 30 | 30 | <?php  | 
                                                        
| 31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );  | 
                                                        |
| 31 | + do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );  | 
                                                        |
| 32 | 32 | }  | 
                                                        
| 33 | 33 | ?>  | 
                                                        
@@ -11,23 +11,23 @@  | 
                                                    ||
| 11 | 11 | <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/>  | 
                                                        
| 12 | 12 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>  | 
                                                        
| 13 | 13 | <?php  | 
                                                        
| 14 | -if ( $ticket instanceof EE_Ticket ) { | 
                                                        |
| 15 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );  | 
                                                        |
| 16 | - $ticket_description .= ! empty( $ticket_description )  | 
                                                        |
| 17 | - ? '<br />' . $ticket_status_display  | 
                                                        |
| 14 | +if ($ticket instanceof EE_Ticket) { | 
                                                        |
| 15 | +    do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event); | 
                                                        |
| 16 | + $ticket_description .= ! empty($ticket_description)  | 
                                                        |
| 17 | + ? '<br />'.$ticket_status_display  | 
                                                        |
| 18 | 18 | : $ticket_status_display;  | 
                                                        
| 19 | -    if (strpos( $ticket_description, '<div' ) === false) { | 
                                                        |
| 19 | +    if (strpos($ticket_description, '<div') === false) { | 
                                                        |
| 20 | 20 |          $ticket_description = "<p>{$ticket_description}</p>"; | 
                                                        
| 21 | 21 | }  | 
                                                        
| 22 | 22 | ?>  | 
                                                        
| 23 | 23 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">  | 
                                                        
| 24 | 24 | <div class="no-tkt-slctr-ticket-content-dv">  | 
                                                        
| 25 | 25 | <h5><?php echo $ticket->name(); ?></h5>  | 
                                                        
| 26 | -        <?php if ( ! empty( $ticket_description ) ) { ?> | 
                                                        |
| 26 | +        <?php if ( ! empty($ticket_description)) { ?> | 
                                                        |
| 27 | 27 | <?php echo $ticket_description; ?>  | 
                                                        
| 28 | 28 | <?php } ?>  | 
                                                        
| 29 | 29 | </div><!-- .no-tkt-slctr-ticket-content-dv -->  | 
                                                        
| 30 | 30 | <?php  | 
                                                        
| 31 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );  | 
                                                        |
| 31 | +    do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); | 
                                                        |
| 32 | 32 | }  | 
                                                        
| 33 | 33 | ?>  | 
                                                        
@@ -18,29 +18,29 @@  | 
                                                    ||
| 18 | 18 | class TicketSelectorRowSimple extends TicketSelectorRow  | 
                                                        
| 19 | 19 |  { | 
                                                        
| 20 | 20 | |
| 21 | - /**  | 
                                                        |
| 22 | - * @throws EE_Error  | 
                                                        |
| 23 | - */  | 
                                                        |
| 24 | - public function setupTicketStatusDisplay()  | 
                                                        |
| 25 | -    { | 
                                                        |
| 26 | - $remaining = $this->ticket->remaining();  | 
                                                        |
| 27 | - $this->setTicketMinAndMax($remaining);  | 
                                                        |
| 28 | - $this->setTicketStatusClasses($remaining);  | 
                                                        |
| 29 | - $this->setTicketStatusDisplay($remaining);  | 
                                                        |
| 30 | - }  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | -  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - public function getTicketDescription()  | 
                                                        |
| 35 | -    { | 
                                                        |
| 36 | - $filtered_row_content = $this->getFilteredRowContents();  | 
                                                        |
| 37 | -        if($filtered_row_content !== false) { | 
                                                        |
| 38 | -            remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 39 | -            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_false'); | 
                                                        |
| 40 | - return $filtered_row_content;  | 
                                                        |
| 41 | - }  | 
                                                        |
| 42 | - return $this->ticket->description();  | 
                                                        |
| 43 | - }  | 
                                                        |
| 21 | + /**  | 
                                                        |
| 22 | + * @throws EE_Error  | 
                                                        |
| 23 | + */  | 
                                                        |
| 24 | + public function setupTicketStatusDisplay()  | 
                                                        |
| 25 | +	{ | 
                                                        |
| 26 | + $remaining = $this->ticket->remaining();  | 
                                                        |
| 27 | + $this->setTicketMinAndMax($remaining);  | 
                                                        |
| 28 | + $this->setTicketStatusClasses($remaining);  | 
                                                        |
| 29 | + $this->setTicketStatusDisplay($remaining);  | 
                                                        |
| 30 | + }  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | +  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + public function getTicketDescription()  | 
                                                        |
| 35 | +	{ | 
                                                        |
| 36 | + $filtered_row_content = $this->getFilteredRowContents();  | 
                                                        |
| 37 | +		if($filtered_row_content !== false) { | 
                                                        |
| 38 | +			remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        |
| 39 | +			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_false'); | 
                                                        |
| 40 | + return $filtered_row_content;  | 
                                                        |
| 41 | + }  | 
                                                        |
| 42 | + return $this->ticket->description();  | 
                                                        |
| 43 | + }  | 
                                                        |
| 44 | 44 | |
| 45 | 45 | }  | 
                                                        
| 46 | 46 | // End of file TicketSelectorRowSimple.php  | 
                                                        
@@ -34,7 +34,7 @@  | 
                                                    ||
| 34 | 34 | public function getTicketDescription()  | 
                                                        
| 35 | 35 |      { | 
                                                        
| 36 | 36 | $filtered_row_content = $this->getFilteredRowContents();  | 
                                                        
| 37 | -        if($filtered_row_content !== false) { | 
                                                        |
| 37 | +        if ($filtered_row_content !== false) { | 
                                                        |
| 38 | 38 |              remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); | 
                                                        
| 39 | 39 |              add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_false'); | 
                                                        
| 40 | 40 | return $filtered_row_content;  |