@@ -10,429 +10,429 @@ |
||
| 10 | 10 | class EEM_Question extends EEM_Soft_Delete_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - // constant used to indicate that the question type is COUNTRY |
|
| 14 | - const QST_type_country = 'COUNTRY'; |
|
| 15 | - |
|
| 16 | - // constant used to indicate that the question type is DATE |
|
| 17 | - const QST_type_date = 'DATE'; |
|
| 18 | - |
|
| 19 | - // constant used to indicate that the question type is DROPDOWN |
|
| 20 | - const QST_type_dropdown = 'DROPDOWN'; |
|
| 21 | - |
|
| 22 | - // constant used to indicate that the question type is CHECKBOX |
|
| 23 | - const QST_type_checkbox = 'CHECKBOX'; |
|
| 24 | - |
|
| 25 | - // constant used to indicate that the question type is RADIO_BTN |
|
| 26 | - const QST_type_radio = 'RADIO_BTN'; |
|
| 27 | - |
|
| 28 | - // constant used to indicate that the question type is STATE |
|
| 29 | - const QST_type_state = 'STATE'; |
|
| 30 | - |
|
| 31 | - // constant used to indicate that the question type is TEXT |
|
| 32 | - const QST_type_text = 'TEXT'; |
|
| 33 | - |
|
| 34 | - // constant used to indicate that the question type is TEXTAREA |
|
| 35 | - const QST_type_textarea = 'TEXTAREA'; |
|
| 36 | - |
|
| 37 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 38 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 39 | - |
|
| 40 | - // constant used to indicate that the question type is an email input |
|
| 41 | - const QST_type_email = 'EMAIL'; |
|
| 42 | - |
|
| 43 | - // constant used to indicate that the question type is a US-formatted phone number |
|
| 44 | - const QST_type_us_phone = 'US_PHONE'; |
|
| 45 | - |
|
| 46 | - // constant used to indicate that the question type is an integer (whole number) |
|
| 47 | - const QST_type_int = 'INTEGER'; |
|
| 48 | - |
|
| 49 | - // constant used to indicate that the question type is a decimal (float) |
|
| 50 | - const QST_type_decimal = 'DECIMAL'; |
|
| 51 | - |
|
| 52 | - // constant used to indicate that the question type is a valid URL |
|
| 53 | - const QST_type_url = 'URL'; |
|
| 54 | - |
|
| 55 | - // constant used to indicate that the question type is a YEAR |
|
| 56 | - const QST_type_year = 'YEAR'; |
|
| 57 | - |
|
| 58 | - // constant used to indicate that the question type is a multi-select |
|
| 59 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
| 63 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 64 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 65 | - * |
|
| 66 | - * @access protected |
|
| 67 | - * @var array $_question_type_categories { |
|
| 68 | - * @type string $text |
|
| 69 | - * @type string $single -answer-enum |
|
| 70 | - * @type string $multi -answer-enum |
|
| 71 | - * } |
|
| 72 | - */ |
|
| 73 | - protected $_question_type_categories = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 77 | - * |
|
| 78 | - * @access protected |
|
| 79 | - * @var array $_allowed_question_types |
|
| 80 | - */ |
|
| 81 | - protected $_allowed_question_types = array(); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * brief descriptions for all the question types |
|
| 85 | - * |
|
| 86 | - * @access protected |
|
| 87 | - * @var EEM_Question $_instance |
|
| 88 | - */ |
|
| 89 | - protected $_question_descriptions; |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Question types that should have an admin-defined max input length |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $question_types_with_max_lengh; |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - // private instance of the Attendee object |
|
| 100 | - protected static $_instance = null; |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * EEM_Question constructor. |
|
| 105 | - * |
|
| 106 | - * @param null $timezone |
|
| 107 | - */ |
|
| 108 | - protected function __construct($timezone = null) |
|
| 109 | - { |
|
| 110 | - $this->singular_item = __('Question', 'event_espresso'); |
|
| 111 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
| 112 | - $this->_allowed_question_types = apply_filters( |
|
| 113 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 114 | - array( |
|
| 115 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
| 116 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
| 117 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
| 118 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
| 119 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
| 120 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
| 121 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
| 122 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
| 123 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
| 124 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
| 125 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
| 126 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
| 127 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
| 128 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
| 129 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
| 130 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - $this->_question_descriptions = apply_filters( |
|
| 134 | - 'FHEE__EEM_Question__construct__question_descriptions', |
|
| 135 | - array( |
|
| 136 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
| 137 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
| 138 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 139 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
| 140 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
| 141 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 142 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
| 143 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
| 144 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 145 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 146 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 147 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
| 148 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 149 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
| 150 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 151 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
| 152 | - ) |
|
| 153 | - ); |
|
| 154 | - $this->_question_type_categories = (array) apply_filters( |
|
| 155 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 156 | - array( |
|
| 157 | - 'text' => array( |
|
| 158 | - EEM_Question::QST_type_text, |
|
| 159 | - EEM_Question::QST_type_textarea, |
|
| 160 | - EEM_Question::QST_type_date, |
|
| 161 | - EEM_Question::QST_type_html_textarea, |
|
| 162 | - EEM_Question::QST_type_email, |
|
| 163 | - EEM_Question::QST_type_us_phone, |
|
| 164 | - EEM_Question::QST_type_decimal, |
|
| 165 | - EEM_Question::QST_type_int, |
|
| 166 | - EEM_Question::QST_type_url, |
|
| 167 | - EEM_Question::QST_type_year |
|
| 168 | - ), |
|
| 169 | - 'single-answer-enum' => array( |
|
| 170 | - EEM_Question::QST_type_radio, |
|
| 171 | - EEM_Question::QST_type_dropdown |
|
| 172 | - ), |
|
| 173 | - 'multi-answer-enum' => array( |
|
| 174 | - EEM_Question::QST_type_checkbox, |
|
| 175 | - EEM_Question::QST_type_multi_select |
|
| 176 | - ) |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - $this->question_types_with_max_lengh = apply_filters( |
|
| 180 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 181 | - array( |
|
| 182 | - EEM_Question::QST_type_text, |
|
| 183 | - EEM_Question::QST_type_textarea, |
|
| 184 | - EEM_Question::QST_type_html_textarea |
|
| 185 | - ) |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - $this->_tables = array( |
|
| 189 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 190 | - ); |
|
| 191 | - $this->_fields = array( |
|
| 192 | - 'Question' => array( |
|
| 193 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
| 194 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
| 195 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 196 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 197 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 198 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
| 199 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 200 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
| 201 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 202 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
| 203 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
| 204 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - $this->_model_relations = array( |
|
| 208 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 209 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 210 | - 'Answer' => new EE_Has_Many_Relation(), |
|
| 211 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 212 | - // for QST_order column |
|
| 213 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 214 | - ); |
|
| 215 | - // this model is generally available for reading |
|
| 216 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 217 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 218 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 219 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 220 | - parent::__construct($timezone); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 225 | - * but they can be extended |
|
| 226 | - * @return string[] |
|
| 227 | - */ |
|
| 228 | - public function allowed_question_types() |
|
| 229 | - { |
|
| 230 | - return $this->_allowed_question_types; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Gets all the question types in the same category |
|
| 235 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 236 | - * @return string[] like EEM_Question::allowed_question_types() |
|
| 237 | - */ |
|
| 238 | - public function question_types_in_same_category($question_type) |
|
| 239 | - { |
|
| 240 | - $question_types = array($question_type); |
|
| 241 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 242 | - if (in_array($question_type, $question_types_in_category)) { |
|
| 243 | - $question_types = $question_types_in_category; |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Determines if the given question type is in the given question type category |
|
| 253 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 254 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 255 | - * @return boolean |
|
| 256 | - */ |
|
| 257 | - public function question_type_is_in_category($question_type, $category) |
|
| 258 | - { |
|
| 259 | - if (!isset($this->_question_type_categories[ $category ])) { |
|
| 260 | - return false; |
|
| 261 | - } |
|
| 262 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns all the question types in the given category |
|
| 268 | - * @param string $category |
|
| 269 | - * @return array|mixed |
|
| 270 | - */ |
|
| 271 | - public function question_types_in_category($category) |
|
| 272 | - { |
|
| 273 | - if (isset($this->_question_type_categories[ $category ])) { |
|
| 274 | - return $this->_question_type_categories[ $category ]; |
|
| 275 | - } |
|
| 276 | - return array(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Returns all the question types that should have question options |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function question_types_with_options() |
|
| 285 | - { |
|
| 286 | - return array_merge( |
|
| 287 | - $this->question_types_in_category('single-answer-enum'), |
|
| 288 | - $this->question_types_in_category('multi-answer-enum') |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Returns the question type categories 2d array |
|
| 294 | - * @return array see EEM_Question::_question_type_categories |
|
| 295 | - */ |
|
| 296 | - public function question_type_categories() |
|
| 297 | - { |
|
| 298 | - return $this->_question_type_categories; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 303 | - * identified by $system_question_group_id |
|
| 304 | - * @param string $system_question_group_id QSG_system |
|
| 305 | - * @return array of system question names (QST_system) |
|
| 306 | - */ |
|
| 307 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 308 | - { |
|
| 309 | - $question_system_ids = array(); |
|
| 310 | - switch ($system_question_group_id) { |
|
| 311 | - case EEM_Question_Group::system_personal: |
|
| 312 | - $question_system_ids = array( |
|
| 313 | - EEM_Attendee::system_question_fname, |
|
| 314 | - EEM_Attendee::system_question_lname, |
|
| 315 | - EEM_Attendee::system_question_email, |
|
| 316 | - EEM_Attendee::system_question_phone |
|
| 317 | - ); |
|
| 318 | - break; |
|
| 319 | - case EEM_Question_Group::system_address: |
|
| 320 | - $question_system_ids = array( |
|
| 321 | - EEM_Attendee::system_question_address, |
|
| 322 | - EEM_Attendee::system_question_address2, |
|
| 323 | - EEM_Attendee::system_question_city, |
|
| 324 | - EEM_Attendee::system_question_state, |
|
| 325 | - EEM_Attendee::system_question_country, |
|
| 326 | - EEM_Attendee::system_question_zip, |
|
| 327 | - EEM_Attendee::system_question_phone |
|
| 328 | - ); |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Returns an array of all the QST_system values that are required in the system question group |
|
| 336 | - * identified by $system_question_group_id |
|
| 337 | - * @param string $system_question_group_id QSG_system |
|
| 338 | - * @return array of system question names (QST_system) |
|
| 339 | - */ |
|
| 340 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 341 | - { |
|
| 342 | - $question_system_ids = null; |
|
| 343 | - switch ($system_question_group_id) { |
|
| 344 | - case EEM_Question_Group::system_personal: |
|
| 345 | - $question_system_ids = array( |
|
| 346 | - EEM_Attendee::system_question_fname, |
|
| 347 | - EEM_Attendee::system_question_email, |
|
| 348 | - ); |
|
| 349 | - break; |
|
| 350 | - default: |
|
| 351 | - $question_system_ids = array(); |
|
| 352 | - } |
|
| 353 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 359 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 360 | - * @param $QST_system |
|
| 361 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 362 | - */ |
|
| 363 | - public function get_Question_ID_from_system_string($QST_system) |
|
| 364 | - { |
|
| 365 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * searches the db for the question with the latest question order and returns that value. |
|
| 371 | - * @access public |
|
| 372 | - * @return int |
|
| 373 | - */ |
|
| 374 | - public function get_latest_question_order() |
|
| 375 | - { |
|
| 376 | - $columns_to_select = array( |
|
| 377 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
| 378 | - ); |
|
| 379 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 380 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Returns an array where keys are system question QST_system values, |
|
| 385 | - * and values are the highest question max the admin can set on the question |
|
| 386 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 387 | - * of 5, but no larger than 12) |
|
| 388 | - * @return array |
|
| 389 | - */ |
|
| 390 | - public function system_question_maxes() |
|
| 391 | - { |
|
| 392 | - return array( |
|
| 393 | - 'fname' => 45, |
|
| 394 | - 'lname' => 45, |
|
| 395 | - 'address' => 255, |
|
| 396 | - 'address2' => 255, |
|
| 397 | - 'city' => 45, |
|
| 398 | - 'zip' => 12, |
|
| 399 | - 'email' => 255, |
|
| 400 | - 'phone' => 45, |
|
| 401 | - ); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
| 406 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 407 | - * @param string $system_question_value |
|
| 408 | - * @return int|float |
|
| 409 | - */ |
|
| 410 | - public function absolute_max_for_system_question($system_question_value) |
|
| 411 | - { |
|
| 412 | - $maxes = $this->system_question_maxes(); |
|
| 413 | - if (isset($maxes[ $system_question_value ])) { |
|
| 414 | - return $maxes[ $system_question_value ]; |
|
| 415 | - } else { |
|
| 416 | - return EE_INF; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * @return array |
|
| 423 | - */ |
|
| 424 | - public function question_descriptions() |
|
| 425 | - { |
|
| 426 | - return $this->_question_descriptions; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Returns all the question types that should have an admin-defined max input length |
|
| 432 | - * @return array |
|
| 433 | - */ |
|
| 434 | - public function questionTypesWithMaxLength() |
|
| 435 | - { |
|
| 436 | - return (array) $this->question_types_with_max_lengh; |
|
| 437 | - } |
|
| 13 | + // constant used to indicate that the question type is COUNTRY |
|
| 14 | + const QST_type_country = 'COUNTRY'; |
|
| 15 | + |
|
| 16 | + // constant used to indicate that the question type is DATE |
|
| 17 | + const QST_type_date = 'DATE'; |
|
| 18 | + |
|
| 19 | + // constant used to indicate that the question type is DROPDOWN |
|
| 20 | + const QST_type_dropdown = 'DROPDOWN'; |
|
| 21 | + |
|
| 22 | + // constant used to indicate that the question type is CHECKBOX |
|
| 23 | + const QST_type_checkbox = 'CHECKBOX'; |
|
| 24 | + |
|
| 25 | + // constant used to indicate that the question type is RADIO_BTN |
|
| 26 | + const QST_type_radio = 'RADIO_BTN'; |
|
| 27 | + |
|
| 28 | + // constant used to indicate that the question type is STATE |
|
| 29 | + const QST_type_state = 'STATE'; |
|
| 30 | + |
|
| 31 | + // constant used to indicate that the question type is TEXT |
|
| 32 | + const QST_type_text = 'TEXT'; |
|
| 33 | + |
|
| 34 | + // constant used to indicate that the question type is TEXTAREA |
|
| 35 | + const QST_type_textarea = 'TEXTAREA'; |
|
| 36 | + |
|
| 37 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 38 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 39 | + |
|
| 40 | + // constant used to indicate that the question type is an email input |
|
| 41 | + const QST_type_email = 'EMAIL'; |
|
| 42 | + |
|
| 43 | + // constant used to indicate that the question type is a US-formatted phone number |
|
| 44 | + const QST_type_us_phone = 'US_PHONE'; |
|
| 45 | + |
|
| 46 | + // constant used to indicate that the question type is an integer (whole number) |
|
| 47 | + const QST_type_int = 'INTEGER'; |
|
| 48 | + |
|
| 49 | + // constant used to indicate that the question type is a decimal (float) |
|
| 50 | + const QST_type_decimal = 'DECIMAL'; |
|
| 51 | + |
|
| 52 | + // constant used to indicate that the question type is a valid URL |
|
| 53 | + const QST_type_url = 'URL'; |
|
| 54 | + |
|
| 55 | + // constant used to indicate that the question type is a YEAR |
|
| 56 | + const QST_type_year = 'YEAR'; |
|
| 57 | + |
|
| 58 | + // constant used to indicate that the question type is a multi-select |
|
| 59 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
| 63 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 64 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 65 | + * |
|
| 66 | + * @access protected |
|
| 67 | + * @var array $_question_type_categories { |
|
| 68 | + * @type string $text |
|
| 69 | + * @type string $single -answer-enum |
|
| 70 | + * @type string $multi -answer-enum |
|
| 71 | + * } |
|
| 72 | + */ |
|
| 73 | + protected $_question_type_categories = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 77 | + * |
|
| 78 | + * @access protected |
|
| 79 | + * @var array $_allowed_question_types |
|
| 80 | + */ |
|
| 81 | + protected $_allowed_question_types = array(); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * brief descriptions for all the question types |
|
| 85 | + * |
|
| 86 | + * @access protected |
|
| 87 | + * @var EEM_Question $_instance |
|
| 88 | + */ |
|
| 89 | + protected $_question_descriptions; |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Question types that should have an admin-defined max input length |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $question_types_with_max_lengh; |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + // private instance of the Attendee object |
|
| 100 | + protected static $_instance = null; |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * EEM_Question constructor. |
|
| 105 | + * |
|
| 106 | + * @param null $timezone |
|
| 107 | + */ |
|
| 108 | + protected function __construct($timezone = null) |
|
| 109 | + { |
|
| 110 | + $this->singular_item = __('Question', 'event_espresso'); |
|
| 111 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
| 112 | + $this->_allowed_question_types = apply_filters( |
|
| 113 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 114 | + array( |
|
| 115 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
| 116 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
| 117 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
| 118 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
| 119 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
| 120 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
| 121 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
| 122 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
| 123 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
| 124 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
| 125 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
| 126 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
| 127 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
| 128 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
| 129 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
| 130 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + $this->_question_descriptions = apply_filters( |
|
| 134 | + 'FHEE__EEM_Question__construct__question_descriptions', |
|
| 135 | + array( |
|
| 136 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
| 137 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
| 138 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 139 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
| 140 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
| 141 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 142 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
| 143 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
| 144 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 145 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 146 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 147 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
| 148 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 149 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
| 150 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 151 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
| 152 | + ) |
|
| 153 | + ); |
|
| 154 | + $this->_question_type_categories = (array) apply_filters( |
|
| 155 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 156 | + array( |
|
| 157 | + 'text' => array( |
|
| 158 | + EEM_Question::QST_type_text, |
|
| 159 | + EEM_Question::QST_type_textarea, |
|
| 160 | + EEM_Question::QST_type_date, |
|
| 161 | + EEM_Question::QST_type_html_textarea, |
|
| 162 | + EEM_Question::QST_type_email, |
|
| 163 | + EEM_Question::QST_type_us_phone, |
|
| 164 | + EEM_Question::QST_type_decimal, |
|
| 165 | + EEM_Question::QST_type_int, |
|
| 166 | + EEM_Question::QST_type_url, |
|
| 167 | + EEM_Question::QST_type_year |
|
| 168 | + ), |
|
| 169 | + 'single-answer-enum' => array( |
|
| 170 | + EEM_Question::QST_type_radio, |
|
| 171 | + EEM_Question::QST_type_dropdown |
|
| 172 | + ), |
|
| 173 | + 'multi-answer-enum' => array( |
|
| 174 | + EEM_Question::QST_type_checkbox, |
|
| 175 | + EEM_Question::QST_type_multi_select |
|
| 176 | + ) |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + $this->question_types_with_max_lengh = apply_filters( |
|
| 180 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 181 | + array( |
|
| 182 | + EEM_Question::QST_type_text, |
|
| 183 | + EEM_Question::QST_type_textarea, |
|
| 184 | + EEM_Question::QST_type_html_textarea |
|
| 185 | + ) |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + $this->_tables = array( |
|
| 189 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 190 | + ); |
|
| 191 | + $this->_fields = array( |
|
| 192 | + 'Question' => array( |
|
| 193 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
| 194 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
| 195 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 196 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 197 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 198 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
| 199 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 200 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
| 201 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 202 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
| 203 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
| 204 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + $this->_model_relations = array( |
|
| 208 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 209 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 210 | + 'Answer' => new EE_Has_Many_Relation(), |
|
| 211 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 212 | + // for QST_order column |
|
| 213 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 214 | + ); |
|
| 215 | + // this model is generally available for reading |
|
| 216 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 217 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 218 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 219 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 220 | + parent::__construct($timezone); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 225 | + * but they can be extended |
|
| 226 | + * @return string[] |
|
| 227 | + */ |
|
| 228 | + public function allowed_question_types() |
|
| 229 | + { |
|
| 230 | + return $this->_allowed_question_types; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Gets all the question types in the same category |
|
| 235 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 236 | + * @return string[] like EEM_Question::allowed_question_types() |
|
| 237 | + */ |
|
| 238 | + public function question_types_in_same_category($question_type) |
|
| 239 | + { |
|
| 240 | + $question_types = array($question_type); |
|
| 241 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 242 | + if (in_array($question_type, $question_types_in_category)) { |
|
| 243 | + $question_types = $question_types_in_category; |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Determines if the given question type is in the given question type category |
|
| 253 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 254 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 255 | + * @return boolean |
|
| 256 | + */ |
|
| 257 | + public function question_type_is_in_category($question_type, $category) |
|
| 258 | + { |
|
| 259 | + if (!isset($this->_question_type_categories[ $category ])) { |
|
| 260 | + return false; |
|
| 261 | + } |
|
| 262 | + return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns all the question types in the given category |
|
| 268 | + * @param string $category |
|
| 269 | + * @return array|mixed |
|
| 270 | + */ |
|
| 271 | + public function question_types_in_category($category) |
|
| 272 | + { |
|
| 273 | + if (isset($this->_question_type_categories[ $category ])) { |
|
| 274 | + return $this->_question_type_categories[ $category ]; |
|
| 275 | + } |
|
| 276 | + return array(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Returns all the question types that should have question options |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function question_types_with_options() |
|
| 285 | + { |
|
| 286 | + return array_merge( |
|
| 287 | + $this->question_types_in_category('single-answer-enum'), |
|
| 288 | + $this->question_types_in_category('multi-answer-enum') |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Returns the question type categories 2d array |
|
| 294 | + * @return array see EEM_Question::_question_type_categories |
|
| 295 | + */ |
|
| 296 | + public function question_type_categories() |
|
| 297 | + { |
|
| 298 | + return $this->_question_type_categories; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 303 | + * identified by $system_question_group_id |
|
| 304 | + * @param string $system_question_group_id QSG_system |
|
| 305 | + * @return array of system question names (QST_system) |
|
| 306 | + */ |
|
| 307 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 308 | + { |
|
| 309 | + $question_system_ids = array(); |
|
| 310 | + switch ($system_question_group_id) { |
|
| 311 | + case EEM_Question_Group::system_personal: |
|
| 312 | + $question_system_ids = array( |
|
| 313 | + EEM_Attendee::system_question_fname, |
|
| 314 | + EEM_Attendee::system_question_lname, |
|
| 315 | + EEM_Attendee::system_question_email, |
|
| 316 | + EEM_Attendee::system_question_phone |
|
| 317 | + ); |
|
| 318 | + break; |
|
| 319 | + case EEM_Question_Group::system_address: |
|
| 320 | + $question_system_ids = array( |
|
| 321 | + EEM_Attendee::system_question_address, |
|
| 322 | + EEM_Attendee::system_question_address2, |
|
| 323 | + EEM_Attendee::system_question_city, |
|
| 324 | + EEM_Attendee::system_question_state, |
|
| 325 | + EEM_Attendee::system_question_country, |
|
| 326 | + EEM_Attendee::system_question_zip, |
|
| 327 | + EEM_Attendee::system_question_phone |
|
| 328 | + ); |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Returns an array of all the QST_system values that are required in the system question group |
|
| 336 | + * identified by $system_question_group_id |
|
| 337 | + * @param string $system_question_group_id QSG_system |
|
| 338 | + * @return array of system question names (QST_system) |
|
| 339 | + */ |
|
| 340 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 341 | + { |
|
| 342 | + $question_system_ids = null; |
|
| 343 | + switch ($system_question_group_id) { |
|
| 344 | + case EEM_Question_Group::system_personal: |
|
| 345 | + $question_system_ids = array( |
|
| 346 | + EEM_Attendee::system_question_fname, |
|
| 347 | + EEM_Attendee::system_question_email, |
|
| 348 | + ); |
|
| 349 | + break; |
|
| 350 | + default: |
|
| 351 | + $question_system_ids = array(); |
|
| 352 | + } |
|
| 353 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 359 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 360 | + * @param $QST_system |
|
| 361 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 362 | + */ |
|
| 363 | + public function get_Question_ID_from_system_string($QST_system) |
|
| 364 | + { |
|
| 365 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * searches the db for the question with the latest question order and returns that value. |
|
| 371 | + * @access public |
|
| 372 | + * @return int |
|
| 373 | + */ |
|
| 374 | + public function get_latest_question_order() |
|
| 375 | + { |
|
| 376 | + $columns_to_select = array( |
|
| 377 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
| 378 | + ); |
|
| 379 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 380 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Returns an array where keys are system question QST_system values, |
|
| 385 | + * and values are the highest question max the admin can set on the question |
|
| 386 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 387 | + * of 5, but no larger than 12) |
|
| 388 | + * @return array |
|
| 389 | + */ |
|
| 390 | + public function system_question_maxes() |
|
| 391 | + { |
|
| 392 | + return array( |
|
| 393 | + 'fname' => 45, |
|
| 394 | + 'lname' => 45, |
|
| 395 | + 'address' => 255, |
|
| 396 | + 'address2' => 255, |
|
| 397 | + 'city' => 45, |
|
| 398 | + 'zip' => 12, |
|
| 399 | + 'email' => 255, |
|
| 400 | + 'phone' => 45, |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
| 406 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 407 | + * @param string $system_question_value |
|
| 408 | + * @return int|float |
|
| 409 | + */ |
|
| 410 | + public function absolute_max_for_system_question($system_question_value) |
|
| 411 | + { |
|
| 412 | + $maxes = $this->system_question_maxes(); |
|
| 413 | + if (isset($maxes[ $system_question_value ])) { |
|
| 414 | + return $maxes[ $system_question_value ]; |
|
| 415 | + } else { |
|
| 416 | + return EE_INF; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @return array |
|
| 423 | + */ |
|
| 424 | + public function question_descriptions() |
|
| 425 | + { |
|
| 426 | + return $this->_question_descriptions; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Returns all the question types that should have an admin-defined max input length |
|
| 432 | + * @return array |
|
| 433 | + */ |
|
| 434 | + public function questionTypesWithMaxLength() |
|
| 435 | + { |
|
| 436 | + return (array) $this->question_types_with_max_lengh; |
|
| 437 | + } |
|
| 438 | 438 | } |
@@ -16,1335 +16,1335 @@ |
||
| 16 | 16 | class EED_Messages extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This holds the EE_messages controller |
|
| 21 | - * |
|
| 22 | - * @deprecated 4.9.0 |
|
| 23 | - * @var EE_messages $_EEMSG |
|
| 24 | - */ |
|
| 25 | - protected static $_EEMSG; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | - */ |
|
| 30 | - protected static $_message_resource_manager; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This holds the EE_Messages_Processor business class. |
|
| 34 | - * |
|
| 35 | - * @type EE_Messages_Processor |
|
| 36 | - */ |
|
| 37 | - protected static $_MSG_PROCESSOR; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * holds all the paths for various messages components. |
|
| 41 | - * Utilized by autoloader registry |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - protected static $_MSG_PATHS; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | - * Format is: |
|
| 51 | - * array( |
|
| 52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | - * ) |
|
| 54 | - * |
|
| 55 | - * @var EE_Messages_Template_Pack[] |
|
| 56 | - */ |
|
| 57 | - protected static $_TMP_PACKS = array(); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return EED_Messages |
|
| 62 | - */ |
|
| 63 | - public static function instance() |
|
| 64 | - { |
|
| 65 | - return parent::get_instance(__CLASS__); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | - * |
|
| 72 | - * @since 4.5.0 |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public static function set_hooks() |
|
| 76 | - { |
|
| 77 | - // actions |
|
| 78 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | - add_action( |
|
| 80 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | - array('EED_Messages', 'maybe_registration'), |
|
| 82 | - 10, |
|
| 83 | - 2 |
|
| 84 | - ); |
|
| 85 | - // filters |
|
| 86 | - add_filter( |
|
| 87 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | - 10, |
|
| 90 | - 4 |
|
| 91 | - ); |
|
| 92 | - add_filter( |
|
| 93 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | - 10, |
|
| 96 | - 4 |
|
| 97 | - ); |
|
| 98 | - // register routes |
|
| 99 | - self::_register_routes(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | - * |
|
| 105 | - * @access public |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public static function set_hooks_admin() |
|
| 109 | - { |
|
| 110 | - // actions |
|
| 111 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | - add_action( |
|
| 113 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | - array('EED_Messages', 'payment_reminder'), |
|
| 115 | - 10 |
|
| 116 | - ); |
|
| 117 | - add_action( |
|
| 118 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | - array('EED_Messages', 'maybe_registration'), |
|
| 120 | - 10, |
|
| 121 | - 3 |
|
| 122 | - ); |
|
| 123 | - add_action( |
|
| 124 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | - array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | - 10, |
|
| 127 | - 2 |
|
| 128 | - ); |
|
| 129 | - add_action( |
|
| 130 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | - array('EED_Messages', 'cancelled_registration'), |
|
| 132 | - 10 |
|
| 133 | - ); |
|
| 134 | - add_action( |
|
| 135 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | - array('EED_Messages', 'process_admin_payment'), |
|
| 137 | - 10, |
|
| 138 | - 1 |
|
| 139 | - ); |
|
| 140 | - // filters |
|
| 141 | - add_filter( |
|
| 142 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | - array('EED_Messages', 'process_resend'), |
|
| 144 | - 10, |
|
| 145 | - 2 |
|
| 146 | - ); |
|
| 147 | - add_filter( |
|
| 148 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | - 10, |
|
| 151 | - 4 |
|
| 152 | - ); |
|
| 153 | - add_filter( |
|
| 154 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | - 10, |
|
| 157 | - 4 |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * All the message triggers done by route go in here. |
|
| 164 | - * |
|
| 165 | - * @since 4.5.0 |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - protected static function _register_routes() |
|
| 169 | - { |
|
| 170 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * This is called when a browser display trigger is executed. |
|
| 180 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | - * browser. |
|
| 182 | - * |
|
| 183 | - * @since 4.9.0 |
|
| 184 | - * @param WP $WP |
|
| 185 | - * @throws EE_Error |
|
| 186 | - * @throws InvalidArgumentException |
|
| 187 | - * @throws ReflectionException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - */ |
|
| 191 | - public function browser_trigger($WP) |
|
| 192 | - { |
|
| 193 | - // ensure controller is loaded |
|
| 194 | - self::_load_controller(); |
|
| 195 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | - try { |
|
| 197 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | - } catch (EE_Error $e) { |
|
| 200 | - $error_msg = __( |
|
| 201 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ); |
|
| 204 | - // add specific message for developers if WP_DEBUG in on |
|
| 205 | - $error_msg .= '||' . $e->getMessage(); |
|
| 206 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * This is called when a browser error trigger is executed. |
|
| 213 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | - * message and display it. |
|
| 215 | - * |
|
| 216 | - * @since 4.9.0 |
|
| 217 | - * @param $WP |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws InvalidArgumentException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - */ |
|
| 223 | - public function browser_error_trigger($WP) |
|
| 224 | - { |
|
| 225 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | - if ($token) { |
|
| 227 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | - if ($message instanceof EE_Message) { |
|
| 229 | - header('HTTP/1.1 200 OK'); |
|
| 230 | - $error_msg = nl2br($message->error_message()); |
|
| 231 | - ?> |
|
| 19 | + /** |
|
| 20 | + * This holds the EE_messages controller |
|
| 21 | + * |
|
| 22 | + * @deprecated 4.9.0 |
|
| 23 | + * @var EE_messages $_EEMSG |
|
| 24 | + */ |
|
| 25 | + protected static $_EEMSG; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | + */ |
|
| 30 | + protected static $_message_resource_manager; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This holds the EE_Messages_Processor business class. |
|
| 34 | + * |
|
| 35 | + * @type EE_Messages_Processor |
|
| 36 | + */ |
|
| 37 | + protected static $_MSG_PROCESSOR; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * holds all the paths for various messages components. |
|
| 41 | + * Utilized by autoloader registry |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + protected static $_MSG_PATHS; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | + * Format is: |
|
| 51 | + * array( |
|
| 52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | + * ) |
|
| 54 | + * |
|
| 55 | + * @var EE_Messages_Template_Pack[] |
|
| 56 | + */ |
|
| 57 | + protected static $_TMP_PACKS = array(); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return EED_Messages |
|
| 62 | + */ |
|
| 63 | + public static function instance() |
|
| 64 | + { |
|
| 65 | + return parent::get_instance(__CLASS__); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | + * |
|
| 72 | + * @since 4.5.0 |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public static function set_hooks() |
|
| 76 | + { |
|
| 77 | + // actions |
|
| 78 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | + add_action( |
|
| 80 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | + array('EED_Messages', 'maybe_registration'), |
|
| 82 | + 10, |
|
| 83 | + 2 |
|
| 84 | + ); |
|
| 85 | + // filters |
|
| 86 | + add_filter( |
|
| 87 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | + 10, |
|
| 90 | + 4 |
|
| 91 | + ); |
|
| 92 | + add_filter( |
|
| 93 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | + 10, |
|
| 96 | + 4 |
|
| 97 | + ); |
|
| 98 | + // register routes |
|
| 99 | + self::_register_routes(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | + * |
|
| 105 | + * @access public |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public static function set_hooks_admin() |
|
| 109 | + { |
|
| 110 | + // actions |
|
| 111 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | + add_action( |
|
| 113 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | + array('EED_Messages', 'payment_reminder'), |
|
| 115 | + 10 |
|
| 116 | + ); |
|
| 117 | + add_action( |
|
| 118 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | + array('EED_Messages', 'maybe_registration'), |
|
| 120 | + 10, |
|
| 121 | + 3 |
|
| 122 | + ); |
|
| 123 | + add_action( |
|
| 124 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | + array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | + 10, |
|
| 127 | + 2 |
|
| 128 | + ); |
|
| 129 | + add_action( |
|
| 130 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | + array('EED_Messages', 'cancelled_registration'), |
|
| 132 | + 10 |
|
| 133 | + ); |
|
| 134 | + add_action( |
|
| 135 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | + array('EED_Messages', 'process_admin_payment'), |
|
| 137 | + 10, |
|
| 138 | + 1 |
|
| 139 | + ); |
|
| 140 | + // filters |
|
| 141 | + add_filter( |
|
| 142 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | + array('EED_Messages', 'process_resend'), |
|
| 144 | + 10, |
|
| 145 | + 2 |
|
| 146 | + ); |
|
| 147 | + add_filter( |
|
| 148 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | + 10, |
|
| 151 | + 4 |
|
| 152 | + ); |
|
| 153 | + add_filter( |
|
| 154 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | + 10, |
|
| 157 | + 4 |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * All the message triggers done by route go in here. |
|
| 164 | + * |
|
| 165 | + * @since 4.5.0 |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + protected static function _register_routes() |
|
| 169 | + { |
|
| 170 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * This is called when a browser display trigger is executed. |
|
| 180 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | + * browser. |
|
| 182 | + * |
|
| 183 | + * @since 4.9.0 |
|
| 184 | + * @param WP $WP |
|
| 185 | + * @throws EE_Error |
|
| 186 | + * @throws InvalidArgumentException |
|
| 187 | + * @throws ReflectionException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + */ |
|
| 191 | + public function browser_trigger($WP) |
|
| 192 | + { |
|
| 193 | + // ensure controller is loaded |
|
| 194 | + self::_load_controller(); |
|
| 195 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | + try { |
|
| 197 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | + } catch (EE_Error $e) { |
|
| 200 | + $error_msg = __( |
|
| 201 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ); |
|
| 204 | + // add specific message for developers if WP_DEBUG in on |
|
| 205 | + $error_msg .= '||' . $e->getMessage(); |
|
| 206 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * This is called when a browser error trigger is executed. |
|
| 213 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | + * message and display it. |
|
| 215 | + * |
|
| 216 | + * @since 4.9.0 |
|
| 217 | + * @param $WP |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws InvalidArgumentException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + */ |
|
| 223 | + public function browser_error_trigger($WP) |
|
| 224 | + { |
|
| 225 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | + if ($token) { |
|
| 227 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | + if ($message instanceof EE_Message) { |
|
| 229 | + header('HTTP/1.1 200 OK'); |
|
| 230 | + $error_msg = nl2br($message->error_message()); |
|
| 231 | + ?> |
|
| 232 | 232 | <!DOCTYPE html> |
| 233 | 233 | <html> |
| 234 | 234 | <head></head> |
| 235 | 235 | <body> |
| 236 | 236 | <?php echo empty($error_msg) |
| 237 | - ? esc_html__( |
|
| 238 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ) |
|
| 241 | - : wp_kses( |
|
| 242 | - $error_msg, |
|
| 243 | - array( |
|
| 244 | - 'a' => array( |
|
| 245 | - 'href' => array(), |
|
| 246 | - 'title' => array(), |
|
| 247 | - ), |
|
| 248 | - 'span' => array(), |
|
| 249 | - 'div' => array(), |
|
| 250 | - 'p' => array(), |
|
| 251 | - 'strong' => array(), |
|
| 252 | - 'em' => array(), |
|
| 253 | - 'br' => array(), |
|
| 254 | - ) |
|
| 255 | - ); ?> |
|
| 237 | + ? esc_html__( |
|
| 238 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ) |
|
| 241 | + : wp_kses( |
|
| 242 | + $error_msg, |
|
| 243 | + array( |
|
| 244 | + 'a' => array( |
|
| 245 | + 'href' => array(), |
|
| 246 | + 'title' => array(), |
|
| 247 | + ), |
|
| 248 | + 'span' => array(), |
|
| 249 | + 'div' => array(), |
|
| 250 | + 'p' => array(), |
|
| 251 | + 'strong' => array(), |
|
| 252 | + 'em' => array(), |
|
| 253 | + 'br' => array(), |
|
| 254 | + ) |
|
| 255 | + ); ?> |
|
| 256 | 256 | </body> |
| 257 | 257 | </html> |
| 258 | 258 | <?php |
| 259 | - exit; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * This runs when the msg_url_trigger route has initiated. |
|
| 268 | - * |
|
| 269 | - * @since 4.5.0 |
|
| 270 | - * @param WP $WP |
|
| 271 | - * @throws EE_Error |
|
| 272 | - * @throws InvalidArgumentException |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - * @throws InvalidDataTypeException |
|
| 275 | - * @throws InvalidInterfaceException |
|
| 276 | - */ |
|
| 277 | - public function run($WP) |
|
| 278 | - { |
|
| 279 | - // ensure controller is loaded |
|
| 280 | - self::_load_controller(); |
|
| 281 | - // attempt to process message |
|
| 282 | - try { |
|
| 283 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | - } catch (EE_Error $e) { |
|
| 287 | - $error_msg = __( |
|
| 288 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | - 'event_espresso' |
|
| 290 | - ); |
|
| 291 | - // add specific message for developers if WP_DEBUG in on |
|
| 292 | - $error_msg .= '||' . $e->getMessage(); |
|
| 293 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | - * |
|
| 301 | - * @param WP $WP |
|
| 302 | - */ |
|
| 303 | - public function execute_batch_request($WP) |
|
| 304 | - { |
|
| 305 | - $this->run_cron(); |
|
| 306 | - header('HTTP/1.1 200 OK'); |
|
| 307 | - exit(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | - * request. |
|
| 314 | - */ |
|
| 315 | - public function run_cron() |
|
| 316 | - { |
|
| 317 | - self::_load_controller(); |
|
| 318 | - // get required vars |
|
| 319 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | - |
|
| 322 | - // now let's verify transient, if not valid exit immediately |
|
| 323 | - if (! get_transient($transient_key)) { |
|
| 324 | - /** |
|
| 325 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | - * request. |
|
| 327 | - */ |
|
| 328 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | - delete_transient($transient_key); |
|
| 333 | - |
|
| 334 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | - self::$_MSG_PROCESSOR->$method(); |
|
| 338 | - } else { |
|
| 339 | - // no matching task |
|
| 340 | - /** |
|
| 341 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | - * request. |
|
| 343 | - */ |
|
| 344 | - trigger_error( |
|
| 345 | - esc_attr( |
|
| 346 | - sprintf( |
|
| 347 | - __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | - $cron_type |
|
| 349 | - ) |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * This is used to retrieve the template pack for the given name. |
|
| 361 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | - * the default template pack is returned. |
|
| 363 | - * |
|
| 364 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | - * in generating the Pack class name). |
|
| 367 | - * @return EE_Messages_Template_Pack |
|
| 368 | - * @throws EE_Error |
|
| 369 | - * @throws InvalidArgumentException |
|
| 370 | - * @throws ReflectionException |
|
| 371 | - * @throws InvalidDataTypeException |
|
| 372 | - * @throws InvalidInterfaceException |
|
| 373 | - */ |
|
| 374 | - public static function get_template_pack($template_pack_name) |
|
| 375 | - { |
|
| 376 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Retrieves an array of all template packs. |
|
| 383 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | - * |
|
| 385 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | - * @return EE_Messages_Template_Pack[] |
|
| 387 | - * @throws EE_Error |
|
| 388 | - * @throws InvalidArgumentException |
|
| 389 | - * @throws ReflectionException |
|
| 390 | - * @throws InvalidDataTypeException |
|
| 391 | - * @throws InvalidInterfaceException |
|
| 392 | - */ |
|
| 393 | - public static function get_template_packs() |
|
| 394 | - { |
|
| 395 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | - |
|
| 397 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | - $template_pack_collection->rewind(); |
|
| 400 | - $template_packs = array(); |
|
| 401 | - while ($template_pack_collection->valid()) { |
|
| 402 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | - $template_pack_collection->next(); |
|
| 404 | - } |
|
| 405 | - return $template_packs; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | - * |
|
| 412 | - * @since 4.5.0 |
|
| 413 | - * @return void |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public static function set_autoloaders() |
|
| 417 | - { |
|
| 418 | - if (empty(self::$_MSG_PATHS)) { |
|
| 419 | - self::_set_messages_paths(); |
|
| 420 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | - } |
|
| 423 | - // add aliases |
|
| 424 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | - * for use by the Messages Autoloaders |
|
| 433 | - * |
|
| 434 | - * @since 4.5.0 |
|
| 435 | - * @return void. |
|
| 436 | - */ |
|
| 437 | - protected static function _set_messages_paths() |
|
| 438 | - { |
|
| 439 | - $dir_ref = array( |
|
| 440 | - 'messages/message_type', |
|
| 441 | - 'messages/messenger', |
|
| 442 | - 'messages/defaults', |
|
| 443 | - 'messages/defaults/email', |
|
| 444 | - 'messages/data_class', |
|
| 445 | - 'messages/validators', |
|
| 446 | - 'messages/validators/email', |
|
| 447 | - 'messages/validators/html', |
|
| 448 | - 'shortcodes', |
|
| 449 | - ); |
|
| 450 | - $paths = array(); |
|
| 451 | - foreach ($dir_ref as $index => $dir) { |
|
| 452 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 453 | - } |
|
| 454 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Takes care of loading dependencies |
|
| 460 | - * |
|
| 461 | - * @since 4.5.0 |
|
| 462 | - * @return void |
|
| 463 | - * @throws EE_Error |
|
| 464 | - * @throws InvalidArgumentException |
|
| 465 | - * @throws ReflectionException |
|
| 466 | - * @throws InvalidDataTypeException |
|
| 467 | - * @throws InvalidInterfaceException |
|
| 468 | - */ |
|
| 469 | - protected static function _load_controller() |
|
| 470 | - { |
|
| 471 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 472 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 473 | - self::set_autoloaders(); |
|
| 474 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 475 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 476 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param EE_Transaction $transaction |
|
| 483 | - * @throws EE_Error |
|
| 484 | - * @throws InvalidArgumentException |
|
| 485 | - * @throws InvalidDataTypeException |
|
| 486 | - * @throws InvalidInterfaceException |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 490 | - { |
|
| 491 | - self::_load_controller(); |
|
| 492 | - $data = array($transaction, null); |
|
| 493 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 499 | - * |
|
| 500 | - * @param EE_Transaction $transaction object |
|
| 501 | - * @param EE_Payment|null $payment object |
|
| 502 | - * @return void |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws InvalidArgumentException |
|
| 505 | - * @throws ReflectionException |
|
| 506 | - * @throws InvalidDataTypeException |
|
| 507 | - * @throws InvalidInterfaceException |
|
| 508 | - */ |
|
| 509 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 510 | - { |
|
| 511 | - // if there's no payment object, then we cannot do a payment type message! |
|
| 512 | - if (! $payment instanceof EE_Payment) { |
|
| 513 | - return; |
|
| 514 | - } |
|
| 515 | - self::_load_controller(); |
|
| 516 | - $data = array($transaction, $payment); |
|
| 517 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 518 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 519 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 520 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 521 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @param EE_Transaction $transaction |
|
| 527 | - * @throws EE_Error |
|
| 528 | - * @throws InvalidArgumentException |
|
| 529 | - * @throws InvalidDataTypeException |
|
| 530 | - * @throws InvalidInterfaceException |
|
| 531 | - * @throws ReflectionException |
|
| 532 | - */ |
|
| 533 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 534 | - { |
|
| 535 | - self::_load_controller(); |
|
| 536 | - $data = array($transaction, null); |
|
| 537 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Trigger for Registration messages |
|
| 543 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 544 | - * incoming transaction. |
|
| 545 | - * |
|
| 546 | - * @param EE_Registration $registration |
|
| 547 | - * @param array $extra_details |
|
| 548 | - * @return void |
|
| 549 | - * @throws EE_Error |
|
| 550 | - * @throws InvalidArgumentException |
|
| 551 | - * @throws InvalidDataTypeException |
|
| 552 | - * @throws InvalidInterfaceException |
|
| 553 | - * @throws ReflectionException |
|
| 554 | - * @throws EntityNotFoundException |
|
| 555 | - */ |
|
| 556 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 557 | - { |
|
| 558 | - |
|
| 559 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 560 | - // no messages please |
|
| 561 | - return; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 565 | - $all_registrations = $registration->transaction()->registrations( |
|
| 566 | - array( |
|
| 567 | - array('REG_deleted' => false), |
|
| 568 | - 'order_by' => array( |
|
| 569 | - 'Event.EVT_name' => 'ASC', |
|
| 570 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 571 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 572 | - ), |
|
| 573 | - ) |
|
| 574 | - ); |
|
| 575 | - // cached array of statuses so we only trigger messages once per status. |
|
| 576 | - $statuses_sent = array(); |
|
| 577 | - self::_load_controller(); |
|
| 578 | - $mtgs = array(); |
|
| 579 | - |
|
| 580 | - // loop through registrations and trigger messages once per status. |
|
| 581 | - foreach ($all_registrations as $reg) { |
|
| 582 | - // already triggered? |
|
| 583 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 584 | - continue; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 588 | - $mtgs = array_merge( |
|
| 589 | - $mtgs, |
|
| 590 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 591 | - $message_type, |
|
| 592 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 593 | - ) |
|
| 594 | - ); |
|
| 595 | - $statuses_sent[] = $reg->status_ID(); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if (count($statuses_sent) > 1) { |
|
| 599 | - $mtgs = array_merge( |
|
| 600 | - $mtgs, |
|
| 601 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 602 | - 'registration_summary', |
|
| 603 | - array($registration->transaction(), null) |
|
| 604 | - ) |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - // batch queue and initiate request |
|
| 609 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 610 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 616 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 617 | - * |
|
| 618 | - * @param EE_Registration $registration [description] |
|
| 619 | - * @param array $extra_details [description] |
|
| 620 | - * @return bool true = send away, false = nope halt the presses. |
|
| 621 | - */ |
|
| 622 | - protected static function _verify_registration_notification_send( |
|
| 623 | - EE_Registration $registration, |
|
| 624 | - $extra_details = array() |
|
| 625 | - ) { |
|
| 626 | - if (! $registration->is_primary_registrant()) { |
|
| 627 | - return false; |
|
| 628 | - } |
|
| 629 | - // first we check if we're in admin and not doing front ajax |
|
| 630 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 631 | - // make sure appropriate admin params are set for sending messages |
|
| 632 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 633 | - || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | - ) { |
|
| 635 | - // no messages sent please. |
|
| 636 | - return false; |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - // frontend request (either regular or via AJAX) |
|
| 640 | - // TXN is NOT finalized ? |
|
| 641 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 642 | - return false; |
|
| 643 | - } |
|
| 644 | - // return visit but nothing changed ??? |
|
| 645 | - if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 646 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 647 | - ) { |
|
| 648 | - return false; |
|
| 649 | - } |
|
| 650 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 651 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 652 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 653 | - ) { |
|
| 654 | - return false; |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - // release the kraken |
|
| 658 | - return true; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 664 | - * status id. |
|
| 665 | - * |
|
| 666 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 667 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 668 | - * @param string $reg_status |
|
| 669 | - * @return array |
|
| 670 | - * @throws EE_Error |
|
| 671 | - * @throws InvalidArgumentException |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - * @throws InvalidDataTypeException |
|
| 674 | - * @throws InvalidInterfaceException |
|
| 675 | - */ |
|
| 676 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 677 | - { |
|
| 678 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 679 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 680 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Simply returns the payment message type for the given payment status. |
|
| 687 | - * |
|
| 688 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 689 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 690 | - * @param string $payment_status The payment status being matched. |
|
| 691 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 692 | - * @throws EE_Error |
|
| 693 | - * @throws InvalidArgumentException |
|
| 694 | - * @throws ReflectionException |
|
| 695 | - * @throws InvalidDataTypeException |
|
| 696 | - * @throws InvalidInterfaceException |
|
| 697 | - */ |
|
| 698 | - protected static function _get_payment_message_type($payment_status) |
|
| 699 | - { |
|
| 700 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 701 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 702 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | - : false; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 709 | - * |
|
| 710 | - * @access public |
|
| 711 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 712 | - * @return bool success/fail |
|
| 713 | - * @throws EE_Error |
|
| 714 | - * @throws InvalidArgumentException |
|
| 715 | - * @throws InvalidDataTypeException |
|
| 716 | - * @throws InvalidInterfaceException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - */ |
|
| 719 | - public static function process_resend($req_data) |
|
| 720 | - { |
|
| 721 | - self::_load_controller(); |
|
| 722 | - |
|
| 723 | - // if $msgID in this request then skip to the new resend_message |
|
| 724 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 725 | - return self::resend_message(); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 729 | - $req_data = (array) $req_data; |
|
| 730 | - foreach ($req_data as $request_key => $request_value) { |
|
| 731 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 735 | - )) { |
|
| 736 | - return false; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - try { |
|
| 740 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 741 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 742 | - } catch (EE_Error $e) { |
|
| 743 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - EE_Error::add_success( |
|
| 747 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 748 | - ); |
|
| 749 | - return true; // everything got queued. |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 755 | - * |
|
| 756 | - * @return bool |
|
| 757 | - * @throws EE_Error |
|
| 758 | - * @throws InvalidArgumentException |
|
| 759 | - * @throws InvalidDataTypeException |
|
| 760 | - * @throws InvalidInterfaceException |
|
| 761 | - * @throws ReflectionException |
|
| 762 | - */ |
|
| 763 | - public static function resend_message() |
|
| 764 | - { |
|
| 765 | - self::_load_controller(); |
|
| 766 | - |
|
| 767 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 768 | - if (! $msgID) { |
|
| 769 | - EE_Error::add_error( |
|
| 770 | - __( |
|
| 771 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 772 | - 'event_espresso' |
|
| 773 | - ), |
|
| 774 | - __FILE__, |
|
| 775 | - __FUNCTION__, |
|
| 776 | - __LINE__ |
|
| 777 | - ); |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 782 | - |
|
| 783 | - // setup success message. |
|
| 784 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 785 | - EE_Error::add_success( |
|
| 786 | - sprintf( |
|
| 787 | - _n( |
|
| 788 | - 'There was %d message queued for resending.', |
|
| 789 | - 'There were %d messages queued for resending.', |
|
| 790 | - $count_ready_for_resend, |
|
| 791 | - 'event_espresso' |
|
| 792 | - ), |
|
| 793 | - $count_ready_for_resend |
|
| 794 | - ) |
|
| 795 | - ); |
|
| 796 | - return true; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Message triggers for manual payment applied by admin |
|
| 802 | - * |
|
| 803 | - * @param EE_Payment $payment EE_payment object |
|
| 804 | - * @return bool success/fail |
|
| 805 | - * @throws EE_Error |
|
| 806 | - * @throws InvalidArgumentException |
|
| 807 | - * @throws ReflectionException |
|
| 808 | - * @throws InvalidDataTypeException |
|
| 809 | - * @throws InvalidInterfaceException |
|
| 810 | - */ |
|
| 811 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 812 | - { |
|
| 813 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 814 | - // we need to get the transaction object |
|
| 815 | - $transaction = $payment->transaction(); |
|
| 816 | - if ($transaction instanceof EE_Transaction) { |
|
| 817 | - $data = array($transaction, $payment); |
|
| 818 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 819 | - |
|
| 820 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 821 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 822 | - |
|
| 823 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 824 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 825 | - ? false : $message_type; |
|
| 826 | - |
|
| 827 | - self::_load_controller(); |
|
| 828 | - |
|
| 829 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 830 | - |
|
| 831 | - // get count of queued for generation |
|
| 832 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 833 | - array( |
|
| 834 | - EEM_Message::status_incomplete, |
|
| 835 | - EEM_Message::status_idle, |
|
| 836 | - ) |
|
| 837 | - ); |
|
| 838 | - |
|
| 839 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 840 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 841 | - return true; |
|
| 842 | - } else { |
|
| 843 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 844 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 845 | - ); |
|
| 846 | - /** |
|
| 847 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 848 | - * IMMEDIATE generation. |
|
| 849 | - */ |
|
| 850 | - if ($count_failed > 0) { |
|
| 851 | - EE_Error::add_error( |
|
| 852 | - sprintf( |
|
| 853 | - _n( |
|
| 854 | - 'The payment notification generation failed.', |
|
| 855 | - '%d payment notifications failed being sent.', |
|
| 856 | - $count_failed, |
|
| 857 | - 'event_espresso' |
|
| 858 | - ), |
|
| 859 | - $count_failed |
|
| 860 | - ), |
|
| 861 | - __FILE__, |
|
| 862 | - __FUNCTION__, |
|
| 863 | - __LINE__ |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - return false; |
|
| 867 | - } else { |
|
| 868 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - } else { |
|
| 873 | - EE_Error::add_error( |
|
| 874 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 875 | - 'event_espresso' |
|
| 876 | - ); |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 884 | - * |
|
| 885 | - * @since 4.3.0 |
|
| 886 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 887 | - * @param int $grp_id a specific message template group id. |
|
| 888 | - * @return void |
|
| 889 | - * @throws EE_Error |
|
| 890 | - * @throws InvalidArgumentException |
|
| 891 | - * @throws InvalidDataTypeException |
|
| 892 | - * @throws InvalidInterfaceException |
|
| 893 | - * @throws ReflectionException |
|
| 894 | - */ |
|
| 895 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 896 | - { |
|
| 897 | - // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 898 | - EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 899 | - self::_load_controller(); |
|
| 900 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 906 | - * |
|
| 907 | - * @since 4.3.0 |
|
| 908 | - * @param string $registration_message_trigger_url |
|
| 909 | - * @param EE_Registration $registration |
|
| 910 | - * @param string $messenger |
|
| 911 | - * @param string $message_type |
|
| 912 | - * @return string |
|
| 913 | - * @throws EE_Error |
|
| 914 | - * @throws InvalidArgumentException |
|
| 915 | - * @throws InvalidDataTypeException |
|
| 916 | - * @throws InvalidInterfaceException |
|
| 917 | - */ |
|
| 918 | - public static function registration_message_trigger_url( |
|
| 919 | - $registration_message_trigger_url, |
|
| 920 | - EE_Registration $registration, |
|
| 921 | - $messenger = 'html', |
|
| 922 | - $message_type = 'invoice' |
|
| 923 | - ) { |
|
| 924 | - // whitelist $messenger |
|
| 925 | - switch ($messenger) { |
|
| 926 | - case 'pdf': |
|
| 927 | - $sending_messenger = 'pdf'; |
|
| 928 | - $generating_messenger = 'html'; |
|
| 929 | - break; |
|
| 930 | - case 'html': |
|
| 931 | - default: |
|
| 932 | - $sending_messenger = 'html'; |
|
| 933 | - $generating_messenger = 'html'; |
|
| 934 | - break; |
|
| 935 | - } |
|
| 936 | - // whitelist $message_type |
|
| 937 | - switch ($message_type) { |
|
| 938 | - case 'receipt': |
|
| 939 | - $message_type = 'receipt'; |
|
| 940 | - break; |
|
| 941 | - case 'invoice': |
|
| 942 | - default: |
|
| 943 | - $message_type = 'invoice'; |
|
| 944 | - break; |
|
| 945 | - } |
|
| 946 | - // verify that both the messenger AND the message type are active |
|
| 947 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 948 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
| 949 | - ) { |
|
| 950 | - // 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?) |
|
| 951 | - $template_query_params = array( |
|
| 952 | - 'MTP_is_active' => true, |
|
| 953 | - 'MTP_messenger' => $generating_messenger, |
|
| 954 | - 'MTP_message_type' => $message_type, |
|
| 955 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 956 | - ); |
|
| 957 | - // get the message template group. |
|
| 958 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 959 | - // if we don't have an EE_Message_Template_Group then return |
|
| 960 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 961 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 962 | - unset($template_query_params['Event.EVT_ID']); |
|
| 963 | - // get global template as the fallback |
|
| 964 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 965 | - } |
|
| 966 | - // if we don't have an EE_Message_Template_Group then return |
|
| 967 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 968 | - return ''; |
|
| 969 | - } |
|
| 970 | - // generate the URL |
|
| 971 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 972 | - $sending_messenger, |
|
| 973 | - $generating_messenger, |
|
| 974 | - 'purchaser', |
|
| 975 | - $message_type, |
|
| 976 | - $registration, |
|
| 977 | - $msg_template_group->ID(), |
|
| 978 | - $registration->transaction_ID() |
|
| 979 | - ); |
|
| 980 | - } |
|
| 981 | - return $registration_message_trigger_url; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * Use to generate and return a message preview! |
|
| 987 | - * |
|
| 988 | - * @param string $type This should correspond with a valid message type |
|
| 989 | - * @param string $context This should correspond with a valid context for the message type |
|
| 990 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 991 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 992 | - * preview |
|
| 993 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 994 | - * @throws EE_Error |
|
| 995 | - * @throws InvalidArgumentException |
|
| 996 | - * @throws InvalidDataTypeException |
|
| 997 | - * @throws InvalidInterfaceException |
|
| 998 | - * @throws ReflectionException |
|
| 999 | - */ |
|
| 1000 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1001 | - { |
|
| 1002 | - self::_load_controller(); |
|
| 1003 | - $mtg = new EE_Message_To_Generate( |
|
| 1004 | - $messenger, |
|
| 1005 | - $type, |
|
| 1006 | - array(), |
|
| 1007 | - $context, |
|
| 1008 | - true |
|
| 1009 | - ); |
|
| 1010 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1011 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1012 | - // loop through all content for the preview and remove any persisted records. |
|
| 1013 | - $content = ''; |
|
| 1014 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1015 | - $content = $message->content(); |
|
| 1016 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1017 | - $message->delete(); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - return $content; |
|
| 1021 | - } else { |
|
| 1022 | - return $generated_preview_queue; |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1029 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1030 | - * content found in the EE_Message objects in the queue. |
|
| 1031 | - * |
|
| 1032 | - * @since 4.9.0 |
|
| 1033 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 1034 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1035 | - * type name is still required to send along the message type to the |
|
| 1036 | - * messenger because this is used for determining what specific |
|
| 1037 | - * variations might be loaded for the generated message. |
|
| 1038 | - * @param EE_Messages_Queue $queue |
|
| 1039 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1040 | - * aggregate EE_Message object. |
|
| 1041 | - * @return bool success or fail. |
|
| 1042 | - * @throws EE_Error |
|
| 1043 | - * @throws InvalidArgumentException |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - * @throws InvalidDataTypeException |
|
| 1046 | - * @throws InvalidInterfaceException |
|
| 1047 | - */ |
|
| 1048 | - public static function send_message_with_messenger_only( |
|
| 1049 | - $messenger, |
|
| 1050 | - $message_type, |
|
| 1051 | - EE_Messages_Queue $queue, |
|
| 1052 | - $custom_subject = '' |
|
| 1053 | - ) { |
|
| 1054 | - self::_load_controller(); |
|
| 1055 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1056 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1057 | - 'Message_To_Generate_From_Queue', |
|
| 1058 | - array( |
|
| 1059 | - $messenger, |
|
| 1060 | - $message_type, |
|
| 1061 | - $queue, |
|
| 1062 | - $custom_subject, |
|
| 1063 | - ) |
|
| 1064 | - ); |
|
| 1065 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1071 | - * |
|
| 1072 | - * @since 4.9.0 |
|
| 1073 | - * @param array $message_ids An array of message ids |
|
| 1074 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1075 | - * messages. |
|
| 1076 | - * @throws EE_Error |
|
| 1077 | - * @throws InvalidArgumentException |
|
| 1078 | - * @throws InvalidDataTypeException |
|
| 1079 | - * @throws InvalidInterfaceException |
|
| 1080 | - * @throws ReflectionException |
|
| 1081 | - */ |
|
| 1082 | - public static function generate_now($message_ids) |
|
| 1083 | - { |
|
| 1084 | - self::_load_controller(); |
|
| 1085 | - $messages = EEM_Message::instance()->get_all( |
|
| 1086 | - array( |
|
| 1087 | - 0 => array( |
|
| 1088 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1089 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1090 | - ), |
|
| 1091 | - ) |
|
| 1092 | - ); |
|
| 1093 | - $generated_queue = false; |
|
| 1094 | - if ($messages) { |
|
| 1095 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1099 | - EE_Error::add_error( |
|
| 1100 | - __( |
|
| 1101 | - '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.', |
|
| 1102 | - 'event_espresso' |
|
| 1103 | - ), |
|
| 1104 | - __FILE__, |
|
| 1105 | - __FUNCTION__, |
|
| 1106 | - __LINE__ |
|
| 1107 | - ); |
|
| 1108 | - } |
|
| 1109 | - return $generated_queue; |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1115 | - * EEM_Message::status_idle |
|
| 1116 | - * |
|
| 1117 | - * @since 4.9.0 |
|
| 1118 | - * @param $message_ids |
|
| 1119 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1120 | - * @throws EE_Error |
|
| 1121 | - * @throws InvalidArgumentException |
|
| 1122 | - * @throws InvalidDataTypeException |
|
| 1123 | - * @throws InvalidInterfaceException |
|
| 1124 | - * @throws ReflectionException |
|
| 1125 | - */ |
|
| 1126 | - public static function send_now($message_ids) |
|
| 1127 | - { |
|
| 1128 | - self::_load_controller(); |
|
| 1129 | - $messages = EEM_Message::instance()->get_all( |
|
| 1130 | - array( |
|
| 1131 | - 0 => array( |
|
| 1132 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1133 | - 'STS_ID' => array( |
|
| 1134 | - 'IN', |
|
| 1135 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1136 | - ), |
|
| 1137 | - ), |
|
| 1138 | - ) |
|
| 1139 | - ); |
|
| 1140 | - $sent_queue = false; |
|
| 1141 | - if ($messages) { |
|
| 1142 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1146 | - EE_Error::add_error( |
|
| 1147 | - __( |
|
| 1148 | - '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.', |
|
| 1149 | - 'event_espresso' |
|
| 1150 | - ), |
|
| 1151 | - __FILE__, |
|
| 1152 | - __FUNCTION__, |
|
| 1153 | - __LINE__ |
|
| 1154 | - ); |
|
| 1155 | - } else { |
|
| 1156 | - // can count how many sent by using the messages in the queue |
|
| 1157 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1158 | - if ($sent_count > 0) { |
|
| 1159 | - EE_Error::add_success( |
|
| 1160 | - sprintf( |
|
| 1161 | - _n( |
|
| 1162 | - 'There was %d message successfully sent.', |
|
| 1163 | - 'There were %d messages successfully sent.', |
|
| 1164 | - $sent_count, |
|
| 1165 | - 'event_espresso' |
|
| 1166 | - ), |
|
| 1167 | - $sent_count |
|
| 1168 | - ) |
|
| 1169 | - ); |
|
| 1170 | - } else { |
|
| 1171 | - EE_Error::overwrite_errors(); |
|
| 1172 | - EE_Error::add_error( |
|
| 1173 | - __( |
|
| 1174 | - '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. |
|
| 259 | + exit; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * This runs when the msg_url_trigger route has initiated. |
|
| 268 | + * |
|
| 269 | + * @since 4.5.0 |
|
| 270 | + * @param WP $WP |
|
| 271 | + * @throws EE_Error |
|
| 272 | + * @throws InvalidArgumentException |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + * @throws InvalidDataTypeException |
|
| 275 | + * @throws InvalidInterfaceException |
|
| 276 | + */ |
|
| 277 | + public function run($WP) |
|
| 278 | + { |
|
| 279 | + // ensure controller is loaded |
|
| 280 | + self::_load_controller(); |
|
| 281 | + // attempt to process message |
|
| 282 | + try { |
|
| 283 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | + } catch (EE_Error $e) { |
|
| 287 | + $error_msg = __( |
|
| 288 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | + 'event_espresso' |
|
| 290 | + ); |
|
| 291 | + // add specific message for developers if WP_DEBUG in on |
|
| 292 | + $error_msg .= '||' . $e->getMessage(); |
|
| 293 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | + * |
|
| 301 | + * @param WP $WP |
|
| 302 | + */ |
|
| 303 | + public function execute_batch_request($WP) |
|
| 304 | + { |
|
| 305 | + $this->run_cron(); |
|
| 306 | + header('HTTP/1.1 200 OK'); |
|
| 307 | + exit(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | + * request. |
|
| 314 | + */ |
|
| 315 | + public function run_cron() |
|
| 316 | + { |
|
| 317 | + self::_load_controller(); |
|
| 318 | + // get required vars |
|
| 319 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | + |
|
| 322 | + // now let's verify transient, if not valid exit immediately |
|
| 323 | + if (! get_transient($transient_key)) { |
|
| 324 | + /** |
|
| 325 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | + * request. |
|
| 327 | + */ |
|
| 328 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | + delete_transient($transient_key); |
|
| 333 | + |
|
| 334 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | + self::$_MSG_PROCESSOR->$method(); |
|
| 338 | + } else { |
|
| 339 | + // no matching task |
|
| 340 | + /** |
|
| 341 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | + * request. |
|
| 343 | + */ |
|
| 344 | + trigger_error( |
|
| 345 | + esc_attr( |
|
| 346 | + sprintf( |
|
| 347 | + __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | + $cron_type |
|
| 349 | + ) |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * This is used to retrieve the template pack for the given name. |
|
| 361 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | + * the default template pack is returned. |
|
| 363 | + * |
|
| 364 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | + * in generating the Pack class name). |
|
| 367 | + * @return EE_Messages_Template_Pack |
|
| 368 | + * @throws EE_Error |
|
| 369 | + * @throws InvalidArgumentException |
|
| 370 | + * @throws ReflectionException |
|
| 371 | + * @throws InvalidDataTypeException |
|
| 372 | + * @throws InvalidInterfaceException |
|
| 373 | + */ |
|
| 374 | + public static function get_template_pack($template_pack_name) |
|
| 375 | + { |
|
| 376 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Retrieves an array of all template packs. |
|
| 383 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | + * |
|
| 385 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | + * @return EE_Messages_Template_Pack[] |
|
| 387 | + * @throws EE_Error |
|
| 388 | + * @throws InvalidArgumentException |
|
| 389 | + * @throws ReflectionException |
|
| 390 | + * @throws InvalidDataTypeException |
|
| 391 | + * @throws InvalidInterfaceException |
|
| 392 | + */ |
|
| 393 | + public static function get_template_packs() |
|
| 394 | + { |
|
| 395 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | + |
|
| 397 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | + $template_pack_collection->rewind(); |
|
| 400 | + $template_packs = array(); |
|
| 401 | + while ($template_pack_collection->valid()) { |
|
| 402 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | + $template_pack_collection->next(); |
|
| 404 | + } |
|
| 405 | + return $template_packs; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | + * |
|
| 412 | + * @since 4.5.0 |
|
| 413 | + * @return void |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public static function set_autoloaders() |
|
| 417 | + { |
|
| 418 | + if (empty(self::$_MSG_PATHS)) { |
|
| 419 | + self::_set_messages_paths(); |
|
| 420 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | + } |
|
| 423 | + // add aliases |
|
| 424 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | + * for use by the Messages Autoloaders |
|
| 433 | + * |
|
| 434 | + * @since 4.5.0 |
|
| 435 | + * @return void. |
|
| 436 | + */ |
|
| 437 | + protected static function _set_messages_paths() |
|
| 438 | + { |
|
| 439 | + $dir_ref = array( |
|
| 440 | + 'messages/message_type', |
|
| 441 | + 'messages/messenger', |
|
| 442 | + 'messages/defaults', |
|
| 443 | + 'messages/defaults/email', |
|
| 444 | + 'messages/data_class', |
|
| 445 | + 'messages/validators', |
|
| 446 | + 'messages/validators/email', |
|
| 447 | + 'messages/validators/html', |
|
| 448 | + 'shortcodes', |
|
| 449 | + ); |
|
| 450 | + $paths = array(); |
|
| 451 | + foreach ($dir_ref as $index => $dir) { |
|
| 452 | + $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 453 | + } |
|
| 454 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Takes care of loading dependencies |
|
| 460 | + * |
|
| 461 | + * @since 4.5.0 |
|
| 462 | + * @return void |
|
| 463 | + * @throws EE_Error |
|
| 464 | + * @throws InvalidArgumentException |
|
| 465 | + * @throws ReflectionException |
|
| 466 | + * @throws InvalidDataTypeException |
|
| 467 | + * @throws InvalidInterfaceException |
|
| 468 | + */ |
|
| 469 | + protected static function _load_controller() |
|
| 470 | + { |
|
| 471 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 472 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 473 | + self::set_autoloaders(); |
|
| 474 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 475 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 476 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param EE_Transaction $transaction |
|
| 483 | + * @throws EE_Error |
|
| 484 | + * @throws InvalidArgumentException |
|
| 485 | + * @throws InvalidDataTypeException |
|
| 486 | + * @throws InvalidInterfaceException |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 490 | + { |
|
| 491 | + self::_load_controller(); |
|
| 492 | + $data = array($transaction, null); |
|
| 493 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 499 | + * |
|
| 500 | + * @param EE_Transaction $transaction object |
|
| 501 | + * @param EE_Payment|null $payment object |
|
| 502 | + * @return void |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws InvalidArgumentException |
|
| 505 | + * @throws ReflectionException |
|
| 506 | + * @throws InvalidDataTypeException |
|
| 507 | + * @throws InvalidInterfaceException |
|
| 508 | + */ |
|
| 509 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 510 | + { |
|
| 511 | + // if there's no payment object, then we cannot do a payment type message! |
|
| 512 | + if (! $payment instanceof EE_Payment) { |
|
| 513 | + return; |
|
| 514 | + } |
|
| 515 | + self::_load_controller(); |
|
| 516 | + $data = array($transaction, $payment); |
|
| 517 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 518 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 519 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 520 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 521 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @param EE_Transaction $transaction |
|
| 527 | + * @throws EE_Error |
|
| 528 | + * @throws InvalidArgumentException |
|
| 529 | + * @throws InvalidDataTypeException |
|
| 530 | + * @throws InvalidInterfaceException |
|
| 531 | + * @throws ReflectionException |
|
| 532 | + */ |
|
| 533 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 534 | + { |
|
| 535 | + self::_load_controller(); |
|
| 536 | + $data = array($transaction, null); |
|
| 537 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Trigger for Registration messages |
|
| 543 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 544 | + * incoming transaction. |
|
| 545 | + * |
|
| 546 | + * @param EE_Registration $registration |
|
| 547 | + * @param array $extra_details |
|
| 548 | + * @return void |
|
| 549 | + * @throws EE_Error |
|
| 550 | + * @throws InvalidArgumentException |
|
| 551 | + * @throws InvalidDataTypeException |
|
| 552 | + * @throws InvalidInterfaceException |
|
| 553 | + * @throws ReflectionException |
|
| 554 | + * @throws EntityNotFoundException |
|
| 555 | + */ |
|
| 556 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 557 | + { |
|
| 558 | + |
|
| 559 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 560 | + // no messages please |
|
| 561 | + return; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 565 | + $all_registrations = $registration->transaction()->registrations( |
|
| 566 | + array( |
|
| 567 | + array('REG_deleted' => false), |
|
| 568 | + 'order_by' => array( |
|
| 569 | + 'Event.EVT_name' => 'ASC', |
|
| 570 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 571 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 572 | + ), |
|
| 573 | + ) |
|
| 574 | + ); |
|
| 575 | + // cached array of statuses so we only trigger messages once per status. |
|
| 576 | + $statuses_sent = array(); |
|
| 577 | + self::_load_controller(); |
|
| 578 | + $mtgs = array(); |
|
| 579 | + |
|
| 580 | + // loop through registrations and trigger messages once per status. |
|
| 581 | + foreach ($all_registrations as $reg) { |
|
| 582 | + // already triggered? |
|
| 583 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 584 | + continue; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 588 | + $mtgs = array_merge( |
|
| 589 | + $mtgs, |
|
| 590 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 591 | + $message_type, |
|
| 592 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + $statuses_sent[] = $reg->status_ID(); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if (count($statuses_sent) > 1) { |
|
| 599 | + $mtgs = array_merge( |
|
| 600 | + $mtgs, |
|
| 601 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 602 | + 'registration_summary', |
|
| 603 | + array($registration->transaction(), null) |
|
| 604 | + ) |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + // batch queue and initiate request |
|
| 609 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 610 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 616 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 617 | + * |
|
| 618 | + * @param EE_Registration $registration [description] |
|
| 619 | + * @param array $extra_details [description] |
|
| 620 | + * @return bool true = send away, false = nope halt the presses. |
|
| 621 | + */ |
|
| 622 | + protected static function _verify_registration_notification_send( |
|
| 623 | + EE_Registration $registration, |
|
| 624 | + $extra_details = array() |
|
| 625 | + ) { |
|
| 626 | + if (! $registration->is_primary_registrant()) { |
|
| 627 | + return false; |
|
| 628 | + } |
|
| 629 | + // first we check if we're in admin and not doing front ajax |
|
| 630 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 631 | + // make sure appropriate admin params are set for sending messages |
|
| 632 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 633 | + || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | + ) { |
|
| 635 | + // no messages sent please. |
|
| 636 | + return false; |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + // frontend request (either regular or via AJAX) |
|
| 640 | + // TXN is NOT finalized ? |
|
| 641 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 642 | + return false; |
|
| 643 | + } |
|
| 644 | + // return visit but nothing changed ??? |
|
| 645 | + if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 646 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 647 | + ) { |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 650 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 651 | + if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 652 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 653 | + ) { |
|
| 654 | + return false; |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + // release the kraken |
|
| 658 | + return true; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 664 | + * status id. |
|
| 665 | + * |
|
| 666 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 667 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 668 | + * @param string $reg_status |
|
| 669 | + * @return array |
|
| 670 | + * @throws EE_Error |
|
| 671 | + * @throws InvalidArgumentException |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + * @throws InvalidDataTypeException |
|
| 674 | + * @throws InvalidInterfaceException |
|
| 675 | + */ |
|
| 676 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 677 | + { |
|
| 678 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 679 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 680 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Simply returns the payment message type for the given payment status. |
|
| 687 | + * |
|
| 688 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 689 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 690 | + * @param string $payment_status The payment status being matched. |
|
| 691 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 692 | + * @throws EE_Error |
|
| 693 | + * @throws InvalidArgumentException |
|
| 694 | + * @throws ReflectionException |
|
| 695 | + * @throws InvalidDataTypeException |
|
| 696 | + * @throws InvalidInterfaceException |
|
| 697 | + */ |
|
| 698 | + protected static function _get_payment_message_type($payment_status) |
|
| 699 | + { |
|
| 700 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 701 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 702 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | + : false; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 709 | + * |
|
| 710 | + * @access public |
|
| 711 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 712 | + * @return bool success/fail |
|
| 713 | + * @throws EE_Error |
|
| 714 | + * @throws InvalidArgumentException |
|
| 715 | + * @throws InvalidDataTypeException |
|
| 716 | + * @throws InvalidInterfaceException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + */ |
|
| 719 | + public static function process_resend($req_data) |
|
| 720 | + { |
|
| 721 | + self::_load_controller(); |
|
| 722 | + |
|
| 723 | + // if $msgID in this request then skip to the new resend_message |
|
| 724 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 725 | + return self::resend_message(); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 729 | + $req_data = (array) $req_data; |
|
| 730 | + foreach ($req_data as $request_key => $request_value) { |
|
| 731 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 735 | + )) { |
|
| 736 | + return false; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + try { |
|
| 740 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 741 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 742 | + } catch (EE_Error $e) { |
|
| 743 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + EE_Error::add_success( |
|
| 747 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 748 | + ); |
|
| 749 | + return true; // everything got queued. |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 755 | + * |
|
| 756 | + * @return bool |
|
| 757 | + * @throws EE_Error |
|
| 758 | + * @throws InvalidArgumentException |
|
| 759 | + * @throws InvalidDataTypeException |
|
| 760 | + * @throws InvalidInterfaceException |
|
| 761 | + * @throws ReflectionException |
|
| 762 | + */ |
|
| 763 | + public static function resend_message() |
|
| 764 | + { |
|
| 765 | + self::_load_controller(); |
|
| 766 | + |
|
| 767 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 768 | + if (! $msgID) { |
|
| 769 | + EE_Error::add_error( |
|
| 770 | + __( |
|
| 771 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 772 | + 'event_espresso' |
|
| 773 | + ), |
|
| 774 | + __FILE__, |
|
| 775 | + __FUNCTION__, |
|
| 776 | + __LINE__ |
|
| 777 | + ); |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 782 | + |
|
| 783 | + // setup success message. |
|
| 784 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 785 | + EE_Error::add_success( |
|
| 786 | + sprintf( |
|
| 787 | + _n( |
|
| 788 | + 'There was %d message queued for resending.', |
|
| 789 | + 'There were %d messages queued for resending.', |
|
| 790 | + $count_ready_for_resend, |
|
| 791 | + 'event_espresso' |
|
| 792 | + ), |
|
| 793 | + $count_ready_for_resend |
|
| 794 | + ) |
|
| 795 | + ); |
|
| 796 | + return true; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Message triggers for manual payment applied by admin |
|
| 802 | + * |
|
| 803 | + * @param EE_Payment $payment EE_payment object |
|
| 804 | + * @return bool success/fail |
|
| 805 | + * @throws EE_Error |
|
| 806 | + * @throws InvalidArgumentException |
|
| 807 | + * @throws ReflectionException |
|
| 808 | + * @throws InvalidDataTypeException |
|
| 809 | + * @throws InvalidInterfaceException |
|
| 810 | + */ |
|
| 811 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 812 | + { |
|
| 813 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 814 | + // we need to get the transaction object |
|
| 815 | + $transaction = $payment->transaction(); |
|
| 816 | + if ($transaction instanceof EE_Transaction) { |
|
| 817 | + $data = array($transaction, $payment); |
|
| 818 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 819 | + |
|
| 820 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 821 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 822 | + |
|
| 823 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 824 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 825 | + ? false : $message_type; |
|
| 826 | + |
|
| 827 | + self::_load_controller(); |
|
| 828 | + |
|
| 829 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 830 | + |
|
| 831 | + // get count of queued for generation |
|
| 832 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 833 | + array( |
|
| 834 | + EEM_Message::status_incomplete, |
|
| 835 | + EEM_Message::status_idle, |
|
| 836 | + ) |
|
| 837 | + ); |
|
| 838 | + |
|
| 839 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 840 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 841 | + return true; |
|
| 842 | + } else { |
|
| 843 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 844 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 845 | + ); |
|
| 846 | + /** |
|
| 847 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 848 | + * IMMEDIATE generation. |
|
| 849 | + */ |
|
| 850 | + if ($count_failed > 0) { |
|
| 851 | + EE_Error::add_error( |
|
| 852 | + sprintf( |
|
| 853 | + _n( |
|
| 854 | + 'The payment notification generation failed.', |
|
| 855 | + '%d payment notifications failed being sent.', |
|
| 856 | + $count_failed, |
|
| 857 | + 'event_espresso' |
|
| 858 | + ), |
|
| 859 | + $count_failed |
|
| 860 | + ), |
|
| 861 | + __FILE__, |
|
| 862 | + __FUNCTION__, |
|
| 863 | + __LINE__ |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + return false; |
|
| 867 | + } else { |
|
| 868 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + } else { |
|
| 873 | + EE_Error::add_error( |
|
| 874 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 875 | + 'event_espresso' |
|
| 876 | + ); |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 884 | + * |
|
| 885 | + * @since 4.3.0 |
|
| 886 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 887 | + * @param int $grp_id a specific message template group id. |
|
| 888 | + * @return void |
|
| 889 | + * @throws EE_Error |
|
| 890 | + * @throws InvalidArgumentException |
|
| 891 | + * @throws InvalidDataTypeException |
|
| 892 | + * @throws InvalidInterfaceException |
|
| 893 | + * @throws ReflectionException |
|
| 894 | + */ |
|
| 895 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 896 | + { |
|
| 897 | + // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 898 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 899 | + self::_load_controller(); |
|
| 900 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 906 | + * |
|
| 907 | + * @since 4.3.0 |
|
| 908 | + * @param string $registration_message_trigger_url |
|
| 909 | + * @param EE_Registration $registration |
|
| 910 | + * @param string $messenger |
|
| 911 | + * @param string $message_type |
|
| 912 | + * @return string |
|
| 913 | + * @throws EE_Error |
|
| 914 | + * @throws InvalidArgumentException |
|
| 915 | + * @throws InvalidDataTypeException |
|
| 916 | + * @throws InvalidInterfaceException |
|
| 917 | + */ |
|
| 918 | + public static function registration_message_trigger_url( |
|
| 919 | + $registration_message_trigger_url, |
|
| 920 | + EE_Registration $registration, |
|
| 921 | + $messenger = 'html', |
|
| 922 | + $message_type = 'invoice' |
|
| 923 | + ) { |
|
| 924 | + // whitelist $messenger |
|
| 925 | + switch ($messenger) { |
|
| 926 | + case 'pdf': |
|
| 927 | + $sending_messenger = 'pdf'; |
|
| 928 | + $generating_messenger = 'html'; |
|
| 929 | + break; |
|
| 930 | + case 'html': |
|
| 931 | + default: |
|
| 932 | + $sending_messenger = 'html'; |
|
| 933 | + $generating_messenger = 'html'; |
|
| 934 | + break; |
|
| 935 | + } |
|
| 936 | + // whitelist $message_type |
|
| 937 | + switch ($message_type) { |
|
| 938 | + case 'receipt': |
|
| 939 | + $message_type = 'receipt'; |
|
| 940 | + break; |
|
| 941 | + case 'invoice': |
|
| 942 | + default: |
|
| 943 | + $message_type = 'invoice'; |
|
| 944 | + break; |
|
| 945 | + } |
|
| 946 | + // verify that both the messenger AND the message type are active |
|
| 947 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 948 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
| 949 | + ) { |
|
| 950 | + // 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?) |
|
| 951 | + $template_query_params = array( |
|
| 952 | + 'MTP_is_active' => true, |
|
| 953 | + 'MTP_messenger' => $generating_messenger, |
|
| 954 | + 'MTP_message_type' => $message_type, |
|
| 955 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 956 | + ); |
|
| 957 | + // get the message template group. |
|
| 958 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 959 | + // if we don't have an EE_Message_Template_Group then return |
|
| 960 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 961 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 962 | + unset($template_query_params['Event.EVT_ID']); |
|
| 963 | + // get global template as the fallback |
|
| 964 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 965 | + } |
|
| 966 | + // if we don't have an EE_Message_Template_Group then return |
|
| 967 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 968 | + return ''; |
|
| 969 | + } |
|
| 970 | + // generate the URL |
|
| 971 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 972 | + $sending_messenger, |
|
| 973 | + $generating_messenger, |
|
| 974 | + 'purchaser', |
|
| 975 | + $message_type, |
|
| 976 | + $registration, |
|
| 977 | + $msg_template_group->ID(), |
|
| 978 | + $registration->transaction_ID() |
|
| 979 | + ); |
|
| 980 | + } |
|
| 981 | + return $registration_message_trigger_url; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * Use to generate and return a message preview! |
|
| 987 | + * |
|
| 988 | + * @param string $type This should correspond with a valid message type |
|
| 989 | + * @param string $context This should correspond with a valid context for the message type |
|
| 990 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 991 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 992 | + * preview |
|
| 993 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 994 | + * @throws EE_Error |
|
| 995 | + * @throws InvalidArgumentException |
|
| 996 | + * @throws InvalidDataTypeException |
|
| 997 | + * @throws InvalidInterfaceException |
|
| 998 | + * @throws ReflectionException |
|
| 999 | + */ |
|
| 1000 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1001 | + { |
|
| 1002 | + self::_load_controller(); |
|
| 1003 | + $mtg = new EE_Message_To_Generate( |
|
| 1004 | + $messenger, |
|
| 1005 | + $type, |
|
| 1006 | + array(), |
|
| 1007 | + $context, |
|
| 1008 | + true |
|
| 1009 | + ); |
|
| 1010 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1011 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1012 | + // loop through all content for the preview and remove any persisted records. |
|
| 1013 | + $content = ''; |
|
| 1014 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1015 | + $content = $message->content(); |
|
| 1016 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1017 | + $message->delete(); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + return $content; |
|
| 1021 | + } else { |
|
| 1022 | + return $generated_preview_queue; |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1029 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1030 | + * content found in the EE_Message objects in the queue. |
|
| 1031 | + * |
|
| 1032 | + * @since 4.9.0 |
|
| 1033 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 1034 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1035 | + * type name is still required to send along the message type to the |
|
| 1036 | + * messenger because this is used for determining what specific |
|
| 1037 | + * variations might be loaded for the generated message. |
|
| 1038 | + * @param EE_Messages_Queue $queue |
|
| 1039 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1040 | + * aggregate EE_Message object. |
|
| 1041 | + * @return bool success or fail. |
|
| 1042 | + * @throws EE_Error |
|
| 1043 | + * @throws InvalidArgumentException |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + * @throws InvalidDataTypeException |
|
| 1046 | + * @throws InvalidInterfaceException |
|
| 1047 | + */ |
|
| 1048 | + public static function send_message_with_messenger_only( |
|
| 1049 | + $messenger, |
|
| 1050 | + $message_type, |
|
| 1051 | + EE_Messages_Queue $queue, |
|
| 1052 | + $custom_subject = '' |
|
| 1053 | + ) { |
|
| 1054 | + self::_load_controller(); |
|
| 1055 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1056 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1057 | + 'Message_To_Generate_From_Queue', |
|
| 1058 | + array( |
|
| 1059 | + $messenger, |
|
| 1060 | + $message_type, |
|
| 1061 | + $queue, |
|
| 1062 | + $custom_subject, |
|
| 1063 | + ) |
|
| 1064 | + ); |
|
| 1065 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1071 | + * |
|
| 1072 | + * @since 4.9.0 |
|
| 1073 | + * @param array $message_ids An array of message ids |
|
| 1074 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1075 | + * messages. |
|
| 1076 | + * @throws EE_Error |
|
| 1077 | + * @throws InvalidArgumentException |
|
| 1078 | + * @throws InvalidDataTypeException |
|
| 1079 | + * @throws InvalidInterfaceException |
|
| 1080 | + * @throws ReflectionException |
|
| 1081 | + */ |
|
| 1082 | + public static function generate_now($message_ids) |
|
| 1083 | + { |
|
| 1084 | + self::_load_controller(); |
|
| 1085 | + $messages = EEM_Message::instance()->get_all( |
|
| 1086 | + array( |
|
| 1087 | + 0 => array( |
|
| 1088 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1089 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1090 | + ), |
|
| 1091 | + ) |
|
| 1092 | + ); |
|
| 1093 | + $generated_queue = false; |
|
| 1094 | + if ($messages) { |
|
| 1095 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1099 | + EE_Error::add_error( |
|
| 1100 | + __( |
|
| 1101 | + '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.', |
|
| 1102 | + 'event_espresso' |
|
| 1103 | + ), |
|
| 1104 | + __FILE__, |
|
| 1105 | + __FUNCTION__, |
|
| 1106 | + __LINE__ |
|
| 1107 | + ); |
|
| 1108 | + } |
|
| 1109 | + return $generated_queue; |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1115 | + * EEM_Message::status_idle |
|
| 1116 | + * |
|
| 1117 | + * @since 4.9.0 |
|
| 1118 | + * @param $message_ids |
|
| 1119 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1120 | + * @throws EE_Error |
|
| 1121 | + * @throws InvalidArgumentException |
|
| 1122 | + * @throws InvalidDataTypeException |
|
| 1123 | + * @throws InvalidInterfaceException |
|
| 1124 | + * @throws ReflectionException |
|
| 1125 | + */ |
|
| 1126 | + public static function send_now($message_ids) |
|
| 1127 | + { |
|
| 1128 | + self::_load_controller(); |
|
| 1129 | + $messages = EEM_Message::instance()->get_all( |
|
| 1130 | + array( |
|
| 1131 | + 0 => array( |
|
| 1132 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1133 | + 'STS_ID' => array( |
|
| 1134 | + 'IN', |
|
| 1135 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1136 | + ), |
|
| 1137 | + ), |
|
| 1138 | + ) |
|
| 1139 | + ); |
|
| 1140 | + $sent_queue = false; |
|
| 1141 | + if ($messages) { |
|
| 1142 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1146 | + EE_Error::add_error( |
|
| 1147 | + __( |
|
| 1148 | + '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.', |
|
| 1149 | + 'event_espresso' |
|
| 1150 | + ), |
|
| 1151 | + __FILE__, |
|
| 1152 | + __FUNCTION__, |
|
| 1153 | + __LINE__ |
|
| 1154 | + ); |
|
| 1155 | + } else { |
|
| 1156 | + // can count how many sent by using the messages in the queue |
|
| 1157 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1158 | + if ($sent_count > 0) { |
|
| 1159 | + EE_Error::add_success( |
|
| 1160 | + sprintf( |
|
| 1161 | + _n( |
|
| 1162 | + 'There was %d message successfully sent.', |
|
| 1163 | + 'There were %d messages successfully sent.', |
|
| 1164 | + $sent_count, |
|
| 1165 | + 'event_espresso' |
|
| 1166 | + ), |
|
| 1167 | + $sent_count |
|
| 1168 | + ) |
|
| 1169 | + ); |
|
| 1170 | + } else { |
|
| 1171 | + EE_Error::overwrite_errors(); |
|
| 1172 | + EE_Error::add_error( |
|
| 1173 | + __( |
|
| 1174 | + '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. |
|
| 1175 | 1175 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1176 | - 'event_espresso' |
|
| 1177 | - ), |
|
| 1178 | - __FILE__, |
|
| 1179 | - __FUNCTION__, |
|
| 1180 | - __LINE__ |
|
| 1181 | - ); |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - return $sent_queue; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - |
|
| 1188 | - /** |
|
| 1189 | - * Generate and send immediately from the given $message_ids |
|
| 1190 | - * |
|
| 1191 | - * @param array $message_ids EE_Message entity ids. |
|
| 1192 | - * @throws EE_Error |
|
| 1193 | - * @throws InvalidArgumentException |
|
| 1194 | - * @throws InvalidDataTypeException |
|
| 1195 | - * @throws InvalidInterfaceException |
|
| 1196 | - * @throws ReflectionException |
|
| 1197 | - */ |
|
| 1198 | - public static function generate_and_send_now(array $message_ids) |
|
| 1199 | - { |
|
| 1200 | - $generated_queue = self::generate_now($message_ids); |
|
| 1201 | - // now let's just trigger sending immediately from this queue. |
|
| 1202 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1203 | - ? $generated_queue->execute() |
|
| 1204 | - : 0; |
|
| 1205 | - if ($messages_sent) { |
|
| 1206 | - EE_Error::add_success( |
|
| 1207 | - esc_html( |
|
| 1208 | - sprintf( |
|
| 1209 | - _n( |
|
| 1210 | - 'There was %d message successfully generated and sent.', |
|
| 1211 | - 'There were %d messages successfully generated and sent.', |
|
| 1212 | - $messages_sent, |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ), |
|
| 1215 | - $messages_sent |
|
| 1216 | - ) |
|
| 1217 | - ) |
|
| 1218 | - ); |
|
| 1219 | - // errors would be added via the generate_now method. |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * This will queue the incoming message ids for resending. |
|
| 1226 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1227 | - * |
|
| 1228 | - * @since 4.9.0 |
|
| 1229 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1230 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1231 | - * resending. |
|
| 1232 | - * @throws EE_Error |
|
| 1233 | - * @throws InvalidArgumentException |
|
| 1234 | - * @throws InvalidDataTypeException |
|
| 1235 | - * @throws InvalidInterfaceException |
|
| 1236 | - * @throws ReflectionException |
|
| 1237 | - */ |
|
| 1238 | - public static function queue_for_resending($message_ids) |
|
| 1239 | - { |
|
| 1240 | - self::_load_controller(); |
|
| 1241 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1242 | - |
|
| 1243 | - // get queue and count |
|
| 1244 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1245 | - |
|
| 1246 | - if ($queue_count > 0 |
|
| 1247 | - ) { |
|
| 1248 | - EE_Error::add_success( |
|
| 1249 | - sprintf( |
|
| 1250 | - _n( |
|
| 1251 | - '%d message successfully queued for resending.', |
|
| 1252 | - '%d messages successfully queued for resending.', |
|
| 1253 | - $queue_count, |
|
| 1254 | - 'event_espresso' |
|
| 1255 | - ), |
|
| 1256 | - $queue_count |
|
| 1257 | - ) |
|
| 1258 | - ); |
|
| 1259 | - /** |
|
| 1260 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1261 | - */ |
|
| 1262 | - } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1263 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1264 | - ) { |
|
| 1265 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1266 | - if ($queue_count > 0) { |
|
| 1267 | - EE_Error::add_success( |
|
| 1268 | - sprintf( |
|
| 1269 | - _n( |
|
| 1270 | - '%d message successfully sent.', |
|
| 1271 | - '%d messages successfully sent.', |
|
| 1272 | - $queue_count, |
|
| 1273 | - 'event_espresso' |
|
| 1274 | - ), |
|
| 1275 | - $queue_count |
|
| 1276 | - ) |
|
| 1277 | - ); |
|
| 1278 | - } else { |
|
| 1279 | - EE_Error::add_error( |
|
| 1280 | - __( |
|
| 1281 | - '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.', |
|
| 1282 | - 'event_espresso' |
|
| 1283 | - ), |
|
| 1284 | - __FILE__, |
|
| 1285 | - __FUNCTION__, |
|
| 1286 | - __LINE__ |
|
| 1287 | - ); |
|
| 1288 | - } |
|
| 1289 | - } else { |
|
| 1290 | - EE_Error::add_error( |
|
| 1291 | - __( |
|
| 1292 | - '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.', |
|
| 1293 | - 'event_espresso' |
|
| 1294 | - ), |
|
| 1295 | - __FILE__, |
|
| 1296 | - __FUNCTION__, |
|
| 1297 | - __LINE__ |
|
| 1298 | - ); |
|
| 1299 | - } |
|
| 1300 | - return (bool) $queue_count; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * debug |
|
| 1306 | - * |
|
| 1307 | - * @param string $class |
|
| 1308 | - * @param string $func |
|
| 1309 | - * @param string $line |
|
| 1310 | - * @param \EE_Transaction $transaction |
|
| 1311 | - * @param array $info |
|
| 1312 | - * @param bool $display_request |
|
| 1313 | - * @throws EE_Error |
|
| 1314 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1315 | - */ |
|
| 1316 | - protected static function log( |
|
| 1317 | - $class = '', |
|
| 1318 | - $func = '', |
|
| 1319 | - $line = '', |
|
| 1320 | - EE_Transaction $transaction, |
|
| 1321 | - $info = array(), |
|
| 1322 | - $display_request = false |
|
| 1323 | - ) { |
|
| 1324 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1325 | - if ($transaction instanceof EE_Transaction) { |
|
| 1326 | - // don't serialize objects |
|
| 1327 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1328 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1329 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1330 | - if ($transaction->ID()) { |
|
| 1331 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1332 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Resets all the static properties in this class when called. |
|
| 1341 | - */ |
|
| 1342 | - public static function reset() |
|
| 1343 | - { |
|
| 1344 | - self::$_EEMSG = null; |
|
| 1345 | - self::$_message_resource_manager = null; |
|
| 1346 | - self::$_MSG_PROCESSOR = null; |
|
| 1347 | - self::$_MSG_PATHS = null; |
|
| 1348 | - self::$_TMP_PACKS = array(); |
|
| 1349 | - } |
|
| 1176 | + 'event_espresso' |
|
| 1177 | + ), |
|
| 1178 | + __FILE__, |
|
| 1179 | + __FUNCTION__, |
|
| 1180 | + __LINE__ |
|
| 1181 | + ); |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + return $sent_queue; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + |
|
| 1188 | + /** |
|
| 1189 | + * Generate and send immediately from the given $message_ids |
|
| 1190 | + * |
|
| 1191 | + * @param array $message_ids EE_Message entity ids. |
|
| 1192 | + * @throws EE_Error |
|
| 1193 | + * @throws InvalidArgumentException |
|
| 1194 | + * @throws InvalidDataTypeException |
|
| 1195 | + * @throws InvalidInterfaceException |
|
| 1196 | + * @throws ReflectionException |
|
| 1197 | + */ |
|
| 1198 | + public static function generate_and_send_now(array $message_ids) |
|
| 1199 | + { |
|
| 1200 | + $generated_queue = self::generate_now($message_ids); |
|
| 1201 | + // now let's just trigger sending immediately from this queue. |
|
| 1202 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1203 | + ? $generated_queue->execute() |
|
| 1204 | + : 0; |
|
| 1205 | + if ($messages_sent) { |
|
| 1206 | + EE_Error::add_success( |
|
| 1207 | + esc_html( |
|
| 1208 | + sprintf( |
|
| 1209 | + _n( |
|
| 1210 | + 'There was %d message successfully generated and sent.', |
|
| 1211 | + 'There were %d messages successfully generated and sent.', |
|
| 1212 | + $messages_sent, |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ), |
|
| 1215 | + $messages_sent |
|
| 1216 | + ) |
|
| 1217 | + ) |
|
| 1218 | + ); |
|
| 1219 | + // errors would be added via the generate_now method. |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * This will queue the incoming message ids for resending. |
|
| 1226 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1227 | + * |
|
| 1228 | + * @since 4.9.0 |
|
| 1229 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1230 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1231 | + * resending. |
|
| 1232 | + * @throws EE_Error |
|
| 1233 | + * @throws InvalidArgumentException |
|
| 1234 | + * @throws InvalidDataTypeException |
|
| 1235 | + * @throws InvalidInterfaceException |
|
| 1236 | + * @throws ReflectionException |
|
| 1237 | + */ |
|
| 1238 | + public static function queue_for_resending($message_ids) |
|
| 1239 | + { |
|
| 1240 | + self::_load_controller(); |
|
| 1241 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1242 | + |
|
| 1243 | + // get queue and count |
|
| 1244 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1245 | + |
|
| 1246 | + if ($queue_count > 0 |
|
| 1247 | + ) { |
|
| 1248 | + EE_Error::add_success( |
|
| 1249 | + sprintf( |
|
| 1250 | + _n( |
|
| 1251 | + '%d message successfully queued for resending.', |
|
| 1252 | + '%d messages successfully queued for resending.', |
|
| 1253 | + $queue_count, |
|
| 1254 | + 'event_espresso' |
|
| 1255 | + ), |
|
| 1256 | + $queue_count |
|
| 1257 | + ) |
|
| 1258 | + ); |
|
| 1259 | + /** |
|
| 1260 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1261 | + */ |
|
| 1262 | + } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1263 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1264 | + ) { |
|
| 1265 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1266 | + if ($queue_count > 0) { |
|
| 1267 | + EE_Error::add_success( |
|
| 1268 | + sprintf( |
|
| 1269 | + _n( |
|
| 1270 | + '%d message successfully sent.', |
|
| 1271 | + '%d messages successfully sent.', |
|
| 1272 | + $queue_count, |
|
| 1273 | + 'event_espresso' |
|
| 1274 | + ), |
|
| 1275 | + $queue_count |
|
| 1276 | + ) |
|
| 1277 | + ); |
|
| 1278 | + } else { |
|
| 1279 | + EE_Error::add_error( |
|
| 1280 | + __( |
|
| 1281 | + '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.', |
|
| 1282 | + 'event_espresso' |
|
| 1283 | + ), |
|
| 1284 | + __FILE__, |
|
| 1285 | + __FUNCTION__, |
|
| 1286 | + __LINE__ |
|
| 1287 | + ); |
|
| 1288 | + } |
|
| 1289 | + } else { |
|
| 1290 | + EE_Error::add_error( |
|
| 1291 | + __( |
|
| 1292 | + '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.', |
|
| 1293 | + 'event_espresso' |
|
| 1294 | + ), |
|
| 1295 | + __FILE__, |
|
| 1296 | + __FUNCTION__, |
|
| 1297 | + __LINE__ |
|
| 1298 | + ); |
|
| 1299 | + } |
|
| 1300 | + return (bool) $queue_count; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * debug |
|
| 1306 | + * |
|
| 1307 | + * @param string $class |
|
| 1308 | + * @param string $func |
|
| 1309 | + * @param string $line |
|
| 1310 | + * @param \EE_Transaction $transaction |
|
| 1311 | + * @param array $info |
|
| 1312 | + * @param bool $display_request |
|
| 1313 | + * @throws EE_Error |
|
| 1314 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1315 | + */ |
|
| 1316 | + protected static function log( |
|
| 1317 | + $class = '', |
|
| 1318 | + $func = '', |
|
| 1319 | + $line = '', |
|
| 1320 | + EE_Transaction $transaction, |
|
| 1321 | + $info = array(), |
|
| 1322 | + $display_request = false |
|
| 1323 | + ) { |
|
| 1324 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1325 | + if ($transaction instanceof EE_Transaction) { |
|
| 1326 | + // don't serialize objects |
|
| 1327 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1328 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1329 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1330 | + if ($transaction->ID()) { |
|
| 1331 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1332 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Resets all the static properties in this class when called. |
|
| 1341 | + */ |
|
| 1342 | + public static function reset() |
|
| 1343 | + { |
|
| 1344 | + self::$_EEMSG = null; |
|
| 1345 | + self::$_message_resource_manager = null; |
|
| 1346 | + self::$_MSG_PROCESSOR = null; |
|
| 1347 | + self::$_MSG_PATHS = null; |
|
| 1348 | + self::$_TMP_PACKS = array(); |
|
| 1349 | + } |
|
| 1350 | 1350 | } |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.006'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.006'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |