@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,1142 +16,1142 @@ discard block |
||
| 16 | 16 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * the input's name attribute |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $_html_name; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * id for the html label tag |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected $_html_label_id; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * class for teh html label tag |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $_html_label_class; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * any additional html attributes that you may want to add |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $_html_other_attributes; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * style for teh html label tag |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - protected $_html_label_style; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * text to be placed in the html label |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $_html_label_text; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * the full html label. If used, all other html_label_* properties are invalid |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - protected $_html_label; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
| 70 | - * has a class of 'description' |
|
| 71 | - * |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 74 | - protected $_html_help_text; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * CSS classes for displaying the help span |
|
| 78 | - * |
|
| 79 | - * @var string |
|
| 80 | - */ |
|
| 81 | - protected $_html_help_class = 'description'; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * CSS to put in the style attribute on the help span |
|
| 85 | - * |
|
| 86 | - * @var string |
|
| 87 | - */ |
|
| 88 | - protected $_html_help_style; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Stores whether or not this input's response is required. |
|
| 92 | - * Because certain styling elements may also want to know that this |
|
| 93 | - * input is required etc. |
|
| 94 | - * |
|
| 95 | - * @var boolean |
|
| 96 | - */ |
|
| 97 | - protected $_required; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * css class added to required inputs |
|
| 101 | - * |
|
| 102 | - * @var string |
|
| 103 | - */ |
|
| 104 | - protected $_required_css_class = 'ee-required'; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * css styles applied to button type inputs |
|
| 108 | - * |
|
| 109 | - * @var string |
|
| 110 | - */ |
|
| 111 | - protected $_button_css_attributes; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * The raw data submitted for this, like in the $_POST super global. |
|
| 115 | - * Generally unsafe for usage in client code |
|
| 116 | - * |
|
| 117 | - * @var mixed string or array |
|
| 118 | - */ |
|
| 119 | - protected $_raw_value; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Value normalized according to the input's normalization strategy. |
|
| 123 | - * The normalization strategy dictates whether this is a string, int, float, |
|
| 124 | - * boolean, or array of any of those. |
|
| 125 | - * |
|
| 126 | - * @var mixed |
|
| 127 | - */ |
|
| 128 | - protected $_normalized_value; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Strategy used for displaying this field. |
|
| 132 | - * Child classes must use _get_display_strategy to access it. |
|
| 133 | - * |
|
| 134 | - * @var EE_Display_Strategy_Base |
|
| 135 | - */ |
|
| 136 | - private $_display_strategy; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Gets all the validation strategies used on this field |
|
| 140 | - * |
|
| 141 | - * @var EE_Validation_Strategy_Base[] |
|
| 142 | - */ |
|
| 143 | - private $_validation_strategies = array(); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * The normalization strategy for this field |
|
| 147 | - * |
|
| 148 | - * @var EE_Normalization_Strategy_Base |
|
| 149 | - */ |
|
| 150 | - private $_normalization_strategy; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Strategy for removing sensitive data after we're done with the form input |
|
| 154 | - * |
|
| 155 | - * @var EE_Sensitive_Data_Removal_Base |
|
| 156 | - */ |
|
| 157 | - protected $_sensitive_data_removal_strategy; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param array $input_args { |
|
| 163 | - * @type string $html_name the html name for the input |
|
| 164 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
| 165 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
| 166 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
| 167 | - * @type string $html_label_text the text to put in the label tag |
|
| 168 | - * @type string $html_label the full html label. If used, |
|
| 169 | - * all other html_label_* args are invalid |
|
| 170 | - * @type string $html_help_text text to put in help element |
|
| 171 | - * @type string $html_help_style style attribute to give to teh help element |
|
| 172 | - * @type string $html_help_class class attribute to give to the help element |
|
| 173 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
| 174 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
| 175 | - * @type EE_Display_Strategy_Base $display strategy |
|
| 176 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
| 177 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
| 178 | - * } |
|
| 179 | - */ |
|
| 180 | - public function __construct($input_args = array()) |
|
| 181 | - { |
|
| 182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
| 183 | - // the following properties must be cast as arrays |
|
| 184 | - if (isset($input_args['validation_strategies'])) { |
|
| 185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
| 186 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
| 187 | - $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - unset($input_args['validation_strategies']); |
|
| 191 | - } |
|
| 192 | - // loop thru incoming options |
|
| 193 | - foreach ($input_args as $key => $value) { |
|
| 194 | - // add underscore to $key to match property names |
|
| 195 | - $_key = '_' . $key; |
|
| 196 | - if (property_exists($this, $_key)) { |
|
| 197 | - $this->{$_key} = $value; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - // ensure that "required" is set correctly |
|
| 201 | - $this->set_required( |
|
| 202 | - $this->_required, isset($input_args['required_validation_error_message']) |
|
| 203 | - ? $input_args['required_validation_error_message'] |
|
| 204 | - : null |
|
| 205 | - ); |
|
| 206 | - //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
| 207 | - $this->_display_strategy->_construct_finalize($this); |
|
| 208 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 209 | - $validation_strategy->_construct_finalize($this); |
|
| 210 | - } |
|
| 211 | - if (! $this->_normalization_strategy) { |
|
| 212 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
| 213 | - } |
|
| 214 | - $this->_normalization_strategy->_construct_finalize($this); |
|
| 215 | - //at least we can use the normalization strategy to populate the default |
|
| 216 | - if (isset($input_args['default'])) { |
|
| 217 | - $this->set_default($input_args['default']); |
|
| 218 | - } |
|
| 219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
| 220 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
| 221 | - } |
|
| 222 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
| 223 | - parent::__construct($input_args); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
| 230 | - * Calculation involves using the name and the parent's html_name |
|
| 231 | - * |
|
| 232 | - * @throws \EE_Error |
|
| 233 | - */ |
|
| 234 | - protected function _set_default_html_name_if_empty() |
|
| 235 | - { |
|
| 236 | - if (! $this->_html_name) { |
|
| 237 | - $this->_html_name = $this->name(); |
|
| 238 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param $parent_form_section |
|
| 248 | - * @param $name |
|
| 249 | - * @throws \EE_Error |
|
| 250 | - */ |
|
| 251 | - public function _construct_finalize($parent_form_section, $name) |
|
| 252 | - { |
|
| 253 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 254 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
| 255 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
| 256 | - } |
|
| 257 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
| 264 | - * |
|
| 265 | - * @return EE_Display_Strategy_Base |
|
| 266 | - * @throws EE_Error |
|
| 267 | - */ |
|
| 268 | - protected function _get_display_strategy() |
|
| 269 | - { |
|
| 270 | - $this->ensure_construct_finalized_called(); |
|
| 271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
| 272 | - throw new EE_Error( |
|
| 273 | - sprintf( |
|
| 274 | - __( |
|
| 275 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
| 276 | - "event_espresso" |
|
| 277 | - ), |
|
| 278 | - $this->html_name(), |
|
| 279 | - $this->html_id() |
|
| 280 | - ) |
|
| 281 | - ); |
|
| 282 | - } else { |
|
| 283 | - return $this->_display_strategy; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Sets the display strategy. |
|
| 291 | - * |
|
| 292 | - * @param EE_Display_Strategy_Base $strategy |
|
| 293 | - */ |
|
| 294 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
| 295 | - { |
|
| 296 | - $this->_display_strategy = $strategy; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Sets the sanitization strategy |
|
| 303 | - * |
|
| 304 | - * @param EE_Normalization_Strategy_Base $strategy |
|
| 305 | - */ |
|
| 306 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
| 307 | - { |
|
| 308 | - $this->_normalization_strategy = $strategy; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Gets sensitive_data_removal_strategy |
|
| 315 | - * |
|
| 316 | - * @return EE_Sensitive_Data_Removal_Base |
|
| 317 | - */ |
|
| 318 | - public function get_sensitive_data_removal_strategy() |
|
| 319 | - { |
|
| 320 | - return $this->_sensitive_data_removal_strategy; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Sets sensitive_data_removal_strategy |
|
| 327 | - * |
|
| 328 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
| 329 | - * @return boolean |
|
| 330 | - */ |
|
| 331 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
| 332 | - { |
|
| 333 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Gets the display strategy for this input |
|
| 340 | - * |
|
| 341 | - * @return EE_Display_Strategy_Base |
|
| 342 | - */ |
|
| 343 | - public function get_display_strategy() |
|
| 344 | - { |
|
| 345 | - return $this->_display_strategy; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Overwrites the display strategy |
|
| 352 | - * |
|
| 353 | - * @param EE_Display_Strategy_Base $display_strategy |
|
| 354 | - */ |
|
| 355 | - public function set_display_strategy($display_strategy) |
|
| 356 | - { |
|
| 357 | - $this->_display_strategy = $display_strategy; |
|
| 358 | - $this->_display_strategy->_construct_finalize($this); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets the normalization strategy set on this input |
|
| 365 | - * |
|
| 366 | - * @return EE_Normalization_Strategy_Base |
|
| 367 | - */ |
|
| 368 | - public function get_normalization_strategy() |
|
| 369 | - { |
|
| 370 | - return $this->_normalization_strategy; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Overwrites the normalization strategy |
|
| 377 | - * |
|
| 378 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
| 379 | - */ |
|
| 380 | - public function set_normalization_strategy($normalization_strategy) |
|
| 381 | - { |
|
| 382 | - $this->_normalization_strategy = $normalization_strategy; |
|
| 383 | - $this->_normalization_strategy->_construct_finalize($this); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
| 390 | - * |
|
| 391 | - * @return EE_Validation_Strategy_Base[] |
|
| 392 | - */ |
|
| 393 | - public function get_validation_strategies() |
|
| 394 | - { |
|
| 395 | - return $this->_validation_strategies; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
| 402 | - * |
|
| 403 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
| 404 | - * @return void |
|
| 405 | - */ |
|
| 406 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
| 407 | - { |
|
| 408 | - $validation_strategy->_construct_finalize($this); |
|
| 409 | - $this->_validation_strategies[] = $validation_strategy; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Adds a new validation strategy onto the form input |
|
| 416 | - * |
|
| 417 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
| 418 | - * @return void |
|
| 419 | - */ |
|
| 420 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
| 421 | - { |
|
| 422 | - $this->_add_validation_strategy($validation_strategy); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * The classname of the validation strategy to remove |
|
| 429 | - * |
|
| 430 | - * @param string $validation_strategy_classname |
|
| 431 | - */ |
|
| 432 | - public function remove_validation_strategy($validation_strategy_classname) |
|
| 433 | - { |
|
| 434 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
| 435 | - if ( |
|
| 436 | - $validation_strategy instanceof $validation_strategy_classname |
|
| 437 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
| 438 | - ) { |
|
| 439 | - unset($this->_validation_strategies[$key]); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
| 448 | - * |
|
| 449 | - * @param array $validation_strategy_classnames |
|
| 450 | - * @return bool |
|
| 451 | - */ |
|
| 452 | - public function has_validation_strategy($validation_strategy_classnames) |
|
| 453 | - { |
|
| 454 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
| 455 | - ? $validation_strategy_classnames |
|
| 456 | - : array($validation_strategy_classnames); |
|
| 457 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
| 458 | - if (in_array($key, $validation_strategy_classnames)) { |
|
| 459 | - return true; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets the HTML |
|
| 469 | - * |
|
| 470 | - * @return string |
|
| 471 | - */ |
|
| 472 | - public function get_html() |
|
| 473 | - { |
|
| 474 | - return $this->_parent_section->get_html_for_input($this); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
| 481 | - * input's display strategy |
|
| 482 | - * Makes sure the JS and CSS are enqueued for it |
|
| 483 | - * |
|
| 484 | - * @return string |
|
| 485 | - * @throws \EE_Error |
|
| 486 | - */ |
|
| 487 | - public function get_html_for_input() |
|
| 488 | - { |
|
| 489 | - return $this->_form_html_filter |
|
| 490 | - ? $this->_form_html_filter->filterHtml( |
|
| 491 | - $this->_get_display_strategy()->display(), |
|
| 492 | - $this |
|
| 493 | - ) |
|
| 494 | - : $this->_get_display_strategy()->display(); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * @return string |
|
| 501 | - */ |
|
| 502 | - public function html_other_attributes() |
|
| 503 | - { |
|
| 504 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * @param string $html_other_attributes |
|
| 511 | - */ |
|
| 512 | - public function set_html_other_attributes($html_other_attributes) |
|
| 513 | - { |
|
| 514 | - $this->_html_other_attributes = $html_other_attributes; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Gets the HTML for displaying the label for this form input |
|
| 521 | - * according to the form section's layout strategy |
|
| 522 | - * |
|
| 523 | - * @return string |
|
| 524 | - */ |
|
| 525 | - public function get_html_for_label() |
|
| 526 | - { |
|
| 527 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Gets the HTML for displaying the errors section for this form input |
|
| 534 | - * according to the form section's layout strategy |
|
| 535 | - * |
|
| 536 | - * @return string |
|
| 537 | - */ |
|
| 538 | - public function get_html_for_errors() |
|
| 539 | - { |
|
| 540 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Gets the HTML for displaying the help text for this form input |
|
| 547 | - * according to the form section's layout strategy |
|
| 548 | - * |
|
| 549 | - * @return string |
|
| 550 | - */ |
|
| 551 | - public function get_html_for_help() |
|
| 552 | - { |
|
| 553 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
| 560 | - * and returns whether or not the form input's submitted value is value |
|
| 561 | - * |
|
| 562 | - * @return boolean |
|
| 563 | - */ |
|
| 564 | - protected function _validate() |
|
| 565 | - { |
|
| 566 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 567 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
| 568 | - try { |
|
| 569 | - $validation_strategy->validate($this->normalized_value()); |
|
| 570 | - } catch (EE_Validation_Error $e) { |
|
| 571 | - $this->add_validation_error($e); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - if ($this->get_validation_errors()) { |
|
| 576 | - return false; |
|
| 577 | - } else { |
|
| 578 | - return true; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
| 586 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
| 587 | - * |
|
| 588 | - * @param string $value |
|
| 589 | - * @return null|string |
|
| 590 | - */ |
|
| 591 | - private function _sanitize($value) |
|
| 592 | - { |
|
| 593 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Picks out the form value that relates to this form input, |
|
| 600 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
| 601 | - * Returns whether or not any validation errors occurred |
|
| 602 | - * |
|
| 603 | - * @param array $req_data like $_POST |
|
| 604 | - * @return boolean whether or not there was an error |
|
| 605 | - * @throws \EE_Error |
|
| 606 | - */ |
|
| 607 | - protected function _normalize($req_data) |
|
| 608 | - { |
|
| 609 | - //any existing validation errors don't apply so clear them |
|
| 610 | - $this->_validation_errors = array(); |
|
| 611 | - try { |
|
| 612 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
| 613 | - //super simple sanitization for now |
|
| 614 | - if (is_array($raw_input)) { |
|
| 615 | - $raw_value = array(); |
|
| 616 | - foreach ($raw_input as $key => $value) { |
|
| 617 | - $raw_value[$key] = $this->_sanitize($value); |
|
| 618 | - } |
|
| 619 | - $this->_set_raw_value($raw_value); |
|
| 620 | - } else { |
|
| 621 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
| 622 | - } |
|
| 623 | - //we want to mostly leave the input alone in case we need to re-display it to the user |
|
| 624 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
| 625 | - } catch (EE_Validation_Error $e) { |
|
| 626 | - $this->add_validation_error($e); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * @return string |
|
| 634 | - */ |
|
| 635 | - public function html_name() |
|
| 636 | - { |
|
| 637 | - $this->_set_default_html_name_if_empty(); |
|
| 638 | - return $this->_html_name; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * @return string |
|
| 645 | - */ |
|
| 646 | - public function html_label_id() |
|
| 647 | - { |
|
| 648 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * @return string |
|
| 655 | - */ |
|
| 656 | - public function html_label_class() |
|
| 657 | - { |
|
| 658 | - return $this->_html_label_class; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * @return string |
|
| 665 | - */ |
|
| 666 | - public function html_label_style() |
|
| 667 | - { |
|
| 668 | - return $this->_html_label_style; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * @return string |
|
| 675 | - */ |
|
| 676 | - public function html_label_text() |
|
| 677 | - { |
|
| 678 | - return $this->_html_label_text; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @return string |
|
| 685 | - */ |
|
| 686 | - public function html_help_text() |
|
| 687 | - { |
|
| 688 | - return $this->_html_help_text; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * @return string |
|
| 695 | - */ |
|
| 696 | - public function html_help_class() |
|
| 697 | - { |
|
| 698 | - return $this->_html_help_class; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * @return string |
|
| 705 | - */ |
|
| 706 | - public function html_help_style() |
|
| 707 | - { |
|
| 708 | - return $this->_html_style; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
| 715 | - * Please note that almost all client code should instead use the normalized_value; |
|
| 716 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
| 717 | - * mostly by escaping quotes) |
|
| 718 | - * Note, we do not store the exact original value sent in the user's request because |
|
| 719 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
| 720 | - * in which case, we would have stored the malicious content to our database. |
|
| 721 | - * |
|
| 722 | - * @return string |
|
| 723 | - */ |
|
| 724 | - public function raw_value() |
|
| 725 | - { |
|
| 726 | - return $this->_raw_value; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * Returns a string safe to usage in form inputs when displaying, because |
|
| 733 | - * it escapes all html entities |
|
| 734 | - * |
|
| 735 | - * @return string |
|
| 736 | - */ |
|
| 737 | - public function raw_value_in_form() |
|
| 738 | - { |
|
| 739 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
| 746 | - * in PHP. Eg, a string, an int, an array, |
|
| 747 | - * |
|
| 748 | - * @return mixed |
|
| 749 | - */ |
|
| 750 | - public function normalized_value() |
|
| 751 | - { |
|
| 752 | - return $this->_normalized_value; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * Returns the normalized value is a presentable way. By default this is just |
|
| 759 | - * the normalized value by itself, but it can be overridden for when that's not |
|
| 760 | - * the best thing to display |
|
| 761 | - * |
|
| 762 | - * @return string |
|
| 763 | - */ |
|
| 764 | - public function pretty_value() |
|
| 765 | - { |
|
| 766 | - return $this->_normalized_value; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * When generating the JS for the jquery validation rules like<br> |
|
| 773 | - * <code>$( "#myform" ).validate({ |
|
| 774 | - * rules: { |
|
| 775 | - * password: "required", |
|
| 776 | - * password_again: { |
|
| 777 | - * equalTo: "#password" |
|
| 778 | - * } |
|
| 779 | - * } |
|
| 780 | - * });</code> |
|
| 781 | - * if this field had the name 'password_again', it should return |
|
| 782 | - * <br><code>password_again: { |
|
| 783 | - * equalTo: "#password" |
|
| 784 | - * }</code> |
|
| 785 | - * |
|
| 786 | - * @return array |
|
| 787 | - */ |
|
| 788 | - public function get_jquery_validation_rules() |
|
| 789 | - { |
|
| 790 | - $jquery_validation_js = array(); |
|
| 791 | - $jquery_validation_rules = array(); |
|
| 792 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 793 | - $jquery_validation_rules = array_replace_recursive( |
|
| 794 | - $jquery_validation_rules, |
|
| 795 | - $validation_strategy->get_jquery_validation_rule_array() |
|
| 796 | - ); |
|
| 797 | - } |
|
| 798 | - if (! empty($jquery_validation_rules)) { |
|
| 799 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
| 800 | - $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - return $jquery_validation_js; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
| 810 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
| 811 | - * |
|
| 812 | - * @param mixed $value |
|
| 813 | - * @return void |
|
| 814 | - */ |
|
| 815 | - public function set_default($value) |
|
| 816 | - { |
|
| 817 | - $this->_set_normalized_value($value); |
|
| 818 | - $this->_set_raw_value($value); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Sets the normalized value on this input |
|
| 825 | - * |
|
| 826 | - * @param mixed $value |
|
| 827 | - */ |
|
| 828 | - protected function _set_normalized_value($value) |
|
| 829 | - { |
|
| 830 | - $this->_normalized_value = $value; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
| 837 | - * |
|
| 838 | - * @param mixed $value |
|
| 839 | - */ |
|
| 840 | - protected function _set_raw_value($value) |
|
| 841 | - { |
|
| 842 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Sets the HTML label text after it has already been defined |
|
| 849 | - * |
|
| 850 | - * @param string $label |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - public function set_html_label_text($label) |
|
| 854 | - { |
|
| 855 | - $this->_html_label_text = $label; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
| 862 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
| 863 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
| 864 | - * |
|
| 865 | - * @param boolean $required boolean |
|
| 866 | - * @param null $required_text |
|
| 867 | - */ |
|
| 868 | - public function set_required($required = true, $required_text = null) |
|
| 869 | - { |
|
| 870 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
| 871 | - //whether $required is a string or a boolean, we want to add a required validation strategy |
|
| 872 | - if ($required) { |
|
| 873 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
| 874 | - } else { |
|
| 875 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
| 876 | - } |
|
| 877 | - $this->_required = $required; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Returns whether or not this field is required |
|
| 884 | - * |
|
| 885 | - * @return boolean |
|
| 886 | - */ |
|
| 887 | - public function required() |
|
| 888 | - { |
|
| 889 | - return $this->_required; |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * @param string $required_css_class |
|
| 896 | - */ |
|
| 897 | - public function set_required_css_class($required_css_class) |
|
| 898 | - { |
|
| 899 | - $this->_required_css_class = $required_css_class; |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * @return string |
|
| 906 | - */ |
|
| 907 | - public function required_css_class() |
|
| 908 | - { |
|
| 909 | - return $this->_required_css_class; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * @param bool $add_required |
|
| 916 | - * @return string |
|
| 917 | - */ |
|
| 918 | - public function html_class($add_required = false) |
|
| 919 | - { |
|
| 920 | - return $add_required && $this->required() |
|
| 921 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
| 922 | - : $this->_html_class; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Sets the help text, in case |
|
| 928 | - * |
|
| 929 | - * @param string $text |
|
| 930 | - */ |
|
| 931 | - public function set_html_help_text($text) |
|
| 932 | - { |
|
| 933 | - $this->_html_help_text = $text; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
| 940 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
| 941 | - * out the raw value completely |
|
| 942 | - * |
|
| 943 | - * @return void |
|
| 944 | - */ |
|
| 945 | - public function clean_sensitive_data() |
|
| 946 | - { |
|
| 947 | - //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
| 948 | - //if we need more logic than this we'll make a strategy for it |
|
| 949 | - if ($this->_sensitive_data_removal_strategy |
|
| 950 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
| 951 | - ) { |
|
| 952 | - $this->_set_raw_value(null); |
|
| 953 | - } |
|
| 954 | - //and clean the normalized value according to the appropriate strategy |
|
| 955 | - $this->_set_normalized_value( |
|
| 956 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
| 957 | - $this->_normalized_value |
|
| 958 | - ) |
|
| 959 | - ); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * @param bool $primary |
|
| 966 | - * @param string $button_size |
|
| 967 | - * @param string $other_attributes |
|
| 968 | - */ |
|
| 969 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
| 970 | - { |
|
| 971 | - $button_css_attributes = 'button'; |
|
| 972 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
| 973 | - switch ($button_size) { |
|
| 974 | - case 'xs' : |
|
| 975 | - case 'extra-small' : |
|
| 976 | - $button_css_attributes .= ' button-xs'; |
|
| 977 | - break; |
|
| 978 | - case 'sm' : |
|
| 979 | - case 'small' : |
|
| 980 | - $button_css_attributes .= ' button-sm'; |
|
| 981 | - break; |
|
| 982 | - case 'lg' : |
|
| 983 | - case 'large' : |
|
| 984 | - $button_css_attributes .= ' button-lg'; |
|
| 985 | - break; |
|
| 986 | - case 'block' : |
|
| 987 | - $button_css_attributes .= ' button-block'; |
|
| 988 | - break; |
|
| 989 | - case 'md' : |
|
| 990 | - case 'medium' : |
|
| 991 | - default : |
|
| 992 | - $button_css_attributes .= ''; |
|
| 993 | - } |
|
| 994 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
| 995 | - ? $button_css_attributes . ' ' . $other_attributes |
|
| 996 | - : $button_css_attributes; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * @return string |
|
| 1003 | - */ |
|
| 1004 | - public function button_css_attributes() |
|
| 1005 | - { |
|
| 1006 | - if (empty($this->_button_css_attributes)) { |
|
| 1007 | - $this->set_button_css_attributes(); |
|
| 1008 | - } |
|
| 1009 | - return $this->_button_css_attributes; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * find_form_data_for_this_section |
|
| 1016 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
| 1017 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
| 1018 | - * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
| 1019 | - * (If that doesn't exist, we also check for this subsection's name |
|
| 1020 | - * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
| 1021 | - * This function finds its value in the form. |
|
| 1022 | - * |
|
| 1023 | - * @param array $req_data |
|
| 1024 | - * @return mixed whatever the raw value of this form section is in the request data |
|
| 1025 | - * @throws \EE_Error |
|
| 1026 | - */ |
|
| 1027 | - public function find_form_data_for_this_section($req_data) |
|
| 1028 | - { |
|
| 1029 | - // break up the html name by "[]" |
|
| 1030 | - if (strpos($this->html_name(), '[') !== false) { |
|
| 1031 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
| 1032 | - } else { |
|
| 1033 | - $before_any_brackets = $this->html_name(); |
|
| 1034 | - } |
|
| 1035 | - // grab all of the segments |
|
| 1036 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
| 1037 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
| 1038 | - $name_parts = $matches[1]; |
|
| 1039 | - array_unshift($name_parts, $before_any_brackets); |
|
| 1040 | - } else { |
|
| 1041 | - $name_parts = array($before_any_brackets); |
|
| 1042 | - } |
|
| 1043 | - // now get the value for the input |
|
| 1044 | - $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
| 1045 | - // check if this thing's name is at the TOP level of the request data |
|
| 1046 | - if ($value === null && isset($req_data[$this->name()])) { |
|
| 1047 | - $value = $req_data[$this->name()]; |
|
| 1048 | - } |
|
| 1049 | - return $value; |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * @param array $html_name_parts |
|
| 1056 | - * @param array $req_data |
|
| 1057 | - * @return array | NULL |
|
| 1058 | - */ |
|
| 1059 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
| 1060 | - { |
|
| 1061 | - $first_part_to_consider = array_shift($html_name_parts); |
|
| 1062 | - if (isset($req_data[$first_part_to_consider])) { |
|
| 1063 | - if (empty($html_name_parts)) { |
|
| 1064 | - return $req_data[$first_part_to_consider]; |
|
| 1065 | - } else { |
|
| 1066 | - return $this->_find_form_data_for_this_section_using_name_parts( |
|
| 1067 | - $html_name_parts, |
|
| 1068 | - $req_data[$first_part_to_consider] |
|
| 1069 | - ); |
|
| 1070 | - } |
|
| 1071 | - } else { |
|
| 1072 | - return null; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * Checks if this form input's data is in the request data |
|
| 1080 | - * |
|
| 1081 | - * @param array $req_data like $_POST |
|
| 1082 | - * @return boolean |
|
| 1083 | - * @throws \EE_Error |
|
| 1084 | - */ |
|
| 1085 | - public function form_data_present_in($req_data = null) |
|
| 1086 | - { |
|
| 1087 | - if ($req_data === null) { |
|
| 1088 | - $req_data = $_POST; |
|
| 1089 | - } |
|
| 1090 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
| 1091 | - if ($checked_value !== null) { |
|
| 1092 | - return true; |
|
| 1093 | - } else { |
|
| 1094 | - return false; |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - /** |
|
| 1101 | - * Overrides parent to add js data from validation and display strategies |
|
| 1102 | - * |
|
| 1103 | - * @param array $form_other_js_data |
|
| 1104 | - * @return array |
|
| 1105 | - */ |
|
| 1106 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 1107 | - { |
|
| 1108 | - $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
| 1109 | - return $form_other_js_data; |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * Gets other JS data for localization from this input's strategies, like |
|
| 1116 | - * the validation strategies and the display strategy |
|
| 1117 | - * |
|
| 1118 | - * @param array $form_other_js_data |
|
| 1119 | - * @return array |
|
| 1120 | - */ |
|
| 1121 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
| 1122 | - { |
|
| 1123 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
| 1124 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 1125 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
| 1126 | - } |
|
| 1127 | - return $form_other_js_data; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
| 1134 | - * |
|
| 1135 | - * @return void |
|
| 1136 | - */ |
|
| 1137 | - public function enqueue_js() |
|
| 1138 | - { |
|
| 1139 | - //ask our display strategy and validation strategies if they have js to enqueue |
|
| 1140 | - $this->enqueue_js_from_strategies(); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - /** |
|
| 1146 | - * Tells strategies when its ok to enqueue their js and css |
|
| 1147 | - * |
|
| 1148 | - * @return void |
|
| 1149 | - */ |
|
| 1150 | - public function enqueue_js_from_strategies() |
|
| 1151 | - { |
|
| 1152 | - $this->get_display_strategy()->enqueue_js(); |
|
| 1153 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 1154 | - $validation_strategy->enqueue_js(); |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 19 | + /** |
|
| 20 | + * the input's name attribute |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $_html_name; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * id for the html label tag |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected $_html_label_id; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * class for teh html label tag |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $_html_label_class; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * any additional html attributes that you may want to add |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $_html_other_attributes; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * style for teh html label tag |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + protected $_html_label_style; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * text to be placed in the html label |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $_html_label_text; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * the full html label. If used, all other html_label_* properties are invalid |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + protected $_html_label; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
| 70 | + * has a class of 'description' |
|
| 71 | + * |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | + protected $_html_help_text; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * CSS classes for displaying the help span |
|
| 78 | + * |
|
| 79 | + * @var string |
|
| 80 | + */ |
|
| 81 | + protected $_html_help_class = 'description'; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * CSS to put in the style attribute on the help span |
|
| 85 | + * |
|
| 86 | + * @var string |
|
| 87 | + */ |
|
| 88 | + protected $_html_help_style; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Stores whether or not this input's response is required. |
|
| 92 | + * Because certain styling elements may also want to know that this |
|
| 93 | + * input is required etc. |
|
| 94 | + * |
|
| 95 | + * @var boolean |
|
| 96 | + */ |
|
| 97 | + protected $_required; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * css class added to required inputs |
|
| 101 | + * |
|
| 102 | + * @var string |
|
| 103 | + */ |
|
| 104 | + protected $_required_css_class = 'ee-required'; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * css styles applied to button type inputs |
|
| 108 | + * |
|
| 109 | + * @var string |
|
| 110 | + */ |
|
| 111 | + protected $_button_css_attributes; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * The raw data submitted for this, like in the $_POST super global. |
|
| 115 | + * Generally unsafe for usage in client code |
|
| 116 | + * |
|
| 117 | + * @var mixed string or array |
|
| 118 | + */ |
|
| 119 | + protected $_raw_value; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Value normalized according to the input's normalization strategy. |
|
| 123 | + * The normalization strategy dictates whether this is a string, int, float, |
|
| 124 | + * boolean, or array of any of those. |
|
| 125 | + * |
|
| 126 | + * @var mixed |
|
| 127 | + */ |
|
| 128 | + protected $_normalized_value; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Strategy used for displaying this field. |
|
| 132 | + * Child classes must use _get_display_strategy to access it. |
|
| 133 | + * |
|
| 134 | + * @var EE_Display_Strategy_Base |
|
| 135 | + */ |
|
| 136 | + private $_display_strategy; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Gets all the validation strategies used on this field |
|
| 140 | + * |
|
| 141 | + * @var EE_Validation_Strategy_Base[] |
|
| 142 | + */ |
|
| 143 | + private $_validation_strategies = array(); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * The normalization strategy for this field |
|
| 147 | + * |
|
| 148 | + * @var EE_Normalization_Strategy_Base |
|
| 149 | + */ |
|
| 150 | + private $_normalization_strategy; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Strategy for removing sensitive data after we're done with the form input |
|
| 154 | + * |
|
| 155 | + * @var EE_Sensitive_Data_Removal_Base |
|
| 156 | + */ |
|
| 157 | + protected $_sensitive_data_removal_strategy; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param array $input_args { |
|
| 163 | + * @type string $html_name the html name for the input |
|
| 164 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
| 165 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
| 166 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
| 167 | + * @type string $html_label_text the text to put in the label tag |
|
| 168 | + * @type string $html_label the full html label. If used, |
|
| 169 | + * all other html_label_* args are invalid |
|
| 170 | + * @type string $html_help_text text to put in help element |
|
| 171 | + * @type string $html_help_style style attribute to give to teh help element |
|
| 172 | + * @type string $html_help_class class attribute to give to the help element |
|
| 173 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
| 174 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
| 175 | + * @type EE_Display_Strategy_Base $display strategy |
|
| 176 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
| 177 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
| 178 | + * } |
|
| 179 | + */ |
|
| 180 | + public function __construct($input_args = array()) |
|
| 181 | + { |
|
| 182 | + $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
| 183 | + // the following properties must be cast as arrays |
|
| 184 | + if (isset($input_args['validation_strategies'])) { |
|
| 185 | + foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
| 186 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
| 187 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + unset($input_args['validation_strategies']); |
|
| 191 | + } |
|
| 192 | + // loop thru incoming options |
|
| 193 | + foreach ($input_args as $key => $value) { |
|
| 194 | + // add underscore to $key to match property names |
|
| 195 | + $_key = '_' . $key; |
|
| 196 | + if (property_exists($this, $_key)) { |
|
| 197 | + $this->{$_key} = $value; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + // ensure that "required" is set correctly |
|
| 201 | + $this->set_required( |
|
| 202 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
| 203 | + ? $input_args['required_validation_error_message'] |
|
| 204 | + : null |
|
| 205 | + ); |
|
| 206 | + //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
| 207 | + $this->_display_strategy->_construct_finalize($this); |
|
| 208 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 209 | + $validation_strategy->_construct_finalize($this); |
|
| 210 | + } |
|
| 211 | + if (! $this->_normalization_strategy) { |
|
| 212 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
| 213 | + } |
|
| 214 | + $this->_normalization_strategy->_construct_finalize($this); |
|
| 215 | + //at least we can use the normalization strategy to populate the default |
|
| 216 | + if (isset($input_args['default'])) { |
|
| 217 | + $this->set_default($input_args['default']); |
|
| 218 | + } |
|
| 219 | + if (! $this->_sensitive_data_removal_strategy) { |
|
| 220 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
| 221 | + } |
|
| 222 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
| 223 | + parent::__construct($input_args); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
| 230 | + * Calculation involves using the name and the parent's html_name |
|
| 231 | + * |
|
| 232 | + * @throws \EE_Error |
|
| 233 | + */ |
|
| 234 | + protected function _set_default_html_name_if_empty() |
|
| 235 | + { |
|
| 236 | + if (! $this->_html_name) { |
|
| 237 | + $this->_html_name = $this->name(); |
|
| 238 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 239 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param $parent_form_section |
|
| 248 | + * @param $name |
|
| 249 | + * @throws \EE_Error |
|
| 250 | + */ |
|
| 251 | + public function _construct_finalize($parent_form_section, $name) |
|
| 252 | + { |
|
| 253 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 254 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
| 255 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
| 256 | + } |
|
| 257 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
| 264 | + * |
|
| 265 | + * @return EE_Display_Strategy_Base |
|
| 266 | + * @throws EE_Error |
|
| 267 | + */ |
|
| 268 | + protected function _get_display_strategy() |
|
| 269 | + { |
|
| 270 | + $this->ensure_construct_finalized_called(); |
|
| 271 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
| 272 | + throw new EE_Error( |
|
| 273 | + sprintf( |
|
| 274 | + __( |
|
| 275 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
| 276 | + "event_espresso" |
|
| 277 | + ), |
|
| 278 | + $this->html_name(), |
|
| 279 | + $this->html_id() |
|
| 280 | + ) |
|
| 281 | + ); |
|
| 282 | + } else { |
|
| 283 | + return $this->_display_strategy; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Sets the display strategy. |
|
| 291 | + * |
|
| 292 | + * @param EE_Display_Strategy_Base $strategy |
|
| 293 | + */ |
|
| 294 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
| 295 | + { |
|
| 296 | + $this->_display_strategy = $strategy; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Sets the sanitization strategy |
|
| 303 | + * |
|
| 304 | + * @param EE_Normalization_Strategy_Base $strategy |
|
| 305 | + */ |
|
| 306 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
| 307 | + { |
|
| 308 | + $this->_normalization_strategy = $strategy; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Gets sensitive_data_removal_strategy |
|
| 315 | + * |
|
| 316 | + * @return EE_Sensitive_Data_Removal_Base |
|
| 317 | + */ |
|
| 318 | + public function get_sensitive_data_removal_strategy() |
|
| 319 | + { |
|
| 320 | + return $this->_sensitive_data_removal_strategy; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Sets sensitive_data_removal_strategy |
|
| 327 | + * |
|
| 328 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
| 329 | + * @return boolean |
|
| 330 | + */ |
|
| 331 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
| 332 | + { |
|
| 333 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Gets the display strategy for this input |
|
| 340 | + * |
|
| 341 | + * @return EE_Display_Strategy_Base |
|
| 342 | + */ |
|
| 343 | + public function get_display_strategy() |
|
| 344 | + { |
|
| 345 | + return $this->_display_strategy; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Overwrites the display strategy |
|
| 352 | + * |
|
| 353 | + * @param EE_Display_Strategy_Base $display_strategy |
|
| 354 | + */ |
|
| 355 | + public function set_display_strategy($display_strategy) |
|
| 356 | + { |
|
| 357 | + $this->_display_strategy = $display_strategy; |
|
| 358 | + $this->_display_strategy->_construct_finalize($this); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets the normalization strategy set on this input |
|
| 365 | + * |
|
| 366 | + * @return EE_Normalization_Strategy_Base |
|
| 367 | + */ |
|
| 368 | + public function get_normalization_strategy() |
|
| 369 | + { |
|
| 370 | + return $this->_normalization_strategy; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Overwrites the normalization strategy |
|
| 377 | + * |
|
| 378 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
| 379 | + */ |
|
| 380 | + public function set_normalization_strategy($normalization_strategy) |
|
| 381 | + { |
|
| 382 | + $this->_normalization_strategy = $normalization_strategy; |
|
| 383 | + $this->_normalization_strategy->_construct_finalize($this); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
| 390 | + * |
|
| 391 | + * @return EE_Validation_Strategy_Base[] |
|
| 392 | + */ |
|
| 393 | + public function get_validation_strategies() |
|
| 394 | + { |
|
| 395 | + return $this->_validation_strategies; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
| 402 | + * |
|
| 403 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
| 404 | + * @return void |
|
| 405 | + */ |
|
| 406 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
| 407 | + { |
|
| 408 | + $validation_strategy->_construct_finalize($this); |
|
| 409 | + $this->_validation_strategies[] = $validation_strategy; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Adds a new validation strategy onto the form input |
|
| 416 | + * |
|
| 417 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
| 418 | + * @return void |
|
| 419 | + */ |
|
| 420 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
| 421 | + { |
|
| 422 | + $this->_add_validation_strategy($validation_strategy); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * The classname of the validation strategy to remove |
|
| 429 | + * |
|
| 430 | + * @param string $validation_strategy_classname |
|
| 431 | + */ |
|
| 432 | + public function remove_validation_strategy($validation_strategy_classname) |
|
| 433 | + { |
|
| 434 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
| 435 | + if ( |
|
| 436 | + $validation_strategy instanceof $validation_strategy_classname |
|
| 437 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
| 438 | + ) { |
|
| 439 | + unset($this->_validation_strategies[$key]); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
| 448 | + * |
|
| 449 | + * @param array $validation_strategy_classnames |
|
| 450 | + * @return bool |
|
| 451 | + */ |
|
| 452 | + public function has_validation_strategy($validation_strategy_classnames) |
|
| 453 | + { |
|
| 454 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
| 455 | + ? $validation_strategy_classnames |
|
| 456 | + : array($validation_strategy_classnames); |
|
| 457 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
| 458 | + if (in_array($key, $validation_strategy_classnames)) { |
|
| 459 | + return true; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets the HTML |
|
| 469 | + * |
|
| 470 | + * @return string |
|
| 471 | + */ |
|
| 472 | + public function get_html() |
|
| 473 | + { |
|
| 474 | + return $this->_parent_section->get_html_for_input($this); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
| 481 | + * input's display strategy |
|
| 482 | + * Makes sure the JS and CSS are enqueued for it |
|
| 483 | + * |
|
| 484 | + * @return string |
|
| 485 | + * @throws \EE_Error |
|
| 486 | + */ |
|
| 487 | + public function get_html_for_input() |
|
| 488 | + { |
|
| 489 | + return $this->_form_html_filter |
|
| 490 | + ? $this->_form_html_filter->filterHtml( |
|
| 491 | + $this->_get_display_strategy()->display(), |
|
| 492 | + $this |
|
| 493 | + ) |
|
| 494 | + : $this->_get_display_strategy()->display(); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * @return string |
|
| 501 | + */ |
|
| 502 | + public function html_other_attributes() |
|
| 503 | + { |
|
| 504 | + return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * @param string $html_other_attributes |
|
| 511 | + */ |
|
| 512 | + public function set_html_other_attributes($html_other_attributes) |
|
| 513 | + { |
|
| 514 | + $this->_html_other_attributes = $html_other_attributes; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Gets the HTML for displaying the label for this form input |
|
| 521 | + * according to the form section's layout strategy |
|
| 522 | + * |
|
| 523 | + * @return string |
|
| 524 | + */ |
|
| 525 | + public function get_html_for_label() |
|
| 526 | + { |
|
| 527 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Gets the HTML for displaying the errors section for this form input |
|
| 534 | + * according to the form section's layout strategy |
|
| 535 | + * |
|
| 536 | + * @return string |
|
| 537 | + */ |
|
| 538 | + public function get_html_for_errors() |
|
| 539 | + { |
|
| 540 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Gets the HTML for displaying the help text for this form input |
|
| 547 | + * according to the form section's layout strategy |
|
| 548 | + * |
|
| 549 | + * @return string |
|
| 550 | + */ |
|
| 551 | + public function get_html_for_help() |
|
| 552 | + { |
|
| 553 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
| 560 | + * and returns whether or not the form input's submitted value is value |
|
| 561 | + * |
|
| 562 | + * @return boolean |
|
| 563 | + */ |
|
| 564 | + protected function _validate() |
|
| 565 | + { |
|
| 566 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 567 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
| 568 | + try { |
|
| 569 | + $validation_strategy->validate($this->normalized_value()); |
|
| 570 | + } catch (EE_Validation_Error $e) { |
|
| 571 | + $this->add_validation_error($e); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + if ($this->get_validation_errors()) { |
|
| 576 | + return false; |
|
| 577 | + } else { |
|
| 578 | + return true; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
| 586 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
| 587 | + * |
|
| 588 | + * @param string $value |
|
| 589 | + * @return null|string |
|
| 590 | + */ |
|
| 591 | + private function _sanitize($value) |
|
| 592 | + { |
|
| 593 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Picks out the form value that relates to this form input, |
|
| 600 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
| 601 | + * Returns whether or not any validation errors occurred |
|
| 602 | + * |
|
| 603 | + * @param array $req_data like $_POST |
|
| 604 | + * @return boolean whether or not there was an error |
|
| 605 | + * @throws \EE_Error |
|
| 606 | + */ |
|
| 607 | + protected function _normalize($req_data) |
|
| 608 | + { |
|
| 609 | + //any existing validation errors don't apply so clear them |
|
| 610 | + $this->_validation_errors = array(); |
|
| 611 | + try { |
|
| 612 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
| 613 | + //super simple sanitization for now |
|
| 614 | + if (is_array($raw_input)) { |
|
| 615 | + $raw_value = array(); |
|
| 616 | + foreach ($raw_input as $key => $value) { |
|
| 617 | + $raw_value[$key] = $this->_sanitize($value); |
|
| 618 | + } |
|
| 619 | + $this->_set_raw_value($raw_value); |
|
| 620 | + } else { |
|
| 621 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
| 622 | + } |
|
| 623 | + //we want to mostly leave the input alone in case we need to re-display it to the user |
|
| 624 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
| 625 | + } catch (EE_Validation_Error $e) { |
|
| 626 | + $this->add_validation_error($e); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * @return string |
|
| 634 | + */ |
|
| 635 | + public function html_name() |
|
| 636 | + { |
|
| 637 | + $this->_set_default_html_name_if_empty(); |
|
| 638 | + return $this->_html_name; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * @return string |
|
| 645 | + */ |
|
| 646 | + public function html_label_id() |
|
| 647 | + { |
|
| 648 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * @return string |
|
| 655 | + */ |
|
| 656 | + public function html_label_class() |
|
| 657 | + { |
|
| 658 | + return $this->_html_label_class; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * @return string |
|
| 665 | + */ |
|
| 666 | + public function html_label_style() |
|
| 667 | + { |
|
| 668 | + return $this->_html_label_style; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * @return string |
|
| 675 | + */ |
|
| 676 | + public function html_label_text() |
|
| 677 | + { |
|
| 678 | + return $this->_html_label_text; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @return string |
|
| 685 | + */ |
|
| 686 | + public function html_help_text() |
|
| 687 | + { |
|
| 688 | + return $this->_html_help_text; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * @return string |
|
| 695 | + */ |
|
| 696 | + public function html_help_class() |
|
| 697 | + { |
|
| 698 | + return $this->_html_help_class; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * @return string |
|
| 705 | + */ |
|
| 706 | + public function html_help_style() |
|
| 707 | + { |
|
| 708 | + return $this->_html_style; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
| 715 | + * Please note that almost all client code should instead use the normalized_value; |
|
| 716 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
| 717 | + * mostly by escaping quotes) |
|
| 718 | + * Note, we do not store the exact original value sent in the user's request because |
|
| 719 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
| 720 | + * in which case, we would have stored the malicious content to our database. |
|
| 721 | + * |
|
| 722 | + * @return string |
|
| 723 | + */ |
|
| 724 | + public function raw_value() |
|
| 725 | + { |
|
| 726 | + return $this->_raw_value; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * Returns a string safe to usage in form inputs when displaying, because |
|
| 733 | + * it escapes all html entities |
|
| 734 | + * |
|
| 735 | + * @return string |
|
| 736 | + */ |
|
| 737 | + public function raw_value_in_form() |
|
| 738 | + { |
|
| 739 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
| 746 | + * in PHP. Eg, a string, an int, an array, |
|
| 747 | + * |
|
| 748 | + * @return mixed |
|
| 749 | + */ |
|
| 750 | + public function normalized_value() |
|
| 751 | + { |
|
| 752 | + return $this->_normalized_value; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * Returns the normalized value is a presentable way. By default this is just |
|
| 759 | + * the normalized value by itself, but it can be overridden for when that's not |
|
| 760 | + * the best thing to display |
|
| 761 | + * |
|
| 762 | + * @return string |
|
| 763 | + */ |
|
| 764 | + public function pretty_value() |
|
| 765 | + { |
|
| 766 | + return $this->_normalized_value; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * When generating the JS for the jquery validation rules like<br> |
|
| 773 | + * <code>$( "#myform" ).validate({ |
|
| 774 | + * rules: { |
|
| 775 | + * password: "required", |
|
| 776 | + * password_again: { |
|
| 777 | + * equalTo: "#password" |
|
| 778 | + * } |
|
| 779 | + * } |
|
| 780 | + * });</code> |
|
| 781 | + * if this field had the name 'password_again', it should return |
|
| 782 | + * <br><code>password_again: { |
|
| 783 | + * equalTo: "#password" |
|
| 784 | + * }</code> |
|
| 785 | + * |
|
| 786 | + * @return array |
|
| 787 | + */ |
|
| 788 | + public function get_jquery_validation_rules() |
|
| 789 | + { |
|
| 790 | + $jquery_validation_js = array(); |
|
| 791 | + $jquery_validation_rules = array(); |
|
| 792 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 793 | + $jquery_validation_rules = array_replace_recursive( |
|
| 794 | + $jquery_validation_rules, |
|
| 795 | + $validation_strategy->get_jquery_validation_rule_array() |
|
| 796 | + ); |
|
| 797 | + } |
|
| 798 | + if (! empty($jquery_validation_rules)) { |
|
| 799 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
| 800 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + return $jquery_validation_js; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
| 810 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
| 811 | + * |
|
| 812 | + * @param mixed $value |
|
| 813 | + * @return void |
|
| 814 | + */ |
|
| 815 | + public function set_default($value) |
|
| 816 | + { |
|
| 817 | + $this->_set_normalized_value($value); |
|
| 818 | + $this->_set_raw_value($value); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Sets the normalized value on this input |
|
| 825 | + * |
|
| 826 | + * @param mixed $value |
|
| 827 | + */ |
|
| 828 | + protected function _set_normalized_value($value) |
|
| 829 | + { |
|
| 830 | + $this->_normalized_value = $value; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
| 837 | + * |
|
| 838 | + * @param mixed $value |
|
| 839 | + */ |
|
| 840 | + protected function _set_raw_value($value) |
|
| 841 | + { |
|
| 842 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Sets the HTML label text after it has already been defined |
|
| 849 | + * |
|
| 850 | + * @param string $label |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + public function set_html_label_text($label) |
|
| 854 | + { |
|
| 855 | + $this->_html_label_text = $label; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
| 862 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
| 863 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
| 864 | + * |
|
| 865 | + * @param boolean $required boolean |
|
| 866 | + * @param null $required_text |
|
| 867 | + */ |
|
| 868 | + public function set_required($required = true, $required_text = null) |
|
| 869 | + { |
|
| 870 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
| 871 | + //whether $required is a string or a boolean, we want to add a required validation strategy |
|
| 872 | + if ($required) { |
|
| 873 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
| 874 | + } else { |
|
| 875 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
| 876 | + } |
|
| 877 | + $this->_required = $required; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Returns whether or not this field is required |
|
| 884 | + * |
|
| 885 | + * @return boolean |
|
| 886 | + */ |
|
| 887 | + public function required() |
|
| 888 | + { |
|
| 889 | + return $this->_required; |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * @param string $required_css_class |
|
| 896 | + */ |
|
| 897 | + public function set_required_css_class($required_css_class) |
|
| 898 | + { |
|
| 899 | + $this->_required_css_class = $required_css_class; |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * @return string |
|
| 906 | + */ |
|
| 907 | + public function required_css_class() |
|
| 908 | + { |
|
| 909 | + return $this->_required_css_class; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * @param bool $add_required |
|
| 916 | + * @return string |
|
| 917 | + */ |
|
| 918 | + public function html_class($add_required = false) |
|
| 919 | + { |
|
| 920 | + return $add_required && $this->required() |
|
| 921 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
| 922 | + : $this->_html_class; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Sets the help text, in case |
|
| 928 | + * |
|
| 929 | + * @param string $text |
|
| 930 | + */ |
|
| 931 | + public function set_html_help_text($text) |
|
| 932 | + { |
|
| 933 | + $this->_html_help_text = $text; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
| 940 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
| 941 | + * out the raw value completely |
|
| 942 | + * |
|
| 943 | + * @return void |
|
| 944 | + */ |
|
| 945 | + public function clean_sensitive_data() |
|
| 946 | + { |
|
| 947 | + //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
| 948 | + //if we need more logic than this we'll make a strategy for it |
|
| 949 | + if ($this->_sensitive_data_removal_strategy |
|
| 950 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
| 951 | + ) { |
|
| 952 | + $this->_set_raw_value(null); |
|
| 953 | + } |
|
| 954 | + //and clean the normalized value according to the appropriate strategy |
|
| 955 | + $this->_set_normalized_value( |
|
| 956 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
| 957 | + $this->_normalized_value |
|
| 958 | + ) |
|
| 959 | + ); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * @param bool $primary |
|
| 966 | + * @param string $button_size |
|
| 967 | + * @param string $other_attributes |
|
| 968 | + */ |
|
| 969 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
| 970 | + { |
|
| 971 | + $button_css_attributes = 'button'; |
|
| 972 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
| 973 | + switch ($button_size) { |
|
| 974 | + case 'xs' : |
|
| 975 | + case 'extra-small' : |
|
| 976 | + $button_css_attributes .= ' button-xs'; |
|
| 977 | + break; |
|
| 978 | + case 'sm' : |
|
| 979 | + case 'small' : |
|
| 980 | + $button_css_attributes .= ' button-sm'; |
|
| 981 | + break; |
|
| 982 | + case 'lg' : |
|
| 983 | + case 'large' : |
|
| 984 | + $button_css_attributes .= ' button-lg'; |
|
| 985 | + break; |
|
| 986 | + case 'block' : |
|
| 987 | + $button_css_attributes .= ' button-block'; |
|
| 988 | + break; |
|
| 989 | + case 'md' : |
|
| 990 | + case 'medium' : |
|
| 991 | + default : |
|
| 992 | + $button_css_attributes .= ''; |
|
| 993 | + } |
|
| 994 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
| 995 | + ? $button_css_attributes . ' ' . $other_attributes |
|
| 996 | + : $button_css_attributes; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * @return string |
|
| 1003 | + */ |
|
| 1004 | + public function button_css_attributes() |
|
| 1005 | + { |
|
| 1006 | + if (empty($this->_button_css_attributes)) { |
|
| 1007 | + $this->set_button_css_attributes(); |
|
| 1008 | + } |
|
| 1009 | + return $this->_button_css_attributes; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * find_form_data_for_this_section |
|
| 1016 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
| 1017 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
| 1018 | + * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
| 1019 | + * (If that doesn't exist, we also check for this subsection's name |
|
| 1020 | + * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
| 1021 | + * This function finds its value in the form. |
|
| 1022 | + * |
|
| 1023 | + * @param array $req_data |
|
| 1024 | + * @return mixed whatever the raw value of this form section is in the request data |
|
| 1025 | + * @throws \EE_Error |
|
| 1026 | + */ |
|
| 1027 | + public function find_form_data_for_this_section($req_data) |
|
| 1028 | + { |
|
| 1029 | + // break up the html name by "[]" |
|
| 1030 | + if (strpos($this->html_name(), '[') !== false) { |
|
| 1031 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
| 1032 | + } else { |
|
| 1033 | + $before_any_brackets = $this->html_name(); |
|
| 1034 | + } |
|
| 1035 | + // grab all of the segments |
|
| 1036 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
| 1037 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
| 1038 | + $name_parts = $matches[1]; |
|
| 1039 | + array_unshift($name_parts, $before_any_brackets); |
|
| 1040 | + } else { |
|
| 1041 | + $name_parts = array($before_any_brackets); |
|
| 1042 | + } |
|
| 1043 | + // now get the value for the input |
|
| 1044 | + $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
| 1045 | + // check if this thing's name is at the TOP level of the request data |
|
| 1046 | + if ($value === null && isset($req_data[$this->name()])) { |
|
| 1047 | + $value = $req_data[$this->name()]; |
|
| 1048 | + } |
|
| 1049 | + return $value; |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * @param array $html_name_parts |
|
| 1056 | + * @param array $req_data |
|
| 1057 | + * @return array | NULL |
|
| 1058 | + */ |
|
| 1059 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
| 1060 | + { |
|
| 1061 | + $first_part_to_consider = array_shift($html_name_parts); |
|
| 1062 | + if (isset($req_data[$first_part_to_consider])) { |
|
| 1063 | + if (empty($html_name_parts)) { |
|
| 1064 | + return $req_data[$first_part_to_consider]; |
|
| 1065 | + } else { |
|
| 1066 | + return $this->_find_form_data_for_this_section_using_name_parts( |
|
| 1067 | + $html_name_parts, |
|
| 1068 | + $req_data[$first_part_to_consider] |
|
| 1069 | + ); |
|
| 1070 | + } |
|
| 1071 | + } else { |
|
| 1072 | + return null; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * Checks if this form input's data is in the request data |
|
| 1080 | + * |
|
| 1081 | + * @param array $req_data like $_POST |
|
| 1082 | + * @return boolean |
|
| 1083 | + * @throws \EE_Error |
|
| 1084 | + */ |
|
| 1085 | + public function form_data_present_in($req_data = null) |
|
| 1086 | + { |
|
| 1087 | + if ($req_data === null) { |
|
| 1088 | + $req_data = $_POST; |
|
| 1089 | + } |
|
| 1090 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
| 1091 | + if ($checked_value !== null) { |
|
| 1092 | + return true; |
|
| 1093 | + } else { |
|
| 1094 | + return false; |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + /** |
|
| 1101 | + * Overrides parent to add js data from validation and display strategies |
|
| 1102 | + * |
|
| 1103 | + * @param array $form_other_js_data |
|
| 1104 | + * @return array |
|
| 1105 | + */ |
|
| 1106 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 1107 | + { |
|
| 1108 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
| 1109 | + return $form_other_js_data; |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * Gets other JS data for localization from this input's strategies, like |
|
| 1116 | + * the validation strategies and the display strategy |
|
| 1117 | + * |
|
| 1118 | + * @param array $form_other_js_data |
|
| 1119 | + * @return array |
|
| 1120 | + */ |
|
| 1121 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
| 1122 | + { |
|
| 1123 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
| 1124 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 1125 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
| 1126 | + } |
|
| 1127 | + return $form_other_js_data; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
| 1134 | + * |
|
| 1135 | + * @return void |
|
| 1136 | + */ |
|
| 1137 | + public function enqueue_js() |
|
| 1138 | + { |
|
| 1139 | + //ask our display strategy and validation strategies if they have js to enqueue |
|
| 1140 | + $this->enqueue_js_from_strategies(); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + /** |
|
| 1146 | + * Tells strategies when its ok to enqueue their js and css |
|
| 1147 | + * |
|
| 1148 | + * @return void |
|
| 1149 | + */ |
|
| 1150 | + public function enqueue_js_from_strategies() |
|
| 1151 | + { |
|
| 1152 | + $this->get_display_strategy()->enqueue_js(); |
|
| 1153 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 1154 | + $validation_strategy->enqueue_js(); |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | 1157 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function __construct($input_args = array()) |
| 181 | 181 | { |
| 182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
| 182 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
| 183 | 183 | // the following properties must be cast as arrays |
| 184 | 184 | if (isset($input_args['validation_strategies'])) { |
| 185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
| 185 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
| 186 | 186 | if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
| 187 | 187 | $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
| 188 | 188 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | // loop thru incoming options |
| 193 | 193 | foreach ($input_args as $key => $value) { |
| 194 | 194 | // add underscore to $key to match property names |
| 195 | - $_key = '_' . $key; |
|
| 195 | + $_key = '_'.$key; |
|
| 196 | 196 | if (property_exists($this, $_key)) { |
| 197 | 197 | $this->{$_key} = $value; |
| 198 | 198 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | foreach ($this->_validation_strategies as $validation_strategy) { |
| 209 | 209 | $validation_strategy->_construct_finalize($this); |
| 210 | 210 | } |
| 211 | - if (! $this->_normalization_strategy) { |
|
| 211 | + if ( ! $this->_normalization_strategy) { |
|
| 212 | 212 | $this->_normalization_strategy = new EE_Text_Normalization(); |
| 213 | 213 | } |
| 214 | 214 | $this->_normalization_strategy->_construct_finalize($this); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | if (isset($input_args['default'])) { |
| 217 | 217 | $this->set_default($input_args['default']); |
| 218 | 218 | } |
| 219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
| 219 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
| 220 | 220 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
| 221 | 221 | } |
| 222 | 222 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
@@ -233,10 +233,10 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | protected function _set_default_html_name_if_empty() |
| 235 | 235 | { |
| 236 | - if (! $this->_html_name) { |
|
| 236 | + if ( ! $this->_html_name) { |
|
| 237 | 237 | $this->_html_name = $this->name(); |
| 238 | 238 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
| 239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
| 239 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | protected function _get_display_strategy() |
| 269 | 269 | { |
| 270 | 270 | $this->ensure_construct_finalized_called(); |
| 271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
| 271 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
| 272 | 272 | throw new EE_Error( |
| 273 | 273 | sprintf( |
| 274 | 274 | __( |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | public function html_other_attributes() |
| 503 | 503 | { |
| 504 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
| 504 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | */ |
| 646 | 646 | public function html_label_id() |
| 647 | 647 | { |
| 648 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
| 648 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl'; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | $validation_strategy->get_jquery_validation_rule_array() |
| 796 | 796 | ); |
| 797 | 797 | } |
| 798 | - if (! empty($jquery_validation_rules)) { |
|
| 798 | + if ( ! empty($jquery_validation_rules)) { |
|
| 799 | 799 | foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
| 800 | 800 | $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
| 801 | 801 | } |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | public function html_class($add_required = false) |
| 919 | 919 | { |
| 920 | 920 | return $add_required && $this->required() |
| 921 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
| 921 | + ? $this->required_css_class().' '.$this->_html_class |
|
| 922 | 922 | : $this->_html_class; |
| 923 | 923 | } |
| 924 | 924 | |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | $button_css_attributes .= ''; |
| 993 | 993 | } |
| 994 | 994 | $this->_button_css_attributes .= ! empty($other_attributes) |
| 995 | - ? $button_css_attributes . ' ' . $other_attributes |
|
| 995 | + ? $button_css_attributes.' '.$other_attributes |
|
| 996 | 996 | : $button_css_attributes; |
| 997 | 997 | } |
| 998 | 998 | |
@@ -13,386 +13,386 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Creates the array for the tips |
|
| 18 | - */ |
|
| 19 | - protected function _set_tips_array() |
|
| 20 | - { |
|
| 21 | - $this->_qtipsa = array( |
|
| 22 | - 2 => array( |
|
| 23 | - 'content_id' => 'dtt-evt-name-label', |
|
| 24 | - 'target' => '.DTT_name_label', |
|
| 25 | - 'content' => $this->_get_event_name_label_info(), |
|
| 26 | - ), |
|
| 27 | - 3 => array( |
|
| 28 | - 'content_id' => 'dtt-evt-start-label', |
|
| 29 | - 'target' => '.DTT_EVT_start_label', |
|
| 30 | - 'content' => $this->_get_event_start_label_info(), |
|
| 31 | - ), |
|
| 32 | - 5 => array( |
|
| 33 | - 'content_id' => 'dtt-evt-end-label', |
|
| 34 | - 'target' => '.DTT_EVT_end_label', |
|
| 35 | - 'content' => $this->_get_event_end_label_info(), |
|
| 36 | - ), |
|
| 37 | - 10 => array( |
|
| 38 | - 'content_id' => 'dtt-reg-limit-label', |
|
| 39 | - 'target' => '.DTT_reg_limit_label', |
|
| 40 | - 'content' => $this->_get_event_datetime_DTT_reg_limit_label_info(), |
|
| 41 | - ), |
|
| 42 | - 15 => array( |
|
| 43 | - 'content_id' => 'dtt-sold-label', |
|
| 44 | - 'target' => '.DTT_sold_label', |
|
| 45 | - 'content' => $this->_get_event_datetime_DTT_sold_label_info(), |
|
| 46 | - ), |
|
| 47 | - 17 => array( |
|
| 48 | - 'content_id' => 'dtt-reserved-label', |
|
| 49 | - 'target' => '.DTT_reserved_label', |
|
| 50 | - 'content' => $this->_get_event_datetime_DTT_reserved_label_info(), |
|
| 51 | - ), |
|
| 52 | - 20 => array( |
|
| 53 | - 'content_id' => 'tkt-name-label', |
|
| 54 | - 'target' => '.TKT_name_label', |
|
| 55 | - 'content' => $this->_get_event_ticket_TKT_name_label_info(), |
|
| 56 | - ), |
|
| 57 | - 25 => array( |
|
| 58 | - 'content_id' => 'tkt-goes-on-sale-label', |
|
| 59 | - 'target' => '.TKT_goes_on_sale_label', |
|
| 60 | - 'content' => $this->_get_event_ticket_TKT_goes_on_sale_label_info(), |
|
| 61 | - ), |
|
| 62 | - 30 => array( |
|
| 63 | - 'content_id' => 'tkt-sell-until-label', |
|
| 64 | - 'target' => '.TKT_sell_until_label', |
|
| 65 | - 'content' => $this->_get_event_ticket_TKT_sell_until_label_info(), |
|
| 66 | - ), |
|
| 67 | - 35 => array( |
|
| 68 | - 'content_id' => 'tkt-price-label', |
|
| 69 | - 'target' => '.TKT_price_label', |
|
| 70 | - 'content' => $this->_get_event_ticket_TKT_price_label_info(), |
|
| 71 | - ), |
|
| 72 | - 40 => array( |
|
| 73 | - 'content_id' => 'tkt-qty-label', |
|
| 74 | - 'target' => '.TKT_qty_label', |
|
| 75 | - 'content' => $this->_get_event_ticket_TKT_qty_label_info(), |
|
| 76 | - ), |
|
| 77 | - 45 => array( |
|
| 78 | - 'content_id' => 'tkt-sold-label', |
|
| 79 | - 'target' => '.TKT_sold_label', |
|
| 80 | - 'content' => $this->_get_event_ticket_TKT_sold_label_info(), |
|
| 81 | - ), |
|
| 82 | - 47 => array( |
|
| 83 | - 'content_id' => 'tkt-reserved-label', |
|
| 84 | - 'target' => '.TKT_reserved_label', |
|
| 85 | - 'content' => $this->_get_event_ticket_TKT_reserved_label_info(), |
|
| 86 | - ), |
|
| 87 | - 50 => array( |
|
| 88 | - 'content_id' => 'tkt-regs-label', |
|
| 89 | - 'target' => '.TKT_regs_label', |
|
| 90 | - 'content' => $this->_get_event_ticket_TKT_regs_label_info(), |
|
| 91 | - ), |
|
| 92 | - 55 => array( |
|
| 93 | - 'content_id' => 'ant-tkt-name-label', |
|
| 94 | - 'target' => '.ANT_TKT_name_label', |
|
| 95 | - 'content' => $this->_get_event_ticket_ANT_TKT_name_label_info(), |
|
| 96 | - ), |
|
| 97 | - 60 => array( |
|
| 98 | - 'content_id' => 'ant-tkt-goes-on-sale-label', |
|
| 99 | - 'target' => '.ANT_TKT_goes_on_sale_label', |
|
| 100 | - 'content' => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(), |
|
| 101 | - ), |
|
| 102 | - 65 => array( |
|
| 103 | - 'content_id' => 'ant-tkt-sell-until-label', |
|
| 104 | - 'target' => '.ANT_TKT_sell_until_label', |
|
| 105 | - 'content' => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(), |
|
| 106 | - ), |
|
| 107 | - 70 => array( |
|
| 108 | - 'content_id' => 'ant-tkt-price-label', |
|
| 109 | - 'target' => '.ANT_TKT_price_label', |
|
| 110 | - 'content' => $this->_get_event_ticket_ANT_TKT_price_label_info(), |
|
| 111 | - ), |
|
| 112 | - 75 => array( |
|
| 113 | - 'content_id' => 'ant-tkt-qty-label', |
|
| 114 | - 'target' => '.ANT_TKT_qty_label', |
|
| 115 | - 'content' => $this->_get_event_ticket_ANT_TKT_qty_label_info(), |
|
| 116 | - ), |
|
| 117 | - 80 => array( |
|
| 118 | - 'content_id' => 'ane-dtt-evt-start-label', |
|
| 119 | - 'target' => '.add-new-event-datetime-DTT_EVT_start_label', |
|
| 120 | - 'content' => $this->_get_add_new_event_start_label_info(), |
|
| 121 | - ), |
|
| 122 | - 85 => array( |
|
| 123 | - 'content_id' => 'ane-dtt-evt-end-label', |
|
| 124 | - 'target' => '.add-new-event-datetime-DTT_EVT_end_label', |
|
| 125 | - 'content' => $this->_get_add_new_event_end_label_info(), |
|
| 126 | - ), |
|
| 127 | - 90 => array( |
|
| 128 | - 'content_id' => 'ane_dtt-reg-limit-label', |
|
| 129 | - 'target' => '.add-new-event-datetime-DTT_reg_limit_label', |
|
| 130 | - 'content' => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(), |
|
| 131 | - ), |
|
| 132 | - 100 => array( |
|
| 133 | - 'content_id' => 'td-tkt-number-datetimes-label', |
|
| 134 | - 'target' => '.TD_TKT_number_datetimes_label', |
|
| 135 | - 'content' => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(), |
|
| 136 | - ), |
|
| 137 | - 110 => array( |
|
| 138 | - 'content_id' => 'td-tkt-min-qty-label', |
|
| 139 | - 'target' => '.TD_TKT_min_qty_label', |
|
| 140 | - 'content' => $this->_get_event_ticket_TD_TKT_min_qty_label_info(), |
|
| 141 | - ), |
|
| 142 | - 120 => array( |
|
| 143 | - 'content_id' => 'td-tkt-max-qty-label', |
|
| 144 | - 'target' => '.TD_TKT_max_qty_label', |
|
| 145 | - 'content' => $this->_get_event_ticket_TD_TKT_max_qty_label_info(), |
|
| 146 | - ), |
|
| 147 | - 130 => array( |
|
| 148 | - 'content_id' => 'ticket-lock-icon', |
|
| 149 | - 'target' => '.ticket-archived .ee-lock-icon', |
|
| 150 | - 'content' => esc_html__( |
|
| 151 | - 'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).', |
|
| 152 | - 'event_espresso' |
|
| 153 | - ), |
|
| 154 | - ), |
|
| 155 | - 135 => array( |
|
| 156 | - 'content_id' => 'ticket-lock-icon-event-editor', |
|
| 157 | - 'target' => '.ee-lock-icon', |
|
| 158 | - 'content' => esc_html__( |
|
| 159 | - 'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.', |
|
| 160 | - 'event_espresso' |
|
| 161 | - ), |
|
| 162 | - ), |
|
| 163 | - ); |
|
| 164 | - } |
|
| 16 | + /** |
|
| 17 | + * Creates the array for the tips |
|
| 18 | + */ |
|
| 19 | + protected function _set_tips_array() |
|
| 20 | + { |
|
| 21 | + $this->_qtipsa = array( |
|
| 22 | + 2 => array( |
|
| 23 | + 'content_id' => 'dtt-evt-name-label', |
|
| 24 | + 'target' => '.DTT_name_label', |
|
| 25 | + 'content' => $this->_get_event_name_label_info(), |
|
| 26 | + ), |
|
| 27 | + 3 => array( |
|
| 28 | + 'content_id' => 'dtt-evt-start-label', |
|
| 29 | + 'target' => '.DTT_EVT_start_label', |
|
| 30 | + 'content' => $this->_get_event_start_label_info(), |
|
| 31 | + ), |
|
| 32 | + 5 => array( |
|
| 33 | + 'content_id' => 'dtt-evt-end-label', |
|
| 34 | + 'target' => '.DTT_EVT_end_label', |
|
| 35 | + 'content' => $this->_get_event_end_label_info(), |
|
| 36 | + ), |
|
| 37 | + 10 => array( |
|
| 38 | + 'content_id' => 'dtt-reg-limit-label', |
|
| 39 | + 'target' => '.DTT_reg_limit_label', |
|
| 40 | + 'content' => $this->_get_event_datetime_DTT_reg_limit_label_info(), |
|
| 41 | + ), |
|
| 42 | + 15 => array( |
|
| 43 | + 'content_id' => 'dtt-sold-label', |
|
| 44 | + 'target' => '.DTT_sold_label', |
|
| 45 | + 'content' => $this->_get_event_datetime_DTT_sold_label_info(), |
|
| 46 | + ), |
|
| 47 | + 17 => array( |
|
| 48 | + 'content_id' => 'dtt-reserved-label', |
|
| 49 | + 'target' => '.DTT_reserved_label', |
|
| 50 | + 'content' => $this->_get_event_datetime_DTT_reserved_label_info(), |
|
| 51 | + ), |
|
| 52 | + 20 => array( |
|
| 53 | + 'content_id' => 'tkt-name-label', |
|
| 54 | + 'target' => '.TKT_name_label', |
|
| 55 | + 'content' => $this->_get_event_ticket_TKT_name_label_info(), |
|
| 56 | + ), |
|
| 57 | + 25 => array( |
|
| 58 | + 'content_id' => 'tkt-goes-on-sale-label', |
|
| 59 | + 'target' => '.TKT_goes_on_sale_label', |
|
| 60 | + 'content' => $this->_get_event_ticket_TKT_goes_on_sale_label_info(), |
|
| 61 | + ), |
|
| 62 | + 30 => array( |
|
| 63 | + 'content_id' => 'tkt-sell-until-label', |
|
| 64 | + 'target' => '.TKT_sell_until_label', |
|
| 65 | + 'content' => $this->_get_event_ticket_TKT_sell_until_label_info(), |
|
| 66 | + ), |
|
| 67 | + 35 => array( |
|
| 68 | + 'content_id' => 'tkt-price-label', |
|
| 69 | + 'target' => '.TKT_price_label', |
|
| 70 | + 'content' => $this->_get_event_ticket_TKT_price_label_info(), |
|
| 71 | + ), |
|
| 72 | + 40 => array( |
|
| 73 | + 'content_id' => 'tkt-qty-label', |
|
| 74 | + 'target' => '.TKT_qty_label', |
|
| 75 | + 'content' => $this->_get_event_ticket_TKT_qty_label_info(), |
|
| 76 | + ), |
|
| 77 | + 45 => array( |
|
| 78 | + 'content_id' => 'tkt-sold-label', |
|
| 79 | + 'target' => '.TKT_sold_label', |
|
| 80 | + 'content' => $this->_get_event_ticket_TKT_sold_label_info(), |
|
| 81 | + ), |
|
| 82 | + 47 => array( |
|
| 83 | + 'content_id' => 'tkt-reserved-label', |
|
| 84 | + 'target' => '.TKT_reserved_label', |
|
| 85 | + 'content' => $this->_get_event_ticket_TKT_reserved_label_info(), |
|
| 86 | + ), |
|
| 87 | + 50 => array( |
|
| 88 | + 'content_id' => 'tkt-regs-label', |
|
| 89 | + 'target' => '.TKT_regs_label', |
|
| 90 | + 'content' => $this->_get_event_ticket_TKT_regs_label_info(), |
|
| 91 | + ), |
|
| 92 | + 55 => array( |
|
| 93 | + 'content_id' => 'ant-tkt-name-label', |
|
| 94 | + 'target' => '.ANT_TKT_name_label', |
|
| 95 | + 'content' => $this->_get_event_ticket_ANT_TKT_name_label_info(), |
|
| 96 | + ), |
|
| 97 | + 60 => array( |
|
| 98 | + 'content_id' => 'ant-tkt-goes-on-sale-label', |
|
| 99 | + 'target' => '.ANT_TKT_goes_on_sale_label', |
|
| 100 | + 'content' => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(), |
|
| 101 | + ), |
|
| 102 | + 65 => array( |
|
| 103 | + 'content_id' => 'ant-tkt-sell-until-label', |
|
| 104 | + 'target' => '.ANT_TKT_sell_until_label', |
|
| 105 | + 'content' => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(), |
|
| 106 | + ), |
|
| 107 | + 70 => array( |
|
| 108 | + 'content_id' => 'ant-tkt-price-label', |
|
| 109 | + 'target' => '.ANT_TKT_price_label', |
|
| 110 | + 'content' => $this->_get_event_ticket_ANT_TKT_price_label_info(), |
|
| 111 | + ), |
|
| 112 | + 75 => array( |
|
| 113 | + 'content_id' => 'ant-tkt-qty-label', |
|
| 114 | + 'target' => '.ANT_TKT_qty_label', |
|
| 115 | + 'content' => $this->_get_event_ticket_ANT_TKT_qty_label_info(), |
|
| 116 | + ), |
|
| 117 | + 80 => array( |
|
| 118 | + 'content_id' => 'ane-dtt-evt-start-label', |
|
| 119 | + 'target' => '.add-new-event-datetime-DTT_EVT_start_label', |
|
| 120 | + 'content' => $this->_get_add_new_event_start_label_info(), |
|
| 121 | + ), |
|
| 122 | + 85 => array( |
|
| 123 | + 'content_id' => 'ane-dtt-evt-end-label', |
|
| 124 | + 'target' => '.add-new-event-datetime-DTT_EVT_end_label', |
|
| 125 | + 'content' => $this->_get_add_new_event_end_label_info(), |
|
| 126 | + ), |
|
| 127 | + 90 => array( |
|
| 128 | + 'content_id' => 'ane_dtt-reg-limit-label', |
|
| 129 | + 'target' => '.add-new-event-datetime-DTT_reg_limit_label', |
|
| 130 | + 'content' => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(), |
|
| 131 | + ), |
|
| 132 | + 100 => array( |
|
| 133 | + 'content_id' => 'td-tkt-number-datetimes-label', |
|
| 134 | + 'target' => '.TD_TKT_number_datetimes_label', |
|
| 135 | + 'content' => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(), |
|
| 136 | + ), |
|
| 137 | + 110 => array( |
|
| 138 | + 'content_id' => 'td-tkt-min-qty-label', |
|
| 139 | + 'target' => '.TD_TKT_min_qty_label', |
|
| 140 | + 'content' => $this->_get_event_ticket_TD_TKT_min_qty_label_info(), |
|
| 141 | + ), |
|
| 142 | + 120 => array( |
|
| 143 | + 'content_id' => 'td-tkt-max-qty-label', |
|
| 144 | + 'target' => '.TD_TKT_max_qty_label', |
|
| 145 | + 'content' => $this->_get_event_ticket_TD_TKT_max_qty_label_info(), |
|
| 146 | + ), |
|
| 147 | + 130 => array( |
|
| 148 | + 'content_id' => 'ticket-lock-icon', |
|
| 149 | + 'target' => '.ticket-archived .ee-lock-icon', |
|
| 150 | + 'content' => esc_html__( |
|
| 151 | + 'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).', |
|
| 152 | + 'event_espresso' |
|
| 153 | + ), |
|
| 154 | + ), |
|
| 155 | + 135 => array( |
|
| 156 | + 'content_id' => 'ticket-lock-icon-event-editor', |
|
| 157 | + 'target' => '.ee-lock-icon', |
|
| 158 | + 'content' => esc_html__( |
|
| 159 | + 'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.', |
|
| 160 | + 'event_espresso' |
|
| 161 | + ), |
|
| 162 | + ), |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - private function _get_event_name_label_info() |
|
| 170 | - { |
|
| 171 | - return esc_html__( |
|
| 172 | - 'This is the name or title for an event datetime.', |
|
| 173 | - 'event_espresso' |
|
| 174 | - ); |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + private function _get_event_name_label_info() |
|
| 170 | + { |
|
| 171 | + return esc_html__( |
|
| 172 | + 'This is the name or title for an event datetime.', |
|
| 173 | + 'event_espresso' |
|
| 174 | + ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - private function _get_event_start_label_info() |
|
| 181 | - { |
|
| 182 | - return esc_html__( |
|
| 183 | - 'This shows when this event datetime starts.', |
|
| 184 | - 'event_espresso' |
|
| 185 | - ); |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + private function _get_event_start_label_info() |
|
| 181 | + { |
|
| 182 | + return esc_html__( |
|
| 183 | + 'This shows when this event datetime starts.', |
|
| 184 | + 'event_espresso' |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - private function _get_event_end_label_info() |
|
| 192 | - { |
|
| 193 | - return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
| 194 | - } |
|
| 188 | + /** |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + private function _get_event_end_label_info() |
|
| 192 | + { |
|
| 193 | + return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - private function _get_event_datetime_DTT_reg_limit_label_info() |
|
| 200 | - { |
|
| 201 | - return esc_html__( |
|
| 202 | - 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ); |
|
| 205 | - } |
|
| 196 | + /** |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + private function _get_event_datetime_DTT_reg_limit_label_info() |
|
| 200 | + { |
|
| 201 | + return esc_html__( |
|
| 202 | + 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - private function _get_event_datetime_DTT_sold_label_info() |
|
| 211 | - { |
|
| 212 | - return esc_html__( |
|
| 213 | - 'This shows the number of tickets that have been sold that have access to this event datetime.', |
|
| 214 | - 'event_espresso' |
|
| 215 | - ); |
|
| 216 | - } |
|
| 207 | + /** |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + private function _get_event_datetime_DTT_sold_label_info() |
|
| 211 | + { |
|
| 212 | + return esc_html__( |
|
| 213 | + 'This shows the number of tickets that have been sold that have access to this event datetime.', |
|
| 214 | + 'event_espresso' |
|
| 215 | + ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @return string |
|
| 220 | - */ |
|
| 221 | - private function _get_event_datetime_DTT_reserved_label_info() |
|
| 222 | - { |
|
| 223 | - return esc_html__( |
|
| 224 | - 'This shows the number of reserved tickets that have access to this event datetime.', |
|
| 225 | - 'event_espresso' |
|
| 226 | - ); |
|
| 227 | - } |
|
| 218 | + /** |
|
| 219 | + * @return string |
|
| 220 | + */ |
|
| 221 | + private function _get_event_datetime_DTT_reserved_label_info() |
|
| 222 | + { |
|
| 223 | + return esc_html__( |
|
| 224 | + 'This shows the number of reserved tickets that have access to this event datetime.', |
|
| 225 | + 'event_espresso' |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - private function _get_event_ticket_TKT_name_label_info() |
|
| 233 | - { |
|
| 234 | - return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
| 235 | - } |
|
| 229 | + /** |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + private function _get_event_ticket_TKT_name_label_info() |
|
| 233 | + { |
|
| 234 | + return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - private function _get_event_ticket_TKT_goes_on_sale_label_info() |
|
| 241 | - { |
|
| 242 | - return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
| 243 | - } |
|
| 237 | + /** |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + private function _get_event_ticket_TKT_goes_on_sale_label_info() |
|
| 241 | + { |
|
| 242 | + return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - private function _get_event_ticket_TKT_sell_until_label_info() |
|
| 249 | - { |
|
| 250 | - return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
| 251 | - } |
|
| 245 | + /** |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + private function _get_event_ticket_TKT_sell_until_label_info() |
|
| 249 | + { |
|
| 250 | + return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - private function _get_event_ticket_TKT_price_label_info() |
|
| 257 | - { |
|
| 258 | - return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
| 259 | - } |
|
| 253 | + /** |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + private function _get_event_ticket_TKT_price_label_info() |
|
| 257 | + { |
|
| 258 | + return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - private function _get_event_ticket_TKT_qty_label_info() |
|
| 265 | - { |
|
| 266 | - return esc_html__( |
|
| 267 | - 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
| 268 | - 'event_espresso' |
|
| 269 | - ); |
|
| 270 | - } |
|
| 261 | + /** |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + private function _get_event_ticket_TKT_qty_label_info() |
|
| 265 | + { |
|
| 266 | + return esc_html__( |
|
| 267 | + 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
| 268 | + 'event_espresso' |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * @return string |
|
| 274 | - */ |
|
| 275 | - private function _get_event_ticket_TKT_sold_label_info() |
|
| 276 | - { |
|
| 277 | - return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso'); |
|
| 278 | - } |
|
| 272 | + /** |
|
| 273 | + * @return string |
|
| 274 | + */ |
|
| 275 | + private function _get_event_ticket_TKT_sold_label_info() |
|
| 276 | + { |
|
| 277 | + return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso'); |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - private function _get_event_ticket_TKT_reserved_label_info() |
|
| 284 | - { |
|
| 285 | - return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso'); |
|
| 286 | - } |
|
| 280 | + /** |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + private function _get_event_ticket_TKT_reserved_label_info() |
|
| 284 | + { |
|
| 285 | + return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso'); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - private function _get_event_ticket_TKT_regs_label_info() |
|
| 292 | - { |
|
| 293 | - return esc_html__( |
|
| 294 | - 'This shows the number of registrations that have occurred from ticket sales.', |
|
| 295 | - 'event_espresso' |
|
| 296 | - ); |
|
| 297 | - } |
|
| 288 | + /** |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + private function _get_event_ticket_TKT_regs_label_info() |
|
| 292 | + { |
|
| 293 | + return esc_html__( |
|
| 294 | + 'This shows the number of registrations that have occurred from ticket sales.', |
|
| 295 | + 'event_espresso' |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - private function _get_event_ticket_ANT_TKT_name_label_info() |
|
| 303 | - { |
|
| 304 | - return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
| 305 | - } |
|
| 299 | + /** |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + private function _get_event_ticket_ANT_TKT_name_label_info() |
|
| 303 | + { |
|
| 304 | + return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info() |
|
| 311 | - { |
|
| 312 | - return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
| 313 | - } |
|
| 307 | + /** |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info() |
|
| 311 | + { |
|
| 312 | + return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - private function _get_event_ticket_ANT_TKT_sell_until_label_info() |
|
| 319 | - { |
|
| 320 | - return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
| 321 | - } |
|
| 315 | + /** |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + private function _get_event_ticket_ANT_TKT_sell_until_label_info() |
|
| 319 | + { |
|
| 320 | + return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - private function _get_event_ticket_ANT_TKT_price_label_info() |
|
| 327 | - { |
|
| 328 | - return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
| 329 | - } |
|
| 323 | + /** |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + private function _get_event_ticket_ANT_TKT_price_label_info() |
|
| 327 | + { |
|
| 328 | + return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * @return string |
|
| 333 | - */ |
|
| 334 | - private function _get_event_ticket_ANT_TKT_qty_label_info() |
|
| 335 | - { |
|
| 336 | - return esc_html__( |
|
| 337 | - 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
| 338 | - 'event_espresso' |
|
| 339 | - ); |
|
| 340 | - } |
|
| 331 | + /** |
|
| 332 | + * @return string |
|
| 333 | + */ |
|
| 334 | + private function _get_event_ticket_ANT_TKT_qty_label_info() |
|
| 335 | + { |
|
| 336 | + return esc_html__( |
|
| 337 | + 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
| 338 | + 'event_espresso' |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * @return string |
|
| 344 | - */ |
|
| 345 | - private function _get_add_new_event_start_label_info() |
|
| 346 | - { |
|
| 347 | - return esc_html__('This shows when this event datetime starts.', 'event_espresso'); |
|
| 348 | - } |
|
| 342 | + /** |
|
| 343 | + * @return string |
|
| 344 | + */ |
|
| 345 | + private function _get_add_new_event_start_label_info() |
|
| 346 | + { |
|
| 347 | + return esc_html__('This shows when this event datetime starts.', 'event_espresso'); |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - /** |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - private function _get_add_new_event_end_label_info() |
|
| 354 | - { |
|
| 355 | - return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
| 356 | - } |
|
| 350 | + /** |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + private function _get_add_new_event_end_label_info() |
|
| 354 | + { |
|
| 355 | + return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * @return string |
|
| 360 | - */ |
|
| 361 | - private function _get_add_new_event_datetime_DTT_reg_limit_label_info() |
|
| 362 | - { |
|
| 363 | - return esc_html__( |
|
| 364 | - 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ); |
|
| 367 | - } |
|
| 358 | + /** |
|
| 359 | + * @return string |
|
| 360 | + */ |
|
| 361 | + private function _get_add_new_event_datetime_DTT_reg_limit_label_info() |
|
| 362 | + { |
|
| 363 | + return esc_html__( |
|
| 364 | + 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ); |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - /** |
|
| 370 | - * @return string |
|
| 371 | - */ |
|
| 372 | - private function _get_event_ticket_TD_TKT_number_datetimes_label_info() |
|
| 373 | - { |
|
| 374 | - return esc_html__( |
|
| 375 | - 'This field allows you to set the number of datetimes that a ticket should have access to.', |
|
| 376 | - 'event_espresso' |
|
| 377 | - ); |
|
| 378 | - } |
|
| 369 | + /** |
|
| 370 | + * @return string |
|
| 371 | + */ |
|
| 372 | + private function _get_event_ticket_TD_TKT_number_datetimes_label_info() |
|
| 373 | + { |
|
| 374 | + return esc_html__( |
|
| 375 | + 'This field allows you to set the number of datetimes that a ticket should have access to.', |
|
| 376 | + 'event_espresso' |
|
| 377 | + ); |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * @return string |
|
| 382 | - */ |
|
| 383 | - private function _get_event_ticket_TD_TKT_min_qty_label_info() |
|
| 384 | - { |
|
| 385 | - return esc_html__( |
|
| 386 | - 'This shows the minimum quantity that can be purchased for this ticket.', |
|
| 387 | - 'event_espresso' |
|
| 388 | - ); |
|
| 389 | - } |
|
| 380 | + /** |
|
| 381 | + * @return string |
|
| 382 | + */ |
|
| 383 | + private function _get_event_ticket_TD_TKT_min_qty_label_info() |
|
| 384 | + { |
|
| 385 | + return esc_html__( |
|
| 386 | + 'This shows the minimum quantity that can be purchased for this ticket.', |
|
| 387 | + 'event_espresso' |
|
| 388 | + ); |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - private function _get_event_ticket_TD_TKT_max_qty_label_info() |
|
| 395 | - { |
|
| 396 | - return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso'); |
|
| 397 | - } |
|
| 391 | + /** |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + private function _get_event_ticket_TD_TKT_max_qty_label_info() |
|
| 395 | + { |
|
| 396 | + return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso'); |
|
| 397 | + } |
|
| 398 | 398 | } |
| 399 | 399 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,2537 +14,2537 @@ discard block |
||
| 14 | 14 | final class EE_Config |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of the EE_Config object |
|
| 28 | + * |
|
| 29 | + * @var EE_Config $_instance |
|
| 30 | + * @access private |
|
| 31 | + */ |
|
| 32 | + private static $_instance; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var boolean $_logging_enabled |
|
| 36 | + */ |
|
| 37 | + private static $_logging_enabled = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * An StdClass whose property names are addon slugs, |
|
| 41 | + * and values are their config classes |
|
| 42 | + * |
|
| 43 | + * @var StdClass |
|
| 44 | + */ |
|
| 45 | + public $addons; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var EE_Admin_Config |
|
| 49 | + */ |
|
| 50 | + public $admin; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var EE_Core_Config |
|
| 54 | + */ |
|
| 55 | + public $core; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var EE_Currency_Config |
|
| 59 | + */ |
|
| 60 | + public $currency; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var EE_Organization_Config |
|
| 64 | + */ |
|
| 65 | + public $organization; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var EE_Registration_Config |
|
| 69 | + */ |
|
| 70 | + public $registration; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var EE_Template_Config |
|
| 74 | + */ |
|
| 75 | + public $template_settings; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Holds EE environment values. |
|
| 79 | + * |
|
| 80 | + * @var EE_Environment_Config |
|
| 81 | + */ |
|
| 82 | + public $environment; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * settings pertaining to Google maps |
|
| 86 | + * |
|
| 87 | + * @var EE_Map_Config |
|
| 88 | + */ |
|
| 89 | + public $map_settings; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * settings pertaining to Taxes |
|
| 93 | + * |
|
| 94 | + * @var EE_Tax_Config |
|
| 95 | + */ |
|
| 96 | + public $tax_settings; |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Settings pertaining to global messages settings. |
|
| 101 | + * |
|
| 102 | + * @var EE_Messages_Config |
|
| 103 | + */ |
|
| 104 | + public $messages; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @deprecated |
|
| 108 | + * @var EE_Gateway_Config |
|
| 109 | + */ |
|
| 110 | + public $gateway; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var array $_addon_option_names |
|
| 114 | + * @access private |
|
| 115 | + */ |
|
| 116 | + private $_addon_option_names = array(); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var array $_module_route_map |
|
| 120 | + * @access private |
|
| 121 | + */ |
|
| 122 | + private static $_module_route_map = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @var array $_module_forward_map |
|
| 126 | + * @access private |
|
| 127 | + */ |
|
| 128 | + private static $_module_forward_map = array(); |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var array $_module_view_map |
|
| 132 | + * @access private |
|
| 133 | + */ |
|
| 134 | + private static $_module_view_map = array(); |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @singleton method used to instantiate class object |
|
| 140 | + * @access public |
|
| 141 | + * @return EE_Config instance |
|
| 142 | + */ |
|
| 143 | + public static function instance() |
|
| 144 | + { |
|
| 145 | + // check if class object is instantiated, and instantiated properly |
|
| 146 | + if (! self::$_instance instanceof EE_Config) { |
|
| 147 | + self::$_instance = new self(); |
|
| 148 | + } |
|
| 149 | + return self::$_instance; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Resets the config |
|
| 156 | + * |
|
| 157 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 158 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 159 | + * reflect its state in the database |
|
| 160 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 161 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 162 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 163 | + * site was put into maintenance mode) |
|
| 164 | + * @return EE_Config |
|
| 165 | + */ |
|
| 166 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 167 | + { |
|
| 168 | + if (self::$_instance instanceof EE_Config) { |
|
| 169 | + if ($hard_reset) { |
|
| 170 | + self::$_instance->_addon_option_names = array(); |
|
| 171 | + self::$_instance->_initialize_config(); |
|
| 172 | + self::$_instance->update_espresso_config(); |
|
| 173 | + } |
|
| 174 | + self::$_instance->update_addon_option_names(); |
|
| 175 | + } |
|
| 176 | + self::$_instance = null; |
|
| 177 | + //we don't need to reset the static properties imo because those should |
|
| 178 | + //only change when a module is added or removed. Currently we don't |
|
| 179 | + //support removing a module during a request when it previously existed |
|
| 180 | + if ($reinstantiate) { |
|
| 181 | + return self::instance(); |
|
| 182 | + } else { |
|
| 183 | + return null; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * class constructor |
|
| 191 | + * |
|
| 192 | + * @access private |
|
| 193 | + */ |
|
| 194 | + private function __construct() |
|
| 195 | + { |
|
| 196 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 197 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 198 | + // setup empty config classes |
|
| 199 | + $this->_initialize_config(); |
|
| 200 | + // load existing EE site settings |
|
| 201 | + $this->_load_core_config(); |
|
| 202 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 203 | + $this->_verify_config(); |
|
| 204 | + // register shortcodes and modules |
|
| 205 | + add_action( |
|
| 206 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 207 | + array($this, 'register_shortcodes_and_modules'), |
|
| 208 | + 999 |
|
| 209 | + ); |
|
| 210 | + // initialize shortcodes and modules |
|
| 211 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 212 | + // register widgets |
|
| 213 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 214 | + // shutdown |
|
| 215 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 216 | + // construct__end hook |
|
| 217 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 218 | + // hardcoded hack |
|
| 219 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * use to get the current theme if needed from static context |
|
| 236 | + * |
|
| 237 | + * @return string current theme set. |
|
| 238 | + */ |
|
| 239 | + public static function get_current_theme() |
|
| 240 | + { |
|
| 241 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 242 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * _initialize_config |
|
| 249 | + * |
|
| 250 | + * @access private |
|
| 251 | + * @return void |
|
| 252 | + */ |
|
| 253 | + private function _initialize_config() |
|
| 254 | + { |
|
| 255 | + EE_Config::trim_log(); |
|
| 256 | + //set defaults |
|
| 257 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 258 | + $this->addons = new stdClass(); |
|
| 259 | + // set _module_route_map |
|
| 260 | + EE_Config::$_module_route_map = array(); |
|
| 261 | + // set _module_forward_map |
|
| 262 | + EE_Config::$_module_forward_map = array(); |
|
| 263 | + // set _module_view_map |
|
| 264 | + EE_Config::$_module_view_map = array(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * load core plugin configuration |
|
| 271 | + * |
|
| 272 | + * @access private |
|
| 273 | + * @return void |
|
| 274 | + */ |
|
| 275 | + private function _load_core_config() |
|
| 276 | + { |
|
| 277 | + // load_core_config__start hook |
|
| 278 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 279 | + $espresso_config = $this->get_espresso_config(); |
|
| 280 | + foreach ($espresso_config as $config => $settings) { |
|
| 281 | + // load_core_config__start hook |
|
| 282 | + $settings = apply_filters( |
|
| 283 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 284 | + $settings, |
|
| 285 | + $config, |
|
| 286 | + $this |
|
| 287 | + ); |
|
| 288 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 289 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 290 | + //call configs populate method to ensure any defaults are set for empty values. |
|
| 291 | + if (method_exists($settings, 'populate')) { |
|
| 292 | + $this->{$config}->populate(); |
|
| 293 | + } |
|
| 294 | + if (method_exists($settings, 'do_hooks')) { |
|
| 295 | + $this->{$config}->do_hooks(); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 300 | + $this->update_espresso_config(); |
|
| 301 | + } |
|
| 302 | + // load_core_config__end hook |
|
| 303 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * _verify_config |
|
| 310 | + * |
|
| 311 | + * @access protected |
|
| 312 | + * @return void |
|
| 313 | + */ |
|
| 314 | + protected function _verify_config() |
|
| 315 | + { |
|
| 316 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 317 | + ? $this->core |
|
| 318 | + : new EE_Core_Config(); |
|
| 319 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 320 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 321 | + ? $this->organization |
|
| 322 | + : new EE_Organization_Config(); |
|
| 323 | + $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization', |
|
| 324 | + $this->organization); |
|
| 325 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 326 | + ? $this->currency |
|
| 327 | + : new EE_Currency_Config(); |
|
| 328 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 329 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 330 | + ? $this->registration |
|
| 331 | + : new EE_Registration_Config(); |
|
| 332 | + $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration', |
|
| 333 | + $this->registration); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 349 | + $this->map_settings); |
|
| 350 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 351 | + ? $this->environment |
|
| 352 | + : new EE_Environment_Config(); |
|
| 353 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 354 | + $this->environment); |
|
| 355 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 356 | + ? $this->tax_settings |
|
| 357 | + : new EE_Tax_Config(); |
|
| 358 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 359 | + $this->tax_settings); |
|
| 360 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 361 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 362 | + ? $this->messages |
|
| 363 | + : new EE_Messages_Config(); |
|
| 364 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 365 | + ? $this->gateway |
|
| 366 | + : new EE_Gateway_Config(); |
|
| 367 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * get_espresso_config |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @return array of espresso config stuff |
|
| 376 | + */ |
|
| 377 | + public function get_espresso_config() |
|
| 378 | + { |
|
| 379 | + // grab espresso configuration |
|
| 380 | + return apply_filters( |
|
| 381 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 382 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 383 | + ); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * double_check_config_comparison |
|
| 390 | + * |
|
| 391 | + * @access public |
|
| 392 | + * @param string $option |
|
| 393 | + * @param $old_value |
|
| 394 | + * @param $value |
|
| 395 | + */ |
|
| 396 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 397 | + { |
|
| 398 | + // make sure we're checking the ee config |
|
| 399 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 400 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 401 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 402 | + if ($value != $old_value) { |
|
| 403 | + // if they are NOT the same, then remove the hook, |
|
| 404 | + // which means the subsequent update results will be based solely on the update query results |
|
| 405 | + // the reason we do this is because, as stated above, |
|
| 406 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 407 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 408 | + // If values are found to match their previous old value, |
|
| 409 | + // then WP bails before performing any update. |
|
| 410 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 411 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 412 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 413 | + // MySQL MAY ALSO NOT perform the update because |
|
| 414 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 415 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 416 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 417 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * update_espresso_config |
|
| 426 | + * |
|
| 427 | + * @access public |
|
| 428 | + */ |
|
| 429 | + protected function _reset_espresso_addon_config() |
|
| 430 | + { |
|
| 431 | + $this->_addon_option_names = array(); |
|
| 432 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 433 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 434 | + $config_class = get_class($addon_config_obj); |
|
| 435 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 436 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 437 | + } |
|
| 438 | + $this->addons->{$addon_name} = null; |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * update_espresso_config |
|
| 446 | + * |
|
| 447 | + * @access public |
|
| 448 | + * @param bool $add_success |
|
| 449 | + * @param bool $add_error |
|
| 450 | + * @return bool |
|
| 451 | + */ |
|
| 452 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 453 | + { |
|
| 454 | + // don't allow config updates during WP heartbeats |
|
| 455 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 459 | + //$clone = clone( self::$_instance ); |
|
| 460 | + //self::$_instance = NULL; |
|
| 461 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 462 | + $this->_reset_espresso_addon_config(); |
|
| 463 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 464 | + // but BEFORE the actual update occurs |
|
| 465 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 466 | + // now update "ee_config" |
|
| 467 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 468 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 469 | + // if not saved... check if the hook we just added still exists; |
|
| 470 | + // if it does, it means one of two things: |
|
| 471 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 472 | + // or... |
|
| 473 | + // the db update query returned 0 rows affected |
|
| 474 | + // (probably because the data value was the same from it's perspective) |
|
| 475 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 476 | + // but just means no update occurred, so don't display an error to the user. |
|
| 477 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 478 | + // then it means that something truly went wrong |
|
| 479 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 480 | + // remove our action since we don't want it in the system anymore |
|
| 481 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 482 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 483 | + //self::$_instance = $clone; |
|
| 484 | + //unset( $clone ); |
|
| 485 | + // if config remains the same or was updated successfully |
|
| 486 | + if ($saved) { |
|
| 487 | + if ($add_success) { |
|
| 488 | + EE_Error::add_success( |
|
| 489 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 490 | + __FILE__, |
|
| 491 | + __FUNCTION__, |
|
| 492 | + __LINE__ |
|
| 493 | + ); |
|
| 494 | + } |
|
| 495 | + return true; |
|
| 496 | + } else { |
|
| 497 | + if ($add_error) { |
|
| 498 | + EE_Error::add_error( |
|
| 499 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 500 | + __FILE__, |
|
| 501 | + __FUNCTION__, |
|
| 502 | + __LINE__ |
|
| 503 | + ); |
|
| 504 | + } |
|
| 505 | + return false; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * _verify_config_params |
|
| 513 | + * |
|
| 514 | + * @access private |
|
| 515 | + * @param string $section |
|
| 516 | + * @param string $name |
|
| 517 | + * @param string $config_class |
|
| 518 | + * @param EE_Config_Base $config_obj |
|
| 519 | + * @param array $tests_to_run |
|
| 520 | + * @param bool $display_errors |
|
| 521 | + * @return bool TRUE on success, FALSE on fail |
|
| 522 | + */ |
|
| 523 | + private function _verify_config_params( |
|
| 524 | + $section = '', |
|
| 525 | + $name = '', |
|
| 526 | + $config_class = '', |
|
| 527 | + $config_obj = null, |
|
| 528 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 529 | + $display_errors = true |
|
| 530 | + ) { |
|
| 531 | + try { |
|
| 532 | + foreach ($tests_to_run as $test) { |
|
| 533 | + switch ($test) { |
|
| 534 | + // TEST #1 : check that section was set |
|
| 535 | + case 1 : |
|
| 536 | + if (empty($section)) { |
|
| 537 | + if ($display_errors) { |
|
| 538 | + throw new EE_Error( |
|
| 539 | + sprintf( |
|
| 540 | + __( |
|
| 541 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 542 | + 'event_espresso' |
|
| 543 | + ), |
|
| 544 | + $config_class |
|
| 545 | + ) |
|
| 546 | + ); |
|
| 547 | + } |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 550 | + break; |
|
| 551 | + // TEST #2 : check that settings section exists |
|
| 552 | + case 2 : |
|
| 553 | + if (! isset($this->{$section})) { |
|
| 554 | + if ($display_errors) { |
|
| 555 | + throw new EE_Error( |
|
| 556 | + sprintf( |
|
| 557 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 558 | + $section |
|
| 559 | + ) |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + break; |
|
| 565 | + // TEST #3 : check that section is the proper format |
|
| 566 | + case 3 : |
|
| 567 | + if ( |
|
| 568 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 569 | + ) { |
|
| 570 | + if ($display_errors) { |
|
| 571 | + throw new EE_Error( |
|
| 572 | + sprintf( |
|
| 573 | + __( |
|
| 574 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 575 | + 'event_espresso' |
|
| 576 | + ), |
|
| 577 | + $section |
|
| 578 | + ) |
|
| 579 | + ); |
|
| 580 | + } |
|
| 581 | + return false; |
|
| 582 | + } |
|
| 583 | + break; |
|
| 584 | + // TEST #4 : check that config section name has been set |
|
| 585 | + case 4 : |
|
| 586 | + if (empty($name)) { |
|
| 587 | + if ($display_errors) { |
|
| 588 | + throw new EE_Error( |
|
| 589 | + __( |
|
| 590 | + 'No name has been provided for the specific configuration section.', |
|
| 591 | + 'event_espresso' |
|
| 592 | + ) |
|
| 593 | + ); |
|
| 594 | + } |
|
| 595 | + return false; |
|
| 596 | + } |
|
| 597 | + break; |
|
| 598 | + // TEST #5 : check that a config class name has been set |
|
| 599 | + case 5 : |
|
| 600 | + if (empty($config_class)) { |
|
| 601 | + if ($display_errors) { |
|
| 602 | + throw new EE_Error( |
|
| 603 | + __( |
|
| 604 | + 'No class name has been provided for the specific configuration section.', |
|
| 605 | + 'event_espresso' |
|
| 606 | + ) |
|
| 607 | + ); |
|
| 608 | + } |
|
| 609 | + return false; |
|
| 610 | + } |
|
| 611 | + break; |
|
| 612 | + // TEST #6 : verify config class is accessible |
|
| 613 | + case 6 : |
|
| 614 | + if (! class_exists($config_class)) { |
|
| 615 | + if ($display_errors) { |
|
| 616 | + throw new EE_Error( |
|
| 617 | + sprintf( |
|
| 618 | + __( |
|
| 619 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 620 | + 'event_espresso' |
|
| 621 | + ), |
|
| 622 | + $config_class |
|
| 623 | + ) |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + // TEST #7 : check that config has even been set |
|
| 630 | + case 7 : |
|
| 631 | + if (! isset($this->{$section}->{$name})) { |
|
| 632 | + if ($display_errors) { |
|
| 633 | + throw new EE_Error( |
|
| 634 | + sprintf( |
|
| 635 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 636 | + $section, |
|
| 637 | + $name |
|
| 638 | + ) |
|
| 639 | + ); |
|
| 640 | + } |
|
| 641 | + return false; |
|
| 642 | + } else { |
|
| 643 | + // and make sure it's not serialized |
|
| 644 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 645 | + } |
|
| 646 | + break; |
|
| 647 | + // TEST #8 : check that config is the requested type |
|
| 648 | + case 8 : |
|
| 649 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 650 | + if ($display_errors) { |
|
| 651 | + throw new EE_Error( |
|
| 652 | + sprintf( |
|
| 653 | + __( |
|
| 654 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 655 | + 'event_espresso' |
|
| 656 | + ), |
|
| 657 | + $section, |
|
| 658 | + $name, |
|
| 659 | + $config_class |
|
| 660 | + ) |
|
| 661 | + ); |
|
| 662 | + } |
|
| 663 | + return false; |
|
| 664 | + } |
|
| 665 | + break; |
|
| 666 | + // TEST #9 : verify config object |
|
| 667 | + case 9 : |
|
| 668 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 669 | + if ($display_errors) { |
|
| 670 | + throw new EE_Error( |
|
| 671 | + sprintf( |
|
| 672 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 673 | + print_r($config_obj, true) |
|
| 674 | + ) |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + return false; |
|
| 678 | + } |
|
| 679 | + break; |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + } catch (EE_Error $e) { |
|
| 683 | + $e->get_error(); |
|
| 684 | + } |
|
| 685 | + // you have successfully run the gauntlet |
|
| 686 | + return true; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * _generate_config_option_name |
|
| 693 | + * |
|
| 694 | + * @access protected |
|
| 695 | + * @param string $section |
|
| 696 | + * @param string $name |
|
| 697 | + * @return string |
|
| 698 | + */ |
|
| 699 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 700 | + { |
|
| 701 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * _set_config_class |
|
| 708 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 709 | + * |
|
| 710 | + * @access private |
|
| 711 | + * @param string $config_class |
|
| 712 | + * @param string $name |
|
| 713 | + * @return string |
|
| 714 | + */ |
|
| 715 | + private function _set_config_class($config_class = '', $name = '') |
|
| 716 | + { |
|
| 717 | + return ! empty($config_class) |
|
| 718 | + ? $config_class |
|
| 719 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * set_config |
|
| 726 | + * |
|
| 727 | + * @access protected |
|
| 728 | + * @param string $section |
|
| 729 | + * @param string $name |
|
| 730 | + * @param string $config_class |
|
| 731 | + * @param EE_Config_Base $config_obj |
|
| 732 | + * @return EE_Config_Base |
|
| 733 | + */ |
|
| 734 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 735 | + { |
|
| 736 | + // ensure config class is set to something |
|
| 737 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 738 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 739 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 740 | + return null; |
|
| 741 | + } |
|
| 742 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 743 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 744 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 745 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 746 | + $this->update_addon_option_names(); |
|
| 747 | + } |
|
| 748 | + // verify the incoming config object but suppress errors |
|
| 749 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 750 | + $config_obj = new $config_class(); |
|
| 751 | + } |
|
| 752 | + if (get_option($config_option_name)) { |
|
| 753 | + EE_Config::log($config_option_name); |
|
| 754 | + update_option($config_option_name, $config_obj); |
|
| 755 | + $this->{$section}->{$name} = $config_obj; |
|
| 756 | + return $this->{$section}->{$name}; |
|
| 757 | + } else { |
|
| 758 | + // create a wp-option for this config |
|
| 759 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 760 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 761 | + return $this->{$section}->{$name}; |
|
| 762 | + } else { |
|
| 763 | + EE_Error::add_error( |
|
| 764 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 765 | + __FILE__, |
|
| 766 | + __FUNCTION__, |
|
| 767 | + __LINE__ |
|
| 768 | + ); |
|
| 769 | + return null; |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * update_config |
|
| 778 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 779 | + * |
|
| 780 | + * @access public |
|
| 781 | + * @param string $section |
|
| 782 | + * @param string $name |
|
| 783 | + * @param EE_Config_Base|string $config_obj |
|
| 784 | + * @param bool $throw_errors |
|
| 785 | + * @return bool |
|
| 786 | + */ |
|
| 787 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 788 | + { |
|
| 789 | + // don't allow config updates during WP heartbeats |
|
| 790 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + $config_obj = maybe_unserialize($config_obj); |
|
| 794 | + // get class name of the incoming object |
|
| 795 | + $config_class = get_class($config_obj); |
|
| 796 | + // run tests 1-5 and 9 to verify config |
|
| 797 | + if (! $this->_verify_config_params( |
|
| 798 | + $section, |
|
| 799 | + $name, |
|
| 800 | + $config_class, |
|
| 801 | + $config_obj, |
|
| 802 | + array(1, 2, 3, 4, 7, 9) |
|
| 803 | + ) |
|
| 804 | + ) { |
|
| 805 | + return false; |
|
| 806 | + } |
|
| 807 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 808 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 809 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 810 | + // save new config to db |
|
| 811 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 812 | + return true; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + // first check if the record already exists |
|
| 816 | + $existing_config = get_option($config_option_name); |
|
| 817 | + $config_obj = serialize($config_obj); |
|
| 818 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 819 | + if ($existing_config == $config_obj) { |
|
| 820 | + $this->{$section}->{$name} = $config_obj; |
|
| 821 | + return true; |
|
| 822 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 823 | + EE_Config::log($config_option_name); |
|
| 824 | + // update wp-option for this config class |
|
| 825 | + $this->{$section}->{$name} = $config_obj; |
|
| 826 | + return true; |
|
| 827 | + } elseif ($throw_errors) { |
|
| 828 | + EE_Error::add_error( |
|
| 829 | + sprintf( |
|
| 830 | + __( |
|
| 831 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 832 | + 'event_espresso' |
|
| 833 | + ), |
|
| 834 | + $config_class, |
|
| 835 | + 'EE_Config->' . $section . '->' . $name |
|
| 836 | + ), |
|
| 837 | + __FILE__, |
|
| 838 | + __FUNCTION__, |
|
| 839 | + __LINE__ |
|
| 840 | + ); |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + /** |
|
| 897 | + * get_config_option |
|
| 898 | + * |
|
| 899 | + * @access public |
|
| 900 | + * @param string $config_option_name |
|
| 901 | + * @return mixed EE_Config_Base | FALSE |
|
| 902 | + */ |
|
| 903 | + public function get_config_option($config_option_name = '') |
|
| 904 | + { |
|
| 905 | + // retrieve the wp-option for this config class. |
|
| 906 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 907 | + if (empty($config_option)) { |
|
| 908 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 909 | + } |
|
| 910 | + return $config_option; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + /** |
|
| 916 | + * log |
|
| 917 | + * |
|
| 918 | + * @param string $config_option_name |
|
| 919 | + */ |
|
| 920 | + public static function log($config_option_name = '') |
|
| 921 | + { |
|
| 922 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | + $_request = $_REQUEST; |
|
| 926 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | + $config_log[(string)microtime(true)] = array( |
|
| 928 | + 'config_name' => $config_option_name, |
|
| 929 | + 'request' => $_request, |
|
| 930 | + ); |
|
| 931 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * trim_log |
|
| 939 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 940 | + */ |
|
| 941 | + public static function trim_log() |
|
| 942 | + { |
|
| 943 | + if (! EE_Config::logging_enabled()) { |
|
| 944 | + return; |
|
| 945 | + } |
|
| 946 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 947 | + $log_length = count($config_log); |
|
| 948 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 949 | + ksort($config_log); |
|
| 950 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 951 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * get_page_for_posts |
|
| 959 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 960 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 961 | + * |
|
| 962 | + * @access public |
|
| 963 | + * @return string |
|
| 964 | + */ |
|
| 965 | + public static function get_page_for_posts() |
|
| 966 | + { |
|
| 967 | + $page_for_posts = get_option('page_for_posts'); |
|
| 968 | + if (! $page_for_posts) { |
|
| 969 | + return 'posts'; |
|
| 970 | + } |
|
| 971 | + /** @type WPDB $wpdb */ |
|
| 972 | + global $wpdb; |
|
| 973 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 974 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * register_shortcodes_and_modules. |
|
| 981 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 982 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 983 | + * so they can help trigger maintenance mode if it's needed |
|
| 984 | + * |
|
| 985 | + * @access public |
|
| 986 | + * @return void |
|
| 987 | + */ |
|
| 988 | + public function register_shortcodes_and_modules() |
|
| 989 | + { |
|
| 990 | + // allow shortcodes to register with WP and to set hooks for the rest of the system |
|
| 991 | + EE_Registry::instance()->shortcodes = $this->_register_shortcodes(); |
|
| 992 | + // allow modules to set hooks for the rest of the system |
|
| 993 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * initialize_shortcodes_and_modules |
|
| 1000 | + * meaning they can start adding their hooks to get stuff done |
|
| 1001 | + * |
|
| 1002 | + * @access public |
|
| 1003 | + * @return void |
|
| 1004 | + */ |
|
| 1005 | + public function initialize_shortcodes_and_modules() |
|
| 1006 | + { |
|
| 1007 | + // allow shortcodes to set hooks for the rest of the system |
|
| 1008 | + $this->_initialize_shortcodes(); |
|
| 1009 | + // allow modules to set hooks for the rest of the system |
|
| 1010 | + $this->_initialize_modules(); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * widgets_init |
|
| 1017 | + * |
|
| 1018 | + * @access private |
|
| 1019 | + * @return void |
|
| 1020 | + */ |
|
| 1021 | + public function widgets_init() |
|
| 1022 | + { |
|
| 1023 | + //only init widgets on admin pages when not in complete maintenance, and |
|
| 1024 | + //on frontend when not in any maintenance mode |
|
| 1025 | + if ( |
|
| 1026 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1027 | + || ( |
|
| 1028 | + is_admin() |
|
| 1029 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1030 | + ) |
|
| 1031 | + ) { |
|
| 1032 | + // grab list of installed widgets |
|
| 1033 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1034 | + // filter list of modules to register |
|
| 1035 | + $widgets_to_register = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1037 | + $widgets_to_register |
|
| 1038 | + ); |
|
| 1039 | + if (! empty($widgets_to_register)) { |
|
| 1040 | + // cycle thru widget folders |
|
| 1041 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1042 | + // add to list of installed widget modules |
|
| 1043 | + EE_Config::register_ee_widget($widget_path); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + // filter list of installed modules |
|
| 1047 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1048 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1049 | + EE_Registry::instance()->widgets |
|
| 1050 | + ); |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * register_ee_widget - makes core aware of this widget |
|
| 1058 | + * |
|
| 1059 | + * @access public |
|
| 1060 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1061 | + * @return void |
|
| 1062 | + */ |
|
| 1063 | + public static function register_ee_widget($widget_path = null) |
|
| 1064 | + { |
|
| 1065 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1066 | + $widget_ext = '.widget.php'; |
|
| 1067 | + // make all separators match |
|
| 1068 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1069 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1070 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1071 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1072 | + $file_name = explode('.', basename($widget_path)); |
|
| 1073 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1074 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1075 | + // sanitize shortcode directory name |
|
| 1076 | + $widget = sanitize_key($widget); |
|
| 1077 | + // now we need to rebuild the shortcode path |
|
| 1078 | + $widget_path = explode(DS, $widget_path); |
|
| 1079 | + // remove last segment |
|
| 1080 | + array_pop($widget_path); |
|
| 1081 | + // glue it back together |
|
| 1082 | + $widget_path = implode(DS, $widget_path); |
|
| 1083 | + } else { |
|
| 1084 | + // grab and sanitize widget directory name |
|
| 1085 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1086 | + } |
|
| 1087 | + // create classname from widget directory name |
|
| 1088 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1089 | + // add class prefix |
|
| 1090 | + $widget_class = 'EEW_' . $widget; |
|
| 1091 | + // does the widget exist ? |
|
| 1092 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1093 | + $msg = sprintf( |
|
| 1094 | + __( |
|
| 1095 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1096 | + 'event_espresso' |
|
| 1097 | + ), |
|
| 1098 | + $widget_class, |
|
| 1099 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1100 | + ); |
|
| 1101 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1102 | + return; |
|
| 1103 | + } |
|
| 1104 | + // load the widget class file |
|
| 1105 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1106 | + // verify that class exists |
|
| 1107 | + if (! class_exists($widget_class)) { |
|
| 1108 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1109 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1110 | + return; |
|
| 1111 | + } |
|
| 1112 | + register_widget($widget_class); |
|
| 1113 | + // add to array of registered widgets |
|
| 1114 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * _register_shortcodes |
|
| 1121 | + * |
|
| 1122 | + * @access private |
|
| 1123 | + * @return array |
|
| 1124 | + */ |
|
| 1125 | + private function _register_shortcodes() |
|
| 1126 | + { |
|
| 1127 | + // grab list of installed shortcodes |
|
| 1128 | + $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR); |
|
| 1129 | + // filter list of modules to register |
|
| 1130 | + $shortcodes_to_register = apply_filters( |
|
| 1131 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 1132 | + $shortcodes_to_register |
|
| 1133 | + ); |
|
| 1134 | + if (! empty($shortcodes_to_register)) { |
|
| 1135 | + // cycle thru shortcode folders |
|
| 1136 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 1137 | + // add to list of installed shortcode modules |
|
| 1138 | + EE_Config::register_shortcode($shortcode_path); |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + // filter list of installed modules |
|
| 1142 | + return apply_filters( |
|
| 1143 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 1144 | + EE_Registry::instance()->shortcodes |
|
| 1145 | + ); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * register_shortcode - makes core aware of this shortcode |
|
| 1152 | + * |
|
| 1153 | + * @access public |
|
| 1154 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1155 | + * @return bool |
|
| 1156 | + */ |
|
| 1157 | + public static function register_shortcode($shortcode_path = null) |
|
| 1158 | + { |
|
| 1159 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 1160 | + $shortcode_ext = '.shortcode.php'; |
|
| 1161 | + // make all separators match |
|
| 1162 | + $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
| 1163 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1164 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 1165 | + // grab shortcode file name from directory name and break apart at dots |
|
| 1166 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 1167 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1168 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 1169 | + ? substr($shortcode_file[0], 4) |
|
| 1170 | + : $shortcode_file[0]; |
|
| 1171 | + // sanitize shortcode directory name |
|
| 1172 | + $shortcode = sanitize_key($shortcode); |
|
| 1173 | + // now we need to rebuild the shortcode path |
|
| 1174 | + $shortcode_path = explode(DS, $shortcode_path); |
|
| 1175 | + // remove last segment |
|
| 1176 | + array_pop($shortcode_path); |
|
| 1177 | + // glue it back together |
|
| 1178 | + $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
| 1179 | + } else { |
|
| 1180 | + // we need to generate the filename based off of the folder name |
|
| 1181 | + // grab and sanitize shortcode directory name |
|
| 1182 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 1183 | + $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
| 1184 | + } |
|
| 1185 | + // create classname from shortcode directory or file name |
|
| 1186 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 1187 | + // add class prefix |
|
| 1188 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 1189 | + // does the shortcode exist ? |
|
| 1190 | + if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
| 1191 | + $msg = sprintf( |
|
| 1192 | + __( |
|
| 1193 | + 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
| 1194 | + 'event_espresso' |
|
| 1195 | + ), |
|
| 1196 | + $shortcode_class, |
|
| 1197 | + $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1198 | + ); |
|
| 1199 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1200 | + return false; |
|
| 1201 | + } |
|
| 1202 | + // load the shortcode class file |
|
| 1203 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 1204 | + // verify that class exists |
|
| 1205 | + if (! class_exists($shortcode_class)) { |
|
| 1206 | + $msg = sprintf( |
|
| 1207 | + __('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 1208 | + $shortcode_class |
|
| 1209 | + ); |
|
| 1210 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1211 | + return false; |
|
| 1212 | + } |
|
| 1213 | + $shortcode = strtoupper($shortcode); |
|
| 1214 | + // add to array of registered shortcodes |
|
| 1215 | + EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1216 | + return true; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + |
|
| 1220 | + |
|
| 1221 | + /** |
|
| 1222 | + * _register_modules |
|
| 1223 | + * |
|
| 1224 | + * @access private |
|
| 1225 | + * @return array |
|
| 1226 | + */ |
|
| 1227 | + private function _register_modules() |
|
| 1228 | + { |
|
| 1229 | + // grab list of installed modules |
|
| 1230 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1231 | + // filter list of modules to register |
|
| 1232 | + $modules_to_register = apply_filters( |
|
| 1233 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1234 | + $modules_to_register |
|
| 1235 | + ); |
|
| 1236 | + if (! empty($modules_to_register)) { |
|
| 1237 | + // loop through folders |
|
| 1238 | + foreach ($modules_to_register as $module_path) { |
|
| 1239 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1240 | + if ( |
|
| 1241 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1242 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1243 | + ) { |
|
| 1244 | + // add to list of installed modules |
|
| 1245 | + EE_Config::register_module($module_path); |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + // filter list of installed modules |
|
| 1250 | + return apply_filters( |
|
| 1251 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1252 | + EE_Registry::instance()->modules |
|
| 1253 | + ); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * register_module - makes core aware of this module |
|
| 1260 | + * |
|
| 1261 | + * @access public |
|
| 1262 | + * @param string $module_path - full path up to and including module folder |
|
| 1263 | + * @return bool |
|
| 1264 | + */ |
|
| 1265 | + public static function register_module($module_path = null) |
|
| 1266 | + { |
|
| 1267 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1268 | + $module_ext = '.module.php'; |
|
| 1269 | + // make all separators match |
|
| 1270 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1271 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1272 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1273 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1274 | + $module_file = explode('.', basename($module_path)); |
|
| 1275 | + // now we need to rebuild the shortcode path |
|
| 1276 | + $module_path = explode(DS, $module_path); |
|
| 1277 | + // remove last segment |
|
| 1278 | + array_pop($module_path); |
|
| 1279 | + // glue it back together |
|
| 1280 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1281 | + // take first segment from file name pieces and sanitize it |
|
| 1282 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1283 | + // ensure class prefix is added |
|
| 1284 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1285 | + } else { |
|
| 1286 | + // we need to generate the filename based off of the folder name |
|
| 1287 | + // grab and sanitize module name |
|
| 1288 | + $module = strtolower(basename($module_path)); |
|
| 1289 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1290 | + // like trailingslashit() |
|
| 1291 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1292 | + // create classname from module directory name |
|
| 1293 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1294 | + // add class prefix |
|
| 1295 | + $module_class = 'EED_' . $module; |
|
| 1296 | + } |
|
| 1297 | + // does the module exist ? |
|
| 1298 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1299 | + $msg = sprintf( |
|
| 1300 | + __( |
|
| 1301 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1302 | + 'event_espresso' |
|
| 1303 | + ), |
|
| 1304 | + $module |
|
| 1305 | + ); |
|
| 1306 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1307 | + return false; |
|
| 1308 | + } |
|
| 1309 | + // load the module class file |
|
| 1310 | + require_once($module_path . $module_class . $module_ext); |
|
| 1311 | + // verify that class exists |
|
| 1312 | + if (! class_exists($module_class)) { |
|
| 1313 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1314 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1315 | + return false; |
|
| 1316 | + } |
|
| 1317 | + // add to array of registered modules |
|
| 1318 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1319 | + do_action( |
|
| 1320 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1321 | + $module_class, |
|
| 1322 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1323 | + ); |
|
| 1324 | + return true; |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * _initialize_shortcodes |
|
| 1331 | + * allow shortcodes to set hooks for the rest of the system |
|
| 1332 | + * |
|
| 1333 | + * @access private |
|
| 1334 | + * @return void |
|
| 1335 | + */ |
|
| 1336 | + private function _initialize_shortcodes() |
|
| 1337 | + { |
|
| 1338 | + // cycle thru shortcode folders |
|
| 1339 | + foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
|
| 1340 | + // add class prefix |
|
| 1341 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 1342 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1343 | + // which set hooks ? |
|
| 1344 | + if (is_admin()) { |
|
| 1345 | + // fire immediately |
|
| 1346 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 1347 | + } else { |
|
| 1348 | + // delay until other systems are online |
|
| 1349 | + add_action( |
|
| 1350 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1351 | + array($shortcode_class, 'set_hooks') |
|
| 1352 | + ); |
|
| 1353 | + // convert classname to UPPERCASE and create WP shortcode. |
|
| 1354 | + $shortcode_tag = strtoupper($shortcode); |
|
| 1355 | + // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
|
| 1356 | + if (! shortcode_exists($shortcode_tag)) { |
|
| 1357 | + // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
|
| 1358 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 1359 | + } |
|
| 1360 | + } |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + /** |
|
| 1367 | + * _initialize_modules |
|
| 1368 | + * allow modules to set hooks for the rest of the system |
|
| 1369 | + * |
|
| 1370 | + * @access private |
|
| 1371 | + * @return void |
|
| 1372 | + */ |
|
| 1373 | + private function _initialize_modules() |
|
| 1374 | + { |
|
| 1375 | + // cycle thru shortcode folders |
|
| 1376 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1377 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1378 | + // which set hooks ? |
|
| 1379 | + if (is_admin()) { |
|
| 1380 | + // fire immediately |
|
| 1381 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1382 | + } else { |
|
| 1383 | + // delay until other systems are online |
|
| 1384 | + add_action( |
|
| 1385 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1386 | + array($module_class, 'set_hooks') |
|
| 1387 | + ); |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * register_route - adds module method routes to route_map |
|
| 1396 | + * |
|
| 1397 | + * @access public |
|
| 1398 | + * @param string $route - "pretty" public alias for module method |
|
| 1399 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1400 | + * @param string $method_name - the actual module method to be routed to |
|
| 1401 | + * @param string $key - url param key indicating a route is being called |
|
| 1402 | + * @return bool |
|
| 1403 | + */ |
|
| 1404 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1405 | + { |
|
| 1406 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1407 | + $module = str_replace('EED_', '', $module); |
|
| 1408 | + $module_class = 'EED_' . $module; |
|
| 1409 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1410 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1411 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1412 | + return false; |
|
| 1413 | + } |
|
| 1414 | + if (empty($route)) { |
|
| 1415 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1416 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1417 | + return false; |
|
| 1418 | + } |
|
| 1419 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1420 | + $msg = sprintf( |
|
| 1421 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1422 | + $route |
|
| 1423 | + ); |
|
| 1424 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1425 | + return false; |
|
| 1426 | + } |
|
| 1427 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1428 | + return true; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * get_route - get module method route |
|
| 1435 | + * |
|
| 1436 | + * @access public |
|
| 1437 | + * @param string $route - "pretty" public alias for module method |
|
| 1438 | + * @param string $key - url param key indicating a route is being called |
|
| 1439 | + * @return string |
|
| 1440 | + */ |
|
| 1441 | + public static function get_route($route = null, $key = 'ee') |
|
| 1442 | + { |
|
| 1443 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1444 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1445 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1446 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1447 | + } |
|
| 1448 | + return null; |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * get_routes - get ALL module method routes |
|
| 1455 | + * |
|
| 1456 | + * @access public |
|
| 1457 | + * @return array |
|
| 1458 | + */ |
|
| 1459 | + public static function get_routes() |
|
| 1460 | + { |
|
| 1461 | + return EE_Config::$_module_route_map; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1468 | + * |
|
| 1469 | + * @access public |
|
| 1470 | + * @param string $route - "pretty" public alias for module method |
|
| 1471 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1472 | + * class, allows different forwards to be served based on status |
|
| 1473 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1474 | + * @param string $key - url param key indicating a route is being called |
|
| 1475 | + * @return bool |
|
| 1476 | + */ |
|
| 1477 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1478 | + { |
|
| 1479 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1480 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1481 | + $msg = sprintf( |
|
| 1482 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1483 | + $route |
|
| 1484 | + ); |
|
| 1485 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1486 | + return false; |
|
| 1487 | + } |
|
| 1488 | + if (empty($forward)) { |
|
| 1489 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1490 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1491 | + return false; |
|
| 1492 | + } |
|
| 1493 | + if (is_array($forward)) { |
|
| 1494 | + if (! isset($forward[1])) { |
|
| 1495 | + $msg = sprintf( |
|
| 1496 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1497 | + $route |
|
| 1498 | + ); |
|
| 1499 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1500 | + return false; |
|
| 1501 | + } |
|
| 1502 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1503 | + $msg = sprintf( |
|
| 1504 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1505 | + $forward[1], |
|
| 1506 | + $route |
|
| 1507 | + ); |
|
| 1508 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1509 | + return false; |
|
| 1510 | + } |
|
| 1511 | + } else if (! function_exists($forward)) { |
|
| 1512 | + $msg = sprintf( |
|
| 1513 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1514 | + $forward, |
|
| 1515 | + $route |
|
| 1516 | + ); |
|
| 1517 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1518 | + return false; |
|
| 1519 | + } |
|
| 1520 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1521 | + return true; |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + |
|
| 1525 | + |
|
| 1526 | + /** |
|
| 1527 | + * get_forward - get forwarding route |
|
| 1528 | + * |
|
| 1529 | + * @access public |
|
| 1530 | + * @param string $route - "pretty" public alias for module method |
|
| 1531 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1532 | + * allows different forwards to be served based on status |
|
| 1533 | + * @param string $key - url param key indicating a route is being called |
|
| 1534 | + * @return string |
|
| 1535 | + */ |
|
| 1536 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1537 | + { |
|
| 1538 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1539 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1540 | + return apply_filters( |
|
| 1541 | + 'FHEE__EE_Config__get_forward', |
|
| 1542 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1543 | + $route, |
|
| 1544 | + $status |
|
| 1545 | + ); |
|
| 1546 | + } |
|
| 1547 | + return null; |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + |
|
| 1551 | + |
|
| 1552 | + /** |
|
| 1553 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1554 | + * results |
|
| 1555 | + * |
|
| 1556 | + * @access public |
|
| 1557 | + * @param string $route - "pretty" public alias for module method |
|
| 1558 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1559 | + * allows different views to be served based on status |
|
| 1560 | + * @param string $view |
|
| 1561 | + * @param string $key - url param key indicating a route is being called |
|
| 1562 | + * @return bool |
|
| 1563 | + */ |
|
| 1564 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1565 | + { |
|
| 1566 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1567 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1568 | + $msg = sprintf( |
|
| 1569 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1570 | + $route |
|
| 1571 | + ); |
|
| 1572 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1573 | + return false; |
|
| 1574 | + } |
|
| 1575 | + if (! is_readable($view)) { |
|
| 1576 | + $msg = sprintf( |
|
| 1577 | + __( |
|
| 1578 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1579 | + 'event_espresso' |
|
| 1580 | + ), |
|
| 1581 | + $view |
|
| 1582 | + ); |
|
| 1583 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1584 | + return false; |
|
| 1585 | + } |
|
| 1586 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1587 | + return true; |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * get_view - get view for route and status |
|
| 1594 | + * |
|
| 1595 | + * @access public |
|
| 1596 | + * @param string $route - "pretty" public alias for module method |
|
| 1597 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1598 | + * allows different views to be served based on status |
|
| 1599 | + * @param string $key - url param key indicating a route is being called |
|
| 1600 | + * @return string |
|
| 1601 | + */ |
|
| 1602 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1603 | + { |
|
| 1604 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1605 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1606 | + return apply_filters( |
|
| 1607 | + 'FHEE__EE_Config__get_view', |
|
| 1608 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1609 | + $route, |
|
| 1610 | + $status |
|
| 1611 | + ); |
|
| 1612 | + } |
|
| 1613 | + return null; |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + |
|
| 1618 | + public function update_addon_option_names() |
|
| 1619 | + { |
|
| 1620 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + |
|
| 1624 | + |
|
| 1625 | + public function shutdown() |
|
| 1626 | + { |
|
| 1627 | + $this->update_addon_option_names(); |
|
| 1628 | + } |
|
| 18 | 1629 | |
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | 1630 | |
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of the EE_Config object |
|
| 28 | - * |
|
| 29 | - * @var EE_Config $_instance |
|
| 30 | - * @access private |
|
| 31 | - */ |
|
| 32 | - private static $_instance; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var boolean $_logging_enabled |
|
| 36 | - */ |
|
| 37 | - private static $_logging_enabled = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * An StdClass whose property names are addon slugs, |
|
| 41 | - * and values are their config classes |
|
| 42 | - * |
|
| 43 | - * @var StdClass |
|
| 44 | - */ |
|
| 45 | - public $addons; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var EE_Admin_Config |
|
| 49 | - */ |
|
| 50 | - public $admin; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var EE_Core_Config |
|
| 54 | - */ |
|
| 55 | - public $core; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var EE_Currency_Config |
|
| 59 | - */ |
|
| 60 | - public $currency; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var EE_Organization_Config |
|
| 64 | - */ |
|
| 65 | - public $organization; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var EE_Registration_Config |
|
| 69 | - */ |
|
| 70 | - public $registration; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var EE_Template_Config |
|
| 74 | - */ |
|
| 75 | - public $template_settings; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Holds EE environment values. |
|
| 79 | - * |
|
| 80 | - * @var EE_Environment_Config |
|
| 81 | - */ |
|
| 82 | - public $environment; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * settings pertaining to Google maps |
|
| 86 | - * |
|
| 87 | - * @var EE_Map_Config |
|
| 88 | - */ |
|
| 89 | - public $map_settings; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * settings pertaining to Taxes |
|
| 93 | - * |
|
| 94 | - * @var EE_Tax_Config |
|
| 95 | - */ |
|
| 96 | - public $tax_settings; |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Settings pertaining to global messages settings. |
|
| 101 | - * |
|
| 102 | - * @var EE_Messages_Config |
|
| 103 | - */ |
|
| 104 | - public $messages; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @deprecated |
|
| 108 | - * @var EE_Gateway_Config |
|
| 109 | - */ |
|
| 110 | - public $gateway; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var array $_addon_option_names |
|
| 114 | - * @access private |
|
| 115 | - */ |
|
| 116 | - private $_addon_option_names = array(); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var array $_module_route_map |
|
| 120 | - * @access private |
|
| 121 | - */ |
|
| 122 | - private static $_module_route_map = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @var array $_module_forward_map |
|
| 126 | - * @access private |
|
| 127 | - */ |
|
| 128 | - private static $_module_forward_map = array(); |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var array $_module_view_map |
|
| 132 | - * @access private |
|
| 133 | - */ |
|
| 134 | - private static $_module_view_map = array(); |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @singleton method used to instantiate class object |
|
| 140 | - * @access public |
|
| 141 | - * @return EE_Config instance |
|
| 142 | - */ |
|
| 143 | - public static function instance() |
|
| 144 | - { |
|
| 145 | - // check if class object is instantiated, and instantiated properly |
|
| 146 | - if (! self::$_instance instanceof EE_Config) { |
|
| 147 | - self::$_instance = new self(); |
|
| 148 | - } |
|
| 149 | - return self::$_instance; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Resets the config |
|
| 156 | - * |
|
| 157 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 158 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 159 | - * reflect its state in the database |
|
| 160 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 161 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 162 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 163 | - * site was put into maintenance mode) |
|
| 164 | - * @return EE_Config |
|
| 165 | - */ |
|
| 166 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 167 | - { |
|
| 168 | - if (self::$_instance instanceof EE_Config) { |
|
| 169 | - if ($hard_reset) { |
|
| 170 | - self::$_instance->_addon_option_names = array(); |
|
| 171 | - self::$_instance->_initialize_config(); |
|
| 172 | - self::$_instance->update_espresso_config(); |
|
| 173 | - } |
|
| 174 | - self::$_instance->update_addon_option_names(); |
|
| 175 | - } |
|
| 176 | - self::$_instance = null; |
|
| 177 | - //we don't need to reset the static properties imo because those should |
|
| 178 | - //only change when a module is added or removed. Currently we don't |
|
| 179 | - //support removing a module during a request when it previously existed |
|
| 180 | - if ($reinstantiate) { |
|
| 181 | - return self::instance(); |
|
| 182 | - } else { |
|
| 183 | - return null; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * class constructor |
|
| 191 | - * |
|
| 192 | - * @access private |
|
| 193 | - */ |
|
| 194 | - private function __construct() |
|
| 195 | - { |
|
| 196 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 197 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 198 | - // setup empty config classes |
|
| 199 | - $this->_initialize_config(); |
|
| 200 | - // load existing EE site settings |
|
| 201 | - $this->_load_core_config(); |
|
| 202 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 203 | - $this->_verify_config(); |
|
| 204 | - // register shortcodes and modules |
|
| 205 | - add_action( |
|
| 206 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 207 | - array($this, 'register_shortcodes_and_modules'), |
|
| 208 | - 999 |
|
| 209 | - ); |
|
| 210 | - // initialize shortcodes and modules |
|
| 211 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 212 | - // register widgets |
|
| 213 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 214 | - // shutdown |
|
| 215 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 216 | - // construct__end hook |
|
| 217 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 218 | - // hardcoded hack |
|
| 219 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * use to get the current theme if needed from static context |
|
| 236 | - * |
|
| 237 | - * @return string current theme set. |
|
| 238 | - */ |
|
| 239 | - public static function get_current_theme() |
|
| 240 | - { |
|
| 241 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 242 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * _initialize_config |
|
| 249 | - * |
|
| 250 | - * @access private |
|
| 251 | - * @return void |
|
| 252 | - */ |
|
| 253 | - private function _initialize_config() |
|
| 254 | - { |
|
| 255 | - EE_Config::trim_log(); |
|
| 256 | - //set defaults |
|
| 257 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 258 | - $this->addons = new stdClass(); |
|
| 259 | - // set _module_route_map |
|
| 260 | - EE_Config::$_module_route_map = array(); |
|
| 261 | - // set _module_forward_map |
|
| 262 | - EE_Config::$_module_forward_map = array(); |
|
| 263 | - // set _module_view_map |
|
| 264 | - EE_Config::$_module_view_map = array(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * load core plugin configuration |
|
| 271 | - * |
|
| 272 | - * @access private |
|
| 273 | - * @return void |
|
| 274 | - */ |
|
| 275 | - private function _load_core_config() |
|
| 276 | - { |
|
| 277 | - // load_core_config__start hook |
|
| 278 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 279 | - $espresso_config = $this->get_espresso_config(); |
|
| 280 | - foreach ($espresso_config as $config => $settings) { |
|
| 281 | - // load_core_config__start hook |
|
| 282 | - $settings = apply_filters( |
|
| 283 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 284 | - $settings, |
|
| 285 | - $config, |
|
| 286 | - $this |
|
| 287 | - ); |
|
| 288 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 289 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 290 | - //call configs populate method to ensure any defaults are set for empty values. |
|
| 291 | - if (method_exists($settings, 'populate')) { |
|
| 292 | - $this->{$config}->populate(); |
|
| 293 | - } |
|
| 294 | - if (method_exists($settings, 'do_hooks')) { |
|
| 295 | - $this->{$config}->do_hooks(); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 300 | - $this->update_espresso_config(); |
|
| 301 | - } |
|
| 302 | - // load_core_config__end hook |
|
| 303 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * _verify_config |
|
| 310 | - * |
|
| 311 | - * @access protected |
|
| 312 | - * @return void |
|
| 313 | - */ |
|
| 314 | - protected function _verify_config() |
|
| 315 | - { |
|
| 316 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 317 | - ? $this->core |
|
| 318 | - : new EE_Core_Config(); |
|
| 319 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 320 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 321 | - ? $this->organization |
|
| 322 | - : new EE_Organization_Config(); |
|
| 323 | - $this->organization = apply_filters('FHEE__EE_Config___initialize_config__organization', |
|
| 324 | - $this->organization); |
|
| 325 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 326 | - ? $this->currency |
|
| 327 | - : new EE_Currency_Config(); |
|
| 328 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 329 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 330 | - ? $this->registration |
|
| 331 | - : new EE_Registration_Config(); |
|
| 332 | - $this->registration = apply_filters('FHEE__EE_Config___initialize_config__registration', |
|
| 333 | - $this->registration); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 349 | - $this->map_settings); |
|
| 350 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 351 | - ? $this->environment |
|
| 352 | - : new EE_Environment_Config(); |
|
| 353 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 354 | - $this->environment); |
|
| 355 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 356 | - ? $this->tax_settings |
|
| 357 | - : new EE_Tax_Config(); |
|
| 358 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 359 | - $this->tax_settings); |
|
| 360 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 361 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 362 | - ? $this->messages |
|
| 363 | - : new EE_Messages_Config(); |
|
| 364 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 365 | - ? $this->gateway |
|
| 366 | - : new EE_Gateway_Config(); |
|
| 367 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * get_espresso_config |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @return array of espresso config stuff |
|
| 376 | - */ |
|
| 377 | - public function get_espresso_config() |
|
| 378 | - { |
|
| 379 | - // grab espresso configuration |
|
| 380 | - return apply_filters( |
|
| 381 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 382 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 383 | - ); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * double_check_config_comparison |
|
| 390 | - * |
|
| 391 | - * @access public |
|
| 392 | - * @param string $option |
|
| 393 | - * @param $old_value |
|
| 394 | - * @param $value |
|
| 395 | - */ |
|
| 396 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 397 | - { |
|
| 398 | - // make sure we're checking the ee config |
|
| 399 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 400 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 401 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 402 | - if ($value != $old_value) { |
|
| 403 | - // if they are NOT the same, then remove the hook, |
|
| 404 | - // which means the subsequent update results will be based solely on the update query results |
|
| 405 | - // the reason we do this is because, as stated above, |
|
| 406 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 407 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 408 | - // If values are found to match their previous old value, |
|
| 409 | - // then WP bails before performing any update. |
|
| 410 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 411 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 412 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 413 | - // MySQL MAY ALSO NOT perform the update because |
|
| 414 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 415 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 416 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 417 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * update_espresso_config |
|
| 426 | - * |
|
| 427 | - * @access public |
|
| 428 | - */ |
|
| 429 | - protected function _reset_espresso_addon_config() |
|
| 430 | - { |
|
| 431 | - $this->_addon_option_names = array(); |
|
| 432 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 433 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 434 | - $config_class = get_class($addon_config_obj); |
|
| 435 | - if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 436 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 437 | - } |
|
| 438 | - $this->addons->{$addon_name} = null; |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * update_espresso_config |
|
| 446 | - * |
|
| 447 | - * @access public |
|
| 448 | - * @param bool $add_success |
|
| 449 | - * @param bool $add_error |
|
| 450 | - * @return bool |
|
| 451 | - */ |
|
| 452 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 453 | - { |
|
| 454 | - // don't allow config updates during WP heartbeats |
|
| 455 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 459 | - //$clone = clone( self::$_instance ); |
|
| 460 | - //self::$_instance = NULL; |
|
| 461 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 462 | - $this->_reset_espresso_addon_config(); |
|
| 463 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 464 | - // but BEFORE the actual update occurs |
|
| 465 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 466 | - // now update "ee_config" |
|
| 467 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 468 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 469 | - // if not saved... check if the hook we just added still exists; |
|
| 470 | - // if it does, it means one of two things: |
|
| 471 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 472 | - // or... |
|
| 473 | - // the db update query returned 0 rows affected |
|
| 474 | - // (probably because the data value was the same from it's perspective) |
|
| 475 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 476 | - // but just means no update occurred, so don't display an error to the user. |
|
| 477 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 478 | - // then it means that something truly went wrong |
|
| 479 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 480 | - // remove our action since we don't want it in the system anymore |
|
| 481 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 482 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 483 | - //self::$_instance = $clone; |
|
| 484 | - //unset( $clone ); |
|
| 485 | - // if config remains the same or was updated successfully |
|
| 486 | - if ($saved) { |
|
| 487 | - if ($add_success) { |
|
| 488 | - EE_Error::add_success( |
|
| 489 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 490 | - __FILE__, |
|
| 491 | - __FUNCTION__, |
|
| 492 | - __LINE__ |
|
| 493 | - ); |
|
| 494 | - } |
|
| 495 | - return true; |
|
| 496 | - } else { |
|
| 497 | - if ($add_error) { |
|
| 498 | - EE_Error::add_error( |
|
| 499 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 500 | - __FILE__, |
|
| 501 | - __FUNCTION__, |
|
| 502 | - __LINE__ |
|
| 503 | - ); |
|
| 504 | - } |
|
| 505 | - return false; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * _verify_config_params |
|
| 513 | - * |
|
| 514 | - * @access private |
|
| 515 | - * @param string $section |
|
| 516 | - * @param string $name |
|
| 517 | - * @param string $config_class |
|
| 518 | - * @param EE_Config_Base $config_obj |
|
| 519 | - * @param array $tests_to_run |
|
| 520 | - * @param bool $display_errors |
|
| 521 | - * @return bool TRUE on success, FALSE on fail |
|
| 522 | - */ |
|
| 523 | - private function _verify_config_params( |
|
| 524 | - $section = '', |
|
| 525 | - $name = '', |
|
| 526 | - $config_class = '', |
|
| 527 | - $config_obj = null, |
|
| 528 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 529 | - $display_errors = true |
|
| 530 | - ) { |
|
| 531 | - try { |
|
| 532 | - foreach ($tests_to_run as $test) { |
|
| 533 | - switch ($test) { |
|
| 534 | - // TEST #1 : check that section was set |
|
| 535 | - case 1 : |
|
| 536 | - if (empty($section)) { |
|
| 537 | - if ($display_errors) { |
|
| 538 | - throw new EE_Error( |
|
| 539 | - sprintf( |
|
| 540 | - __( |
|
| 541 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 542 | - 'event_espresso' |
|
| 543 | - ), |
|
| 544 | - $config_class |
|
| 545 | - ) |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - return false; |
|
| 549 | - } |
|
| 550 | - break; |
|
| 551 | - // TEST #2 : check that settings section exists |
|
| 552 | - case 2 : |
|
| 553 | - if (! isset($this->{$section})) { |
|
| 554 | - if ($display_errors) { |
|
| 555 | - throw new EE_Error( |
|
| 556 | - sprintf( |
|
| 557 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 558 | - $section |
|
| 559 | - ) |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - break; |
|
| 565 | - // TEST #3 : check that section is the proper format |
|
| 566 | - case 3 : |
|
| 567 | - if ( |
|
| 568 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 569 | - ) { |
|
| 570 | - if ($display_errors) { |
|
| 571 | - throw new EE_Error( |
|
| 572 | - sprintf( |
|
| 573 | - __( |
|
| 574 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 575 | - 'event_espresso' |
|
| 576 | - ), |
|
| 577 | - $section |
|
| 578 | - ) |
|
| 579 | - ); |
|
| 580 | - } |
|
| 581 | - return false; |
|
| 582 | - } |
|
| 583 | - break; |
|
| 584 | - // TEST #4 : check that config section name has been set |
|
| 585 | - case 4 : |
|
| 586 | - if (empty($name)) { |
|
| 587 | - if ($display_errors) { |
|
| 588 | - throw new EE_Error( |
|
| 589 | - __( |
|
| 590 | - 'No name has been provided for the specific configuration section.', |
|
| 591 | - 'event_espresso' |
|
| 592 | - ) |
|
| 593 | - ); |
|
| 594 | - } |
|
| 595 | - return false; |
|
| 596 | - } |
|
| 597 | - break; |
|
| 598 | - // TEST #5 : check that a config class name has been set |
|
| 599 | - case 5 : |
|
| 600 | - if (empty($config_class)) { |
|
| 601 | - if ($display_errors) { |
|
| 602 | - throw new EE_Error( |
|
| 603 | - __( |
|
| 604 | - 'No class name has been provided for the specific configuration section.', |
|
| 605 | - 'event_espresso' |
|
| 606 | - ) |
|
| 607 | - ); |
|
| 608 | - } |
|
| 609 | - return false; |
|
| 610 | - } |
|
| 611 | - break; |
|
| 612 | - // TEST #6 : verify config class is accessible |
|
| 613 | - case 6 : |
|
| 614 | - if (! class_exists($config_class)) { |
|
| 615 | - if ($display_errors) { |
|
| 616 | - throw new EE_Error( |
|
| 617 | - sprintf( |
|
| 618 | - __( |
|
| 619 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 620 | - 'event_espresso' |
|
| 621 | - ), |
|
| 622 | - $config_class |
|
| 623 | - ) |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - // TEST #7 : check that config has even been set |
|
| 630 | - case 7 : |
|
| 631 | - if (! isset($this->{$section}->{$name})) { |
|
| 632 | - if ($display_errors) { |
|
| 633 | - throw new EE_Error( |
|
| 634 | - sprintf( |
|
| 635 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 636 | - $section, |
|
| 637 | - $name |
|
| 638 | - ) |
|
| 639 | - ); |
|
| 640 | - } |
|
| 641 | - return false; |
|
| 642 | - } else { |
|
| 643 | - // and make sure it's not serialized |
|
| 644 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 645 | - } |
|
| 646 | - break; |
|
| 647 | - // TEST #8 : check that config is the requested type |
|
| 648 | - case 8 : |
|
| 649 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 650 | - if ($display_errors) { |
|
| 651 | - throw new EE_Error( |
|
| 652 | - sprintf( |
|
| 653 | - __( |
|
| 654 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 655 | - 'event_espresso' |
|
| 656 | - ), |
|
| 657 | - $section, |
|
| 658 | - $name, |
|
| 659 | - $config_class |
|
| 660 | - ) |
|
| 661 | - ); |
|
| 662 | - } |
|
| 663 | - return false; |
|
| 664 | - } |
|
| 665 | - break; |
|
| 666 | - // TEST #9 : verify config object |
|
| 667 | - case 9 : |
|
| 668 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 669 | - if ($display_errors) { |
|
| 670 | - throw new EE_Error( |
|
| 671 | - sprintf( |
|
| 672 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 673 | - print_r($config_obj, true) |
|
| 674 | - ) |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - return false; |
|
| 678 | - } |
|
| 679 | - break; |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - } catch (EE_Error $e) { |
|
| 683 | - $e->get_error(); |
|
| 684 | - } |
|
| 685 | - // you have successfully run the gauntlet |
|
| 686 | - return true; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * _generate_config_option_name |
|
| 693 | - * |
|
| 694 | - * @access protected |
|
| 695 | - * @param string $section |
|
| 696 | - * @param string $name |
|
| 697 | - * @return string |
|
| 698 | - */ |
|
| 699 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 700 | - { |
|
| 701 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * _set_config_class |
|
| 708 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 709 | - * |
|
| 710 | - * @access private |
|
| 711 | - * @param string $config_class |
|
| 712 | - * @param string $name |
|
| 713 | - * @return string |
|
| 714 | - */ |
|
| 715 | - private function _set_config_class($config_class = '', $name = '') |
|
| 716 | - { |
|
| 717 | - return ! empty($config_class) |
|
| 718 | - ? $config_class |
|
| 719 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * set_config |
|
| 726 | - * |
|
| 727 | - * @access protected |
|
| 728 | - * @param string $section |
|
| 729 | - * @param string $name |
|
| 730 | - * @param string $config_class |
|
| 731 | - * @param EE_Config_Base $config_obj |
|
| 732 | - * @return EE_Config_Base |
|
| 733 | - */ |
|
| 734 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 735 | - { |
|
| 736 | - // ensure config class is set to something |
|
| 737 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 738 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 739 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 740 | - return null; |
|
| 741 | - } |
|
| 742 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 743 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 744 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 745 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 746 | - $this->update_addon_option_names(); |
|
| 747 | - } |
|
| 748 | - // verify the incoming config object but suppress errors |
|
| 749 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 750 | - $config_obj = new $config_class(); |
|
| 751 | - } |
|
| 752 | - if (get_option($config_option_name)) { |
|
| 753 | - EE_Config::log($config_option_name); |
|
| 754 | - update_option($config_option_name, $config_obj); |
|
| 755 | - $this->{$section}->{$name} = $config_obj; |
|
| 756 | - return $this->{$section}->{$name}; |
|
| 757 | - } else { |
|
| 758 | - // create a wp-option for this config |
|
| 759 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 760 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 761 | - return $this->{$section}->{$name}; |
|
| 762 | - } else { |
|
| 763 | - EE_Error::add_error( |
|
| 764 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 765 | - __FILE__, |
|
| 766 | - __FUNCTION__, |
|
| 767 | - __LINE__ |
|
| 768 | - ); |
|
| 769 | - return null; |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * update_config |
|
| 778 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 779 | - * |
|
| 780 | - * @access public |
|
| 781 | - * @param string $section |
|
| 782 | - * @param string $name |
|
| 783 | - * @param EE_Config_Base|string $config_obj |
|
| 784 | - * @param bool $throw_errors |
|
| 785 | - * @return bool |
|
| 786 | - */ |
|
| 787 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 788 | - { |
|
| 789 | - // don't allow config updates during WP heartbeats |
|
| 790 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - $config_obj = maybe_unserialize($config_obj); |
|
| 794 | - // get class name of the incoming object |
|
| 795 | - $config_class = get_class($config_obj); |
|
| 796 | - // run tests 1-5 and 9 to verify config |
|
| 797 | - if (! $this->_verify_config_params( |
|
| 798 | - $section, |
|
| 799 | - $name, |
|
| 800 | - $config_class, |
|
| 801 | - $config_obj, |
|
| 802 | - array(1, 2, 3, 4, 7, 9) |
|
| 803 | - ) |
|
| 804 | - ) { |
|
| 805 | - return false; |
|
| 806 | - } |
|
| 807 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 808 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 809 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 810 | - // save new config to db |
|
| 811 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 812 | - return true; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - // first check if the record already exists |
|
| 816 | - $existing_config = get_option($config_option_name); |
|
| 817 | - $config_obj = serialize($config_obj); |
|
| 818 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 819 | - if ($existing_config == $config_obj) { |
|
| 820 | - $this->{$section}->{$name} = $config_obj; |
|
| 821 | - return true; |
|
| 822 | - } else if (update_option($config_option_name, $config_obj)) { |
|
| 823 | - EE_Config::log($config_option_name); |
|
| 824 | - // update wp-option for this config class |
|
| 825 | - $this->{$section}->{$name} = $config_obj; |
|
| 826 | - return true; |
|
| 827 | - } elseif ($throw_errors) { |
|
| 828 | - EE_Error::add_error( |
|
| 829 | - sprintf( |
|
| 830 | - __( |
|
| 831 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 832 | - 'event_espresso' |
|
| 833 | - ), |
|
| 834 | - $config_class, |
|
| 835 | - 'EE_Config->' . $section . '->' . $name |
|
| 836 | - ), |
|
| 837 | - __FILE__, |
|
| 838 | - __FUNCTION__, |
|
| 839 | - __LINE__ |
|
| 840 | - ); |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - /** |
|
| 897 | - * get_config_option |
|
| 898 | - * |
|
| 899 | - * @access public |
|
| 900 | - * @param string $config_option_name |
|
| 901 | - * @return mixed EE_Config_Base | FALSE |
|
| 902 | - */ |
|
| 903 | - public function get_config_option($config_option_name = '') |
|
| 904 | - { |
|
| 905 | - // retrieve the wp-option for this config class. |
|
| 906 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 907 | - if (empty($config_option)) { |
|
| 908 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 909 | - } |
|
| 910 | - return $config_option; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - /** |
|
| 916 | - * log |
|
| 917 | - * |
|
| 918 | - * @param string $config_option_name |
|
| 919 | - */ |
|
| 920 | - public static function log($config_option_name = '') |
|
| 921 | - { |
|
| 922 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | - $_request = $_REQUEST; |
|
| 926 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | - $config_log[(string)microtime(true)] = array( |
|
| 928 | - 'config_name' => $config_option_name, |
|
| 929 | - 'request' => $_request, |
|
| 930 | - ); |
|
| 931 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * trim_log |
|
| 939 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 940 | - */ |
|
| 941 | - public static function trim_log() |
|
| 942 | - { |
|
| 943 | - if (! EE_Config::logging_enabled()) { |
|
| 944 | - return; |
|
| 945 | - } |
|
| 946 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 947 | - $log_length = count($config_log); |
|
| 948 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 949 | - ksort($config_log); |
|
| 950 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 951 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * get_page_for_posts |
|
| 959 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 960 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 961 | - * |
|
| 962 | - * @access public |
|
| 963 | - * @return string |
|
| 964 | - */ |
|
| 965 | - public static function get_page_for_posts() |
|
| 966 | - { |
|
| 967 | - $page_for_posts = get_option('page_for_posts'); |
|
| 968 | - if (! $page_for_posts) { |
|
| 969 | - return 'posts'; |
|
| 970 | - } |
|
| 971 | - /** @type WPDB $wpdb */ |
|
| 972 | - global $wpdb; |
|
| 973 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 974 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * register_shortcodes_and_modules. |
|
| 981 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 982 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 983 | - * so they can help trigger maintenance mode if it's needed |
|
| 984 | - * |
|
| 985 | - * @access public |
|
| 986 | - * @return void |
|
| 987 | - */ |
|
| 988 | - public function register_shortcodes_and_modules() |
|
| 989 | - { |
|
| 990 | - // allow shortcodes to register with WP and to set hooks for the rest of the system |
|
| 991 | - EE_Registry::instance()->shortcodes = $this->_register_shortcodes(); |
|
| 992 | - // allow modules to set hooks for the rest of the system |
|
| 993 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * initialize_shortcodes_and_modules |
|
| 1000 | - * meaning they can start adding their hooks to get stuff done |
|
| 1001 | - * |
|
| 1002 | - * @access public |
|
| 1003 | - * @return void |
|
| 1004 | - */ |
|
| 1005 | - public function initialize_shortcodes_and_modules() |
|
| 1006 | - { |
|
| 1007 | - // allow shortcodes to set hooks for the rest of the system |
|
| 1008 | - $this->_initialize_shortcodes(); |
|
| 1009 | - // allow modules to set hooks for the rest of the system |
|
| 1010 | - $this->_initialize_modules(); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * widgets_init |
|
| 1017 | - * |
|
| 1018 | - * @access private |
|
| 1019 | - * @return void |
|
| 1020 | - */ |
|
| 1021 | - public function widgets_init() |
|
| 1022 | - { |
|
| 1023 | - //only init widgets on admin pages when not in complete maintenance, and |
|
| 1024 | - //on frontend when not in any maintenance mode |
|
| 1025 | - if ( |
|
| 1026 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1027 | - || ( |
|
| 1028 | - is_admin() |
|
| 1029 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1030 | - ) |
|
| 1031 | - ) { |
|
| 1032 | - // grab list of installed widgets |
|
| 1033 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1034 | - // filter list of modules to register |
|
| 1035 | - $widgets_to_register = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1037 | - $widgets_to_register |
|
| 1038 | - ); |
|
| 1039 | - if (! empty($widgets_to_register)) { |
|
| 1040 | - // cycle thru widget folders |
|
| 1041 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1042 | - // add to list of installed widget modules |
|
| 1043 | - EE_Config::register_ee_widget($widget_path); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - // filter list of installed modules |
|
| 1047 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1048 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1049 | - EE_Registry::instance()->widgets |
|
| 1050 | - ); |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * register_ee_widget - makes core aware of this widget |
|
| 1058 | - * |
|
| 1059 | - * @access public |
|
| 1060 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1061 | - * @return void |
|
| 1062 | - */ |
|
| 1063 | - public static function register_ee_widget($widget_path = null) |
|
| 1064 | - { |
|
| 1065 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1066 | - $widget_ext = '.widget.php'; |
|
| 1067 | - // make all separators match |
|
| 1068 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1069 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1070 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1071 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1072 | - $file_name = explode('.', basename($widget_path)); |
|
| 1073 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1074 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1075 | - // sanitize shortcode directory name |
|
| 1076 | - $widget = sanitize_key($widget); |
|
| 1077 | - // now we need to rebuild the shortcode path |
|
| 1078 | - $widget_path = explode(DS, $widget_path); |
|
| 1079 | - // remove last segment |
|
| 1080 | - array_pop($widget_path); |
|
| 1081 | - // glue it back together |
|
| 1082 | - $widget_path = implode(DS, $widget_path); |
|
| 1083 | - } else { |
|
| 1084 | - // grab and sanitize widget directory name |
|
| 1085 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1086 | - } |
|
| 1087 | - // create classname from widget directory name |
|
| 1088 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1089 | - // add class prefix |
|
| 1090 | - $widget_class = 'EEW_' . $widget; |
|
| 1091 | - // does the widget exist ? |
|
| 1092 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1093 | - $msg = sprintf( |
|
| 1094 | - __( |
|
| 1095 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1096 | - 'event_espresso' |
|
| 1097 | - ), |
|
| 1098 | - $widget_class, |
|
| 1099 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1100 | - ); |
|
| 1101 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1102 | - return; |
|
| 1103 | - } |
|
| 1104 | - // load the widget class file |
|
| 1105 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1106 | - // verify that class exists |
|
| 1107 | - if (! class_exists($widget_class)) { |
|
| 1108 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1109 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1110 | - return; |
|
| 1111 | - } |
|
| 1112 | - register_widget($widget_class); |
|
| 1113 | - // add to array of registered widgets |
|
| 1114 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * _register_shortcodes |
|
| 1121 | - * |
|
| 1122 | - * @access private |
|
| 1123 | - * @return array |
|
| 1124 | - */ |
|
| 1125 | - private function _register_shortcodes() |
|
| 1126 | - { |
|
| 1127 | - // grab list of installed shortcodes |
|
| 1128 | - $shortcodes_to_register = glob(EE_SHORTCODES . '*', GLOB_ONLYDIR); |
|
| 1129 | - // filter list of modules to register |
|
| 1130 | - $shortcodes_to_register = apply_filters( |
|
| 1131 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 1132 | - $shortcodes_to_register |
|
| 1133 | - ); |
|
| 1134 | - if (! empty($shortcodes_to_register)) { |
|
| 1135 | - // cycle thru shortcode folders |
|
| 1136 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 1137 | - // add to list of installed shortcode modules |
|
| 1138 | - EE_Config::register_shortcode($shortcode_path); |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - // filter list of installed modules |
|
| 1142 | - return apply_filters( |
|
| 1143 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 1144 | - EE_Registry::instance()->shortcodes |
|
| 1145 | - ); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * register_shortcode - makes core aware of this shortcode |
|
| 1152 | - * |
|
| 1153 | - * @access public |
|
| 1154 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1155 | - * @return bool |
|
| 1156 | - */ |
|
| 1157 | - public static function register_shortcode($shortcode_path = null) |
|
| 1158 | - { |
|
| 1159 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 1160 | - $shortcode_ext = '.shortcode.php'; |
|
| 1161 | - // make all separators match |
|
| 1162 | - $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path); |
|
| 1163 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1164 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 1165 | - // grab shortcode file name from directory name and break apart at dots |
|
| 1166 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 1167 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1168 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 1169 | - ? substr($shortcode_file[0], 4) |
|
| 1170 | - : $shortcode_file[0]; |
|
| 1171 | - // sanitize shortcode directory name |
|
| 1172 | - $shortcode = sanitize_key($shortcode); |
|
| 1173 | - // now we need to rebuild the shortcode path |
|
| 1174 | - $shortcode_path = explode(DS, $shortcode_path); |
|
| 1175 | - // remove last segment |
|
| 1176 | - array_pop($shortcode_path); |
|
| 1177 | - // glue it back together |
|
| 1178 | - $shortcode_path = implode(DS, $shortcode_path) . DS; |
|
| 1179 | - } else { |
|
| 1180 | - // we need to generate the filename based off of the folder name |
|
| 1181 | - // grab and sanitize shortcode directory name |
|
| 1182 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 1183 | - $shortcode_path = rtrim($shortcode_path, DS) . DS; |
|
| 1184 | - } |
|
| 1185 | - // create classname from shortcode directory or file name |
|
| 1186 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 1187 | - // add class prefix |
|
| 1188 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1189 | - // does the shortcode exist ? |
|
| 1190 | - if (! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) { |
|
| 1191 | - $msg = sprintf( |
|
| 1192 | - __( |
|
| 1193 | - 'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s', |
|
| 1194 | - 'event_espresso' |
|
| 1195 | - ), |
|
| 1196 | - $shortcode_class, |
|
| 1197 | - $shortcode_path . DS . $shortcode_class . $shortcode_ext |
|
| 1198 | - ); |
|
| 1199 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1200 | - return false; |
|
| 1201 | - } |
|
| 1202 | - // load the shortcode class file |
|
| 1203 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 1204 | - // verify that class exists |
|
| 1205 | - if (! class_exists($shortcode_class)) { |
|
| 1206 | - $msg = sprintf( |
|
| 1207 | - __('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 1208 | - $shortcode_class |
|
| 1209 | - ); |
|
| 1210 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1211 | - return false; |
|
| 1212 | - } |
|
| 1213 | - $shortcode = strtoupper($shortcode); |
|
| 1214 | - // add to array of registered shortcodes |
|
| 1215 | - EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 1216 | - return true; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - |
|
| 1220 | - |
|
| 1221 | - /** |
|
| 1222 | - * _register_modules |
|
| 1223 | - * |
|
| 1224 | - * @access private |
|
| 1225 | - * @return array |
|
| 1226 | - */ |
|
| 1227 | - private function _register_modules() |
|
| 1228 | - { |
|
| 1229 | - // grab list of installed modules |
|
| 1230 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1231 | - // filter list of modules to register |
|
| 1232 | - $modules_to_register = apply_filters( |
|
| 1233 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1234 | - $modules_to_register |
|
| 1235 | - ); |
|
| 1236 | - if (! empty($modules_to_register)) { |
|
| 1237 | - // loop through folders |
|
| 1238 | - foreach ($modules_to_register as $module_path) { |
|
| 1239 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1240 | - if ( |
|
| 1241 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1242 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1243 | - ) { |
|
| 1244 | - // add to list of installed modules |
|
| 1245 | - EE_Config::register_module($module_path); |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - // filter list of installed modules |
|
| 1250 | - return apply_filters( |
|
| 1251 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1252 | - EE_Registry::instance()->modules |
|
| 1253 | - ); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * register_module - makes core aware of this module |
|
| 1260 | - * |
|
| 1261 | - * @access public |
|
| 1262 | - * @param string $module_path - full path up to and including module folder |
|
| 1263 | - * @return bool |
|
| 1264 | - */ |
|
| 1265 | - public static function register_module($module_path = null) |
|
| 1266 | - { |
|
| 1267 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1268 | - $module_ext = '.module.php'; |
|
| 1269 | - // make all separators match |
|
| 1270 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1271 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1272 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1273 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1274 | - $module_file = explode('.', basename($module_path)); |
|
| 1275 | - // now we need to rebuild the shortcode path |
|
| 1276 | - $module_path = explode(DS, $module_path); |
|
| 1277 | - // remove last segment |
|
| 1278 | - array_pop($module_path); |
|
| 1279 | - // glue it back together |
|
| 1280 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1281 | - // take first segment from file name pieces and sanitize it |
|
| 1282 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1283 | - // ensure class prefix is added |
|
| 1284 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1285 | - } else { |
|
| 1286 | - // we need to generate the filename based off of the folder name |
|
| 1287 | - // grab and sanitize module name |
|
| 1288 | - $module = strtolower(basename($module_path)); |
|
| 1289 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1290 | - // like trailingslashit() |
|
| 1291 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1292 | - // create classname from module directory name |
|
| 1293 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1294 | - // add class prefix |
|
| 1295 | - $module_class = 'EED_' . $module; |
|
| 1296 | - } |
|
| 1297 | - // does the module exist ? |
|
| 1298 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1299 | - $msg = sprintf( |
|
| 1300 | - __( |
|
| 1301 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1302 | - 'event_espresso' |
|
| 1303 | - ), |
|
| 1304 | - $module |
|
| 1305 | - ); |
|
| 1306 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1307 | - return false; |
|
| 1308 | - } |
|
| 1309 | - // load the module class file |
|
| 1310 | - require_once($module_path . $module_class . $module_ext); |
|
| 1311 | - // verify that class exists |
|
| 1312 | - if (! class_exists($module_class)) { |
|
| 1313 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1314 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1315 | - return false; |
|
| 1316 | - } |
|
| 1317 | - // add to array of registered modules |
|
| 1318 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1319 | - do_action( |
|
| 1320 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1321 | - $module_class, |
|
| 1322 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1323 | - ); |
|
| 1324 | - return true; |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - |
|
| 1328 | - |
|
| 1329 | - /** |
|
| 1330 | - * _initialize_shortcodes |
|
| 1331 | - * allow shortcodes to set hooks for the rest of the system |
|
| 1332 | - * |
|
| 1333 | - * @access private |
|
| 1334 | - * @return void |
|
| 1335 | - */ |
|
| 1336 | - private function _initialize_shortcodes() |
|
| 1337 | - { |
|
| 1338 | - // cycle thru shortcode folders |
|
| 1339 | - foreach (EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path) { |
|
| 1340 | - // add class prefix |
|
| 1341 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 1342 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1343 | - // which set hooks ? |
|
| 1344 | - if (is_admin()) { |
|
| 1345 | - // fire immediately |
|
| 1346 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 1347 | - } else { |
|
| 1348 | - // delay until other systems are online |
|
| 1349 | - add_action( |
|
| 1350 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1351 | - array($shortcode_class, 'set_hooks') |
|
| 1352 | - ); |
|
| 1353 | - // convert classname to UPPERCASE and create WP shortcode. |
|
| 1354 | - $shortcode_tag = strtoupper($shortcode); |
|
| 1355 | - // but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor' |
|
| 1356 | - if (! shortcode_exists($shortcode_tag)) { |
|
| 1357 | - // NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes() |
|
| 1358 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 1359 | - } |
|
| 1360 | - } |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - /** |
|
| 1367 | - * _initialize_modules |
|
| 1368 | - * allow modules to set hooks for the rest of the system |
|
| 1369 | - * |
|
| 1370 | - * @access private |
|
| 1371 | - * @return void |
|
| 1372 | - */ |
|
| 1373 | - private function _initialize_modules() |
|
| 1374 | - { |
|
| 1375 | - // cycle thru shortcode folders |
|
| 1376 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1377 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1378 | - // which set hooks ? |
|
| 1379 | - if (is_admin()) { |
|
| 1380 | - // fire immediately |
|
| 1381 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1382 | - } else { |
|
| 1383 | - // delay until other systems are online |
|
| 1384 | - add_action( |
|
| 1385 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1386 | - array($module_class, 'set_hooks') |
|
| 1387 | - ); |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * register_route - adds module method routes to route_map |
|
| 1396 | - * |
|
| 1397 | - * @access public |
|
| 1398 | - * @param string $route - "pretty" public alias for module method |
|
| 1399 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1400 | - * @param string $method_name - the actual module method to be routed to |
|
| 1401 | - * @param string $key - url param key indicating a route is being called |
|
| 1402 | - * @return bool |
|
| 1403 | - */ |
|
| 1404 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1405 | - { |
|
| 1406 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1407 | - $module = str_replace('EED_', '', $module); |
|
| 1408 | - $module_class = 'EED_' . $module; |
|
| 1409 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1410 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1411 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1412 | - return false; |
|
| 1413 | - } |
|
| 1414 | - if (empty($route)) { |
|
| 1415 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1416 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1417 | - return false; |
|
| 1418 | - } |
|
| 1419 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1420 | - $msg = sprintf( |
|
| 1421 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1422 | - $route |
|
| 1423 | - ); |
|
| 1424 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1425 | - return false; |
|
| 1426 | - } |
|
| 1427 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1428 | - return true; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * get_route - get module method route |
|
| 1435 | - * |
|
| 1436 | - * @access public |
|
| 1437 | - * @param string $route - "pretty" public alias for module method |
|
| 1438 | - * @param string $key - url param key indicating a route is being called |
|
| 1439 | - * @return string |
|
| 1440 | - */ |
|
| 1441 | - public static function get_route($route = null, $key = 'ee') |
|
| 1442 | - { |
|
| 1443 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1444 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1445 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1446 | - return EE_Config::$_module_route_map[$key][$route]; |
|
| 1447 | - } |
|
| 1448 | - return null; |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * get_routes - get ALL module method routes |
|
| 1455 | - * |
|
| 1456 | - * @access public |
|
| 1457 | - * @return array |
|
| 1458 | - */ |
|
| 1459 | - public static function get_routes() |
|
| 1460 | - { |
|
| 1461 | - return EE_Config::$_module_route_map; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1468 | - * |
|
| 1469 | - * @access public |
|
| 1470 | - * @param string $route - "pretty" public alias for module method |
|
| 1471 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1472 | - * class, allows different forwards to be served based on status |
|
| 1473 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1474 | - * @param string $key - url param key indicating a route is being called |
|
| 1475 | - * @return bool |
|
| 1476 | - */ |
|
| 1477 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1478 | - { |
|
| 1479 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1480 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1481 | - $msg = sprintf( |
|
| 1482 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1483 | - $route |
|
| 1484 | - ); |
|
| 1485 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1486 | - return false; |
|
| 1487 | - } |
|
| 1488 | - if (empty($forward)) { |
|
| 1489 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1490 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1491 | - return false; |
|
| 1492 | - } |
|
| 1493 | - if (is_array($forward)) { |
|
| 1494 | - if (! isset($forward[1])) { |
|
| 1495 | - $msg = sprintf( |
|
| 1496 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1497 | - $route |
|
| 1498 | - ); |
|
| 1499 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1500 | - return false; |
|
| 1501 | - } |
|
| 1502 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1503 | - $msg = sprintf( |
|
| 1504 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1505 | - $forward[1], |
|
| 1506 | - $route |
|
| 1507 | - ); |
|
| 1508 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1509 | - return false; |
|
| 1510 | - } |
|
| 1511 | - } else if (! function_exists($forward)) { |
|
| 1512 | - $msg = sprintf( |
|
| 1513 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1514 | - $forward, |
|
| 1515 | - $route |
|
| 1516 | - ); |
|
| 1517 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1518 | - return false; |
|
| 1519 | - } |
|
| 1520 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1521 | - return true; |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - |
|
| 1525 | - |
|
| 1526 | - /** |
|
| 1527 | - * get_forward - get forwarding route |
|
| 1528 | - * |
|
| 1529 | - * @access public |
|
| 1530 | - * @param string $route - "pretty" public alias for module method |
|
| 1531 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1532 | - * allows different forwards to be served based on status |
|
| 1533 | - * @param string $key - url param key indicating a route is being called |
|
| 1534 | - * @return string |
|
| 1535 | - */ |
|
| 1536 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1537 | - { |
|
| 1538 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1539 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1540 | - return apply_filters( |
|
| 1541 | - 'FHEE__EE_Config__get_forward', |
|
| 1542 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1543 | - $route, |
|
| 1544 | - $status |
|
| 1545 | - ); |
|
| 1546 | - } |
|
| 1547 | - return null; |
|
| 1548 | - } |
|
| 1549 | - |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - /** |
|
| 1553 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1554 | - * results |
|
| 1555 | - * |
|
| 1556 | - * @access public |
|
| 1557 | - * @param string $route - "pretty" public alias for module method |
|
| 1558 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1559 | - * allows different views to be served based on status |
|
| 1560 | - * @param string $view |
|
| 1561 | - * @param string $key - url param key indicating a route is being called |
|
| 1562 | - * @return bool |
|
| 1563 | - */ |
|
| 1564 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1565 | - { |
|
| 1566 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1567 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1568 | - $msg = sprintf( |
|
| 1569 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1570 | - $route |
|
| 1571 | - ); |
|
| 1572 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1573 | - return false; |
|
| 1574 | - } |
|
| 1575 | - if (! is_readable($view)) { |
|
| 1576 | - $msg = sprintf( |
|
| 1577 | - __( |
|
| 1578 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1579 | - 'event_espresso' |
|
| 1580 | - ), |
|
| 1581 | - $view |
|
| 1582 | - ); |
|
| 1583 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1584 | - return false; |
|
| 1585 | - } |
|
| 1586 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1587 | - return true; |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * get_view - get view for route and status |
|
| 1594 | - * |
|
| 1595 | - * @access public |
|
| 1596 | - * @param string $route - "pretty" public alias for module method |
|
| 1597 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1598 | - * allows different views to be served based on status |
|
| 1599 | - * @param string $key - url param key indicating a route is being called |
|
| 1600 | - * @return string |
|
| 1601 | - */ |
|
| 1602 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1603 | - { |
|
| 1604 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1605 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1606 | - return apply_filters( |
|
| 1607 | - 'FHEE__EE_Config__get_view', |
|
| 1608 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1609 | - $route, |
|
| 1610 | - $status |
|
| 1611 | - ); |
|
| 1612 | - } |
|
| 1613 | - return null; |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - |
|
| 1618 | - public function update_addon_option_names() |
|
| 1619 | - { |
|
| 1620 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - |
|
| 1624 | - |
|
| 1625 | - public function shutdown() |
|
| 1626 | - { |
|
| 1627 | - $this->update_addon_option_names(); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - |
|
| 1631 | -} |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | -/** |
|
| 1636 | - * Base class used for config classes. These classes should generally not have |
|
| 1637 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1638 | - * basically, they should just be well-defined stdClasses |
|
| 1639 | - */ |
|
| 1640 | -class EE_Config_Base |
|
| 1641 | -{ |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * Utility function for escaping the value of a property and returning. |
|
| 1645 | - * |
|
| 1646 | - * @param string $property property name (checks to see if exists). |
|
| 1647 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1648 | - * @throws \EE_Error |
|
| 1649 | - */ |
|
| 1650 | - public function get_pretty($property) |
|
| 1651 | - { |
|
| 1652 | - if (! property_exists($this, $property)) { |
|
| 1653 | - throw new EE_Error( |
|
| 1654 | - sprintf( |
|
| 1655 | - __( |
|
| 1656 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1657 | - 'event_espresso' |
|
| 1658 | - ), |
|
| 1659 | - get_class($this), |
|
| 1660 | - $property |
|
| 1661 | - ) |
|
| 1662 | - ); |
|
| 1663 | - } |
|
| 1664 | - //just handling escaping of strings for now. |
|
| 1665 | - if (is_string($this->{$property})) { |
|
| 1666 | - return stripslashes($this->{$property}); |
|
| 1667 | - } |
|
| 1668 | - return $this->{$property}; |
|
| 1669 | - } |
|
| 1670 | - |
|
| 1671 | - |
|
| 1672 | - |
|
| 1673 | - public function populate() |
|
| 1674 | - { |
|
| 1675 | - //grab defaults via a new instance of this class. |
|
| 1676 | - $class_name = get_class($this); |
|
| 1677 | - $defaults = new $class_name; |
|
| 1678 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1679 | - //default from our $defaults object. |
|
| 1680 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1681 | - if ($this->{$property} === null) { |
|
| 1682 | - $this->{$property} = $value; |
|
| 1683 | - } |
|
| 1684 | - } |
|
| 1685 | - //cleanup |
|
| 1686 | - unset($defaults); |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * @ override magic methods |
|
| 1692 | - * @ return void |
|
| 1693 | - */ |
|
| 1694 | - // public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); } |
|
| 1695 | - // public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); } |
|
| 1696 | - /** |
|
| 1697 | - * __isset |
|
| 1698 | - * |
|
| 1699 | - * @param $a |
|
| 1700 | - * @return bool |
|
| 1701 | - */ |
|
| 1702 | - public function __isset($a) |
|
| 1703 | - { |
|
| 1704 | - return false; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - |
|
| 1708 | - |
|
| 1709 | - /** |
|
| 1710 | - * __unset |
|
| 1711 | - * |
|
| 1712 | - * @param $a |
|
| 1713 | - * @return bool |
|
| 1714 | - */ |
|
| 1715 | - public function __unset($a) |
|
| 1716 | - { |
|
| 1717 | - return false; |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * __clone |
|
| 1724 | - */ |
|
| 1725 | - public function __clone() |
|
| 1726 | - { |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * __wakeup |
|
| 1733 | - */ |
|
| 1734 | - public function __wakeup() |
|
| 1735 | - { |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * __destruct |
|
| 1742 | - */ |
|
| 1743 | - public function __destruct() |
|
| 1744 | - { |
|
| 1745 | - } |
|
| 1746 | -} |
|
| 1747 | - |
|
| 1748 | - |
|
| 1749 | - |
|
| 1750 | -/** |
|
| 1751 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1752 | - */ |
|
| 1753 | -class EE_Core_Config extends EE_Config_Base |
|
| 1754 | -{ |
|
| 1755 | - |
|
| 1756 | - public $current_blog_id; |
|
| 1757 | - |
|
| 1758 | - public $ee_ueip_optin; |
|
| 1759 | - |
|
| 1760 | - public $ee_ueip_has_notified; |
|
| 1761 | - |
|
| 1762 | - /** |
|
| 1763 | - * Not to be confused with the 4 critical page variables (See |
|
| 1764 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1765 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1766 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1767 | - * |
|
| 1768 | - * @var array |
|
| 1769 | - */ |
|
| 1770 | - public $post_shortcodes; |
|
| 1771 | - |
|
| 1772 | - public $module_route_map; |
|
| 1773 | - |
|
| 1774 | - public $module_forward_map; |
|
| 1775 | - |
|
| 1776 | - public $module_view_map; |
|
| 1777 | - |
|
| 1778 | - /** |
|
| 1779 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1780 | - * |
|
| 1781 | - * @var int |
|
| 1782 | - */ |
|
| 1783 | - public $reg_page_id; |
|
| 1784 | - |
|
| 1785 | - public $txn_page_id; |
|
| 1786 | - |
|
| 1787 | - public $thank_you_page_id; |
|
| 1788 | - |
|
| 1789 | - public $cancel_page_id; |
|
| 1790 | - |
|
| 1791 | - /** |
|
| 1792 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1793 | - * |
|
| 1794 | - * @var int |
|
| 1795 | - */ |
|
| 1796 | - public $reg_page_url; |
|
| 1797 | - |
|
| 1798 | - public $txn_page_url; |
|
| 1799 | - |
|
| 1800 | - public $thank_you_page_url; |
|
| 1801 | - |
|
| 1802 | - public $cancel_page_url; |
|
| 1803 | - |
|
| 1804 | - /** |
|
| 1805 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1806 | - */ |
|
| 1807 | - public $event_cpt_slug; |
|
| 1808 | - |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1812 | - * request across blog switches in a multisite context. |
|
| 1813 | - * Avoids extra queries to the db for this option. |
|
| 1814 | - * |
|
| 1815 | - * @var bool |
|
| 1816 | - */ |
|
| 1817 | - public static $ee_ueip_option; |
|
| 1818 | - |
|
| 1819 | - |
|
| 1820 | - |
|
| 1821 | - /** |
|
| 1822 | - * class constructor |
|
| 1823 | - * |
|
| 1824 | - * @access public |
|
| 1825 | - */ |
|
| 1826 | - public function __construct() |
|
| 1827 | - { |
|
| 1828 | - // set default organization settings |
|
| 1829 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1830 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1831 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1832 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1833 | - $this->post_shortcodes = array(); |
|
| 1834 | - $this->module_route_map = array(); |
|
| 1835 | - $this->module_forward_map = array(); |
|
| 1836 | - $this->module_view_map = array(); |
|
| 1837 | - // critical EE page IDs |
|
| 1838 | - $this->reg_page_id = 0; |
|
| 1839 | - $this->txn_page_id = 0; |
|
| 1840 | - $this->thank_you_page_id = 0; |
|
| 1841 | - $this->cancel_page_id = 0; |
|
| 1842 | - // critical EE page URLs |
|
| 1843 | - $this->reg_page_url = ''; |
|
| 1844 | - $this->txn_page_url = ''; |
|
| 1845 | - $this->thank_you_page_url = ''; |
|
| 1846 | - $this->cancel_page_url = ''; |
|
| 1847 | - //cpt slugs |
|
| 1848 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1849 | - //ueip constant check |
|
| 1850 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1851 | - $this->ee_ueip_optin = false; |
|
| 1852 | - $this->ee_ueip_has_notified = true; |
|
| 1853 | - } |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * @return array |
|
| 1860 | - */ |
|
| 1861 | - public function get_critical_pages_array() |
|
| 1862 | - { |
|
| 1863 | - return array( |
|
| 1864 | - $this->reg_page_id, |
|
| 1865 | - $this->txn_page_id, |
|
| 1866 | - $this->thank_you_page_id, |
|
| 1867 | - $this->cancel_page_id, |
|
| 1868 | - ); |
|
| 1869 | - } |
|
| 1870 | - |
|
| 1871 | - |
|
| 1872 | - |
|
| 1873 | - /** |
|
| 1874 | - * @return array |
|
| 1875 | - */ |
|
| 1876 | - public function get_critical_pages_shortcodes_array() |
|
| 1877 | - { |
|
| 1878 | - return array( |
|
| 1879 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1880 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1881 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1882 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1883 | - ); |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * gets/returns URL for EE reg_page |
|
| 1890 | - * |
|
| 1891 | - * @access public |
|
| 1892 | - * @return string |
|
| 1893 | - */ |
|
| 1894 | - public function reg_page_url() |
|
| 1895 | - { |
|
| 1896 | - if (! $this->reg_page_url) { |
|
| 1897 | - $this->reg_page_url = add_query_arg( |
|
| 1898 | - array('uts' => time()), |
|
| 1899 | - get_permalink($this->reg_page_id) |
|
| 1900 | - ) . '#checkout'; |
|
| 1901 | - } |
|
| 1902 | - return $this->reg_page_url; |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - |
|
| 1906 | - |
|
| 1907 | - /** |
|
| 1908 | - * gets/returns URL for EE txn_page |
|
| 1909 | - * |
|
| 1910 | - * @param array $query_args like what gets passed to |
|
| 1911 | - * add_query_arg() as the first argument |
|
| 1912 | - * @access public |
|
| 1913 | - * @return string |
|
| 1914 | - */ |
|
| 1915 | - public function txn_page_url($query_args = array()) |
|
| 1916 | - { |
|
| 1917 | - if (! $this->txn_page_url) { |
|
| 1918 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1919 | - } |
|
| 1920 | - if ($query_args) { |
|
| 1921 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1922 | - } else { |
|
| 1923 | - return $this->txn_page_url; |
|
| 1924 | - } |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - |
|
| 1928 | - |
|
| 1929 | - /** |
|
| 1930 | - * gets/returns URL for EE thank_you_page |
|
| 1931 | - * |
|
| 1932 | - * @param array $query_args like what gets passed to |
|
| 1933 | - * add_query_arg() as the first argument |
|
| 1934 | - * @access public |
|
| 1935 | - * @return string |
|
| 1936 | - */ |
|
| 1937 | - public function thank_you_page_url($query_args = array()) |
|
| 1938 | - { |
|
| 1939 | - if (! $this->thank_you_page_url) { |
|
| 1940 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1941 | - } |
|
| 1942 | - if ($query_args) { |
|
| 1943 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1944 | - } else { |
|
| 1945 | - return $this->thank_you_page_url; |
|
| 1946 | - } |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - |
|
| 1950 | - |
|
| 1951 | - /** |
|
| 1952 | - * gets/returns URL for EE cancel_page |
|
| 1953 | - * |
|
| 1954 | - * @access public |
|
| 1955 | - * @return string |
|
| 1956 | - */ |
|
| 1957 | - public function cancel_page_url() |
|
| 1958 | - { |
|
| 1959 | - if (! $this->cancel_page_url) { |
|
| 1960 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1961 | - } |
|
| 1962 | - return $this->cancel_page_url; |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - |
|
| 1966 | - |
|
| 1967 | - /** |
|
| 1968 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1969 | - * |
|
| 1970 | - * @since 4.7.5 |
|
| 1971 | - */ |
|
| 1972 | - protected function _reset_urls() |
|
| 1973 | - { |
|
| 1974 | - $this->reg_page_url = ''; |
|
| 1975 | - $this->txn_page_url = ''; |
|
| 1976 | - $this->cancel_page_url = ''; |
|
| 1977 | - $this->thank_you_page_url = ''; |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1984 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1985 | - * on the main site only. |
|
| 1986 | - * |
|
| 1987 | - * @return mixed|void |
|
| 1988 | - */ |
|
| 1989 | - protected function _get_main_ee_ueip_optin() |
|
| 1990 | - { |
|
| 1991 | - //if this is the main site then we can just bypass our direct query. |
|
| 1992 | - if (is_main_site()) { |
|
| 1993 | - return get_option('ee_ueip_optin', false); |
|
| 1994 | - } |
|
| 1995 | - //is this already cached for this request? If so use it. |
|
| 1996 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1997 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1998 | - } |
|
| 1999 | - global $wpdb; |
|
| 2000 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 2001 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 2002 | - $option = 'ee_ueip_optin'; |
|
| 2003 | - //set correct table for query |
|
| 2004 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 2005 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 2006 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 2007 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 2008 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 2009 | - //for the purpose of caching. |
|
| 2010 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 2011 | - if (false !== $pre) { |
|
| 2012 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 2013 | - return EE_Core_Config::$ee_ueip_option; |
|
| 2014 | - } |
|
| 2015 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 2016 | - $option)); |
|
| 2017 | - if (is_object($row)) { |
|
| 2018 | - $value = $row->option_value; |
|
| 2019 | - } else { //option does not exist so use default. |
|
| 2020 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 2021 | - } |
|
| 2022 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 2023 | - return EE_Core_Config::$ee_ueip_option; |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - |
|
| 2027 | - |
|
| 2028 | - /** |
|
| 2029 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 2030 | - * on the object. |
|
| 2031 | - * |
|
| 2032 | - * @return array |
|
| 2033 | - */ |
|
| 2034 | - public function __sleep() |
|
| 2035 | - { |
|
| 2036 | - //reset all url properties |
|
| 2037 | - $this->_reset_urls(); |
|
| 2038 | - //return what to save to db |
|
| 2039 | - return array_keys(get_object_vars($this)); |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | -} |
|
| 2043 | - |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | -/** |
|
| 2047 | - * Config class for storing info on the Organization |
|
| 2048 | - */ |
|
| 2049 | -class EE_Organization_Config extends EE_Config_Base |
|
| 2050 | -{ |
|
| 2051 | - |
|
| 2052 | - /** |
|
| 2053 | - * @var string $name |
|
| 2054 | - * eg EE4.1 |
|
| 2055 | - */ |
|
| 2056 | - public $name; |
|
| 2057 | - |
|
| 2058 | - /** |
|
| 2059 | - * @var string $address_1 |
|
| 2060 | - * eg 123 Onna Road |
|
| 2061 | - */ |
|
| 2062 | - public $address_1; |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * @var string $address_2 |
|
| 2066 | - * eg PO Box 123 |
|
| 2067 | - */ |
|
| 2068 | - public $address_2; |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * @var string $city |
|
| 2072 | - * eg Inna City |
|
| 2073 | - */ |
|
| 2074 | - public $city; |
|
| 2075 | - |
|
| 2076 | - /** |
|
| 2077 | - * @var int $STA_ID |
|
| 2078 | - * eg 4 |
|
| 2079 | - */ |
|
| 2080 | - public $STA_ID; |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * @var string $CNT_ISO |
|
| 2084 | - * eg US |
|
| 2085 | - */ |
|
| 2086 | - public $CNT_ISO; |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * @var string $zip |
|
| 2090 | - * eg 12345 or V1A 2B3 |
|
| 2091 | - */ |
|
| 2092 | - public $zip; |
|
| 2093 | - |
|
| 2094 | - /** |
|
| 2095 | - * @var string $email |
|
| 2096 | - * eg [email protected] |
|
| 2097 | - */ |
|
| 2098 | - public $email; |
|
| 2099 | - |
|
| 2100 | - |
|
| 2101 | - /** |
|
| 2102 | - * @var string $phone |
|
| 2103 | - * eg. 111-111-1111 |
|
| 2104 | - */ |
|
| 2105 | - public $phone; |
|
| 2106 | - |
|
| 2107 | - |
|
| 2108 | - /** |
|
| 2109 | - * @var string $vat |
|
| 2110 | - * VAT/Tax Number |
|
| 2111 | - */ |
|
| 2112 | - public $vat; |
|
| 2113 | - |
|
| 2114 | - /** |
|
| 2115 | - * @var string $logo_url |
|
| 2116 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2117 | - */ |
|
| 2118 | - public $logo_url; |
|
| 2119 | - |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2123 | - * |
|
| 2124 | - * @var string |
|
| 2125 | - */ |
|
| 2126 | - /** |
|
| 2127 | - * facebook (facebook.com/profile.name) |
|
| 2128 | - * |
|
| 2129 | - * @var string |
|
| 2130 | - */ |
|
| 2131 | - public $facebook; |
|
| 2132 | - |
|
| 2133 | - |
|
| 2134 | - /** |
|
| 2135 | - * twitter (twitter.com/twitter_handle) |
|
| 2136 | - * |
|
| 2137 | - * @var string |
|
| 2138 | - */ |
|
| 2139 | - public $twitter; |
|
| 2140 | - |
|
| 2141 | - |
|
| 2142 | - /** |
|
| 2143 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2144 | - * |
|
| 2145 | - * @var string |
|
| 2146 | - */ |
|
| 2147 | - public $linkedin; |
|
| 2148 | - |
|
| 2149 | - |
|
| 2150 | - /** |
|
| 2151 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2152 | - * |
|
| 2153 | - * @var string |
|
| 2154 | - */ |
|
| 2155 | - public $pinterest; |
|
| 2156 | - |
|
| 2157 | - |
|
| 2158 | - /** |
|
| 2159 | - * google+ (google.com/+profileName) |
|
| 2160 | - * |
|
| 2161 | - * @var string |
|
| 2162 | - */ |
|
| 2163 | - public $google; |
|
| 2164 | - |
|
| 2165 | - |
|
| 2166 | - /** |
|
| 2167 | - * instagram (instagram.com/handle) |
|
| 2168 | - * |
|
| 2169 | - * @var string |
|
| 2170 | - */ |
|
| 2171 | - public $instagram; |
|
| 2172 | - |
|
| 2173 | - |
|
| 2174 | - |
|
| 2175 | - /** |
|
| 2176 | - * class constructor |
|
| 2177 | - * |
|
| 2178 | - * @access public |
|
| 2179 | - */ |
|
| 2180 | - public function __construct() |
|
| 2181 | - { |
|
| 2182 | - // set default organization settings |
|
| 2183 | - $this->name = get_bloginfo('name'); |
|
| 2184 | - $this->address_1 = '123 Onna Road'; |
|
| 2185 | - $this->address_2 = 'PO Box 123'; |
|
| 2186 | - $this->city = 'Inna City'; |
|
| 2187 | - $this->STA_ID = 4; |
|
| 2188 | - $this->CNT_ISO = 'US'; |
|
| 2189 | - $this->zip = '12345'; |
|
| 2190 | - $this->email = get_bloginfo('admin_email'); |
|
| 2191 | - $this->phone = ''; |
|
| 2192 | - $this->vat = '123456789'; |
|
| 2193 | - $this->logo_url = ''; |
|
| 2194 | - $this->facebook = ''; |
|
| 2195 | - $this->twitter = ''; |
|
| 2196 | - $this->linkedin = ''; |
|
| 2197 | - $this->pinterest = ''; |
|
| 2198 | - $this->google = ''; |
|
| 2199 | - $this->instagram = ''; |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | -} |
|
| 2203 | - |
|
| 2204 | - |
|
| 2205 | - |
|
| 2206 | -/** |
|
| 2207 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2208 | - */ |
|
| 2209 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2210 | -{ |
|
| 2211 | - |
|
| 2212 | - /** |
|
| 2213 | - * @var string $code |
|
| 2214 | - * eg 'US' |
|
| 2215 | - */ |
|
| 2216 | - public $code; |
|
| 2217 | - |
|
| 2218 | - /** |
|
| 2219 | - * @var string $name |
|
| 2220 | - * eg 'Dollar' |
|
| 2221 | - */ |
|
| 2222 | - public $name; |
|
| 2223 | - |
|
| 2224 | - /** |
|
| 2225 | - * plural name |
|
| 2226 | - * |
|
| 2227 | - * @var string $plural |
|
| 2228 | - * eg 'Dollars' |
|
| 2229 | - */ |
|
| 2230 | - public $plural; |
|
| 2231 | - |
|
| 2232 | - /** |
|
| 2233 | - * currency sign |
|
| 2234 | - * |
|
| 2235 | - * @var string $sign |
|
| 2236 | - * eg '$' |
|
| 2237 | - */ |
|
| 2238 | - public $sign; |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * Whether the currency sign should come before the number or not |
|
| 2242 | - * |
|
| 2243 | - * @var boolean $sign_b4 |
|
| 2244 | - */ |
|
| 2245 | - public $sign_b4; |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * How many digits should come after the decimal place |
|
| 2249 | - * |
|
| 2250 | - * @var int $dec_plc |
|
| 2251 | - */ |
|
| 2252 | - public $dec_plc; |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * Symbol to use for decimal mark |
|
| 2256 | - * |
|
| 2257 | - * @var string $dec_mrk |
|
| 2258 | - * eg '.' |
|
| 2259 | - */ |
|
| 2260 | - public $dec_mrk; |
|
| 2261 | - |
|
| 2262 | - /** |
|
| 2263 | - * Symbol to use for thousands |
|
| 2264 | - * |
|
| 2265 | - * @var string $thsnds |
|
| 2266 | - * eg ',' |
|
| 2267 | - */ |
|
| 2268 | - public $thsnds; |
|
| 2269 | - |
|
| 2270 | - |
|
| 2271 | - |
|
| 2272 | - /** |
|
| 2273 | - * class constructor |
|
| 2274 | - * |
|
| 2275 | - * @access public |
|
| 2276 | - * @param string $CNT_ISO |
|
| 2277 | - * @throws \EE_Error |
|
| 2278 | - */ |
|
| 2279 | - public function __construct($CNT_ISO = '') |
|
| 2280 | - { |
|
| 2281 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2282 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2283 | - // get country code from organization settings or use default |
|
| 2284 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2285 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2286 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2287 | - : ''; |
|
| 2288 | - // but override if requested |
|
| 2289 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2290 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2291 | - if ( |
|
| 2292 | - ! empty($CNT_ISO) |
|
| 2293 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2294 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2295 | - ) { |
|
| 2296 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2297 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2298 | - if ($country instanceof EE_Country) { |
|
| 2299 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2300 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2301 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2302 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2303 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2304 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2305 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2306 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2307 | - } |
|
| 2308 | - } |
|
| 2309 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2310 | - if (empty($this->code)) { |
|
| 2311 | - // set default currency settings |
|
| 2312 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2313 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2314 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2315 | - $this->sign = '$'; // currency sign: $ |
|
| 2316 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2317 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2318 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2319 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2320 | - } |
|
| 2321 | - } |
|
| 2322 | -} |
|
| 2323 | - |
|
| 2324 | - |
|
| 2325 | - |
|
| 2326 | -/** |
|
| 2327 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2328 | - */ |
|
| 2329 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2330 | -{ |
|
| 2331 | - |
|
| 2332 | - /** |
|
| 2333 | - * Default registration status |
|
| 2334 | - * |
|
| 2335 | - * @var string $default_STS_ID |
|
| 2336 | - * eg 'RPP' |
|
| 2337 | - */ |
|
| 2338 | - public $default_STS_ID; |
|
| 2339 | - |
|
| 2340 | - |
|
| 2341 | - /** |
|
| 2342 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2343 | - * registrations) |
|
| 2344 | - * @var int |
|
| 2345 | - */ |
|
| 2346 | - public $default_maximum_number_of_tickets; |
|
| 2347 | - |
|
| 2348 | - |
|
| 2349 | - /** |
|
| 2350 | - * level of validation to apply to email addresses |
|
| 2351 | - * |
|
| 2352 | - * @var string $email_validation_level |
|
| 2353 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2354 | - */ |
|
| 2355 | - public $email_validation_level; |
|
| 2356 | - |
|
| 2357 | - /** |
|
| 2358 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2359 | - * |
|
| 2360 | - * @var boolean $show_pending_payment_options |
|
| 2361 | - */ |
|
| 2362 | - public $show_pending_payment_options; |
|
| 2363 | - |
|
| 2364 | - /** |
|
| 2365 | - * Whether to skip the registration confirmation page |
|
| 2366 | - * |
|
| 2367 | - * @var boolean $skip_reg_confirmation |
|
| 2368 | - */ |
|
| 2369 | - public $skip_reg_confirmation; |
|
| 2370 | - |
|
| 2371 | - /** |
|
| 2372 | - * an array of SPCO reg steps where: |
|
| 2373 | - * the keys denotes the reg step order |
|
| 2374 | - * each element consists of an array with the following elements: |
|
| 2375 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2376 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2377 | - * "slug" => the URL param used to trigger the reg step |
|
| 2378 | - * |
|
| 2379 | - * @var array $reg_steps |
|
| 2380 | - */ |
|
| 2381 | - public $reg_steps; |
|
| 2382 | - |
|
| 2383 | - /** |
|
| 2384 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2385 | - * |
|
| 2386 | - * @var boolean $reg_confirmation_last |
|
| 2387 | - */ |
|
| 2388 | - public $reg_confirmation_last; |
|
| 2389 | - |
|
| 2390 | - /** |
|
| 2391 | - * Whether or not to enable the EE Bot Trap |
|
| 2392 | - * |
|
| 2393 | - * @var boolean $use_bot_trap |
|
| 2394 | - */ |
|
| 2395 | - public $use_bot_trap; |
|
| 2396 | - |
|
| 2397 | - /** |
|
| 2398 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2399 | - * |
|
| 2400 | - * @var boolean $use_encryption |
|
| 2401 | - */ |
|
| 2402 | - public $use_encryption; |
|
| 1631 | +} |
|
| 2403 | 1632 | |
| 2404 | - /** |
|
| 2405 | - * Whether or not to use ReCaptcha |
|
| 2406 | - * |
|
| 2407 | - * @var boolean $use_captcha |
|
| 2408 | - */ |
|
| 2409 | - public $use_captcha; |
|
| 2410 | 1633 | |
| 2411 | - /** |
|
| 2412 | - * ReCaptcha Theme |
|
| 2413 | - * |
|
| 2414 | - * @var string $recaptcha_theme |
|
| 2415 | - * options: 'dark ', 'light' |
|
| 2416 | - */ |
|
| 2417 | - public $recaptcha_theme; |
|
| 2418 | 1634 | |
| 2419 | - /** |
|
| 2420 | - * ReCaptcha Type |
|
| 2421 | - * |
|
| 2422 | - * @var string $recaptcha_type |
|
| 2423 | - * options: 'audio', 'image' |
|
| 2424 | - */ |
|
| 2425 | - public $recaptcha_type; |
|
| 1635 | +/** |
|
| 1636 | + * Base class used for config classes. These classes should generally not have |
|
| 1637 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1638 | + * basically, they should just be well-defined stdClasses |
|
| 1639 | + */ |
|
| 1640 | +class EE_Config_Base |
|
| 1641 | +{ |
|
| 2426 | 1642 | |
| 2427 | - /** |
|
| 2428 | - * ReCaptcha language |
|
| 2429 | - * |
|
| 2430 | - * @var string $recaptcha_language |
|
| 2431 | - * eg 'en' |
|
| 2432 | - */ |
|
| 2433 | - public $recaptcha_language; |
|
| 1643 | + /** |
|
| 1644 | + * Utility function for escaping the value of a property and returning. |
|
| 1645 | + * |
|
| 1646 | + * @param string $property property name (checks to see if exists). |
|
| 1647 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1648 | + * @throws \EE_Error |
|
| 1649 | + */ |
|
| 1650 | + public function get_pretty($property) |
|
| 1651 | + { |
|
| 1652 | + if (! property_exists($this, $property)) { |
|
| 1653 | + throw new EE_Error( |
|
| 1654 | + sprintf( |
|
| 1655 | + __( |
|
| 1656 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1657 | + 'event_espresso' |
|
| 1658 | + ), |
|
| 1659 | + get_class($this), |
|
| 1660 | + $property |
|
| 1661 | + ) |
|
| 1662 | + ); |
|
| 1663 | + } |
|
| 1664 | + //just handling escaping of strings for now. |
|
| 1665 | + if (is_string($this->{$property})) { |
|
| 1666 | + return stripslashes($this->{$property}); |
|
| 1667 | + } |
|
| 1668 | + return $this->{$property}; |
|
| 1669 | + } |
|
| 1670 | + |
|
| 1671 | + |
|
| 1672 | + |
|
| 1673 | + public function populate() |
|
| 1674 | + { |
|
| 1675 | + //grab defaults via a new instance of this class. |
|
| 1676 | + $class_name = get_class($this); |
|
| 1677 | + $defaults = new $class_name; |
|
| 1678 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1679 | + //default from our $defaults object. |
|
| 1680 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1681 | + if ($this->{$property} === null) { |
|
| 1682 | + $this->{$property} = $value; |
|
| 1683 | + } |
|
| 1684 | + } |
|
| 1685 | + //cleanup |
|
| 1686 | + unset($defaults); |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * @ override magic methods |
|
| 1692 | + * @ return void |
|
| 1693 | + */ |
|
| 1694 | + // public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); } |
|
| 1695 | + // public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); } |
|
| 1696 | + /** |
|
| 1697 | + * __isset |
|
| 1698 | + * |
|
| 1699 | + * @param $a |
|
| 1700 | + * @return bool |
|
| 1701 | + */ |
|
| 1702 | + public function __isset($a) |
|
| 1703 | + { |
|
| 1704 | + return false; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + |
|
| 1708 | + |
|
| 1709 | + /** |
|
| 1710 | + * __unset |
|
| 1711 | + * |
|
| 1712 | + * @param $a |
|
| 1713 | + * @return bool |
|
| 1714 | + */ |
|
| 1715 | + public function __unset($a) |
|
| 1716 | + { |
|
| 1717 | + return false; |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * __clone |
|
| 1724 | + */ |
|
| 1725 | + public function __clone() |
|
| 1726 | + { |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * __wakeup |
|
| 1733 | + */ |
|
| 1734 | + public function __wakeup() |
|
| 1735 | + { |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * __destruct |
|
| 1742 | + */ |
|
| 1743 | + public function __destruct() |
|
| 1744 | + { |
|
| 1745 | + } |
|
| 1746 | +} |
|
| 2434 | 1747 | |
| 2435 | - /** |
|
| 2436 | - * ReCaptcha public key |
|
| 2437 | - * |
|
| 2438 | - * @var string $recaptcha_publickey |
|
| 2439 | - */ |
|
| 2440 | - public $recaptcha_publickey; |
|
| 2441 | 1748 | |
| 2442 | - /** |
|
| 2443 | - * ReCaptcha private key |
|
| 2444 | - * |
|
| 2445 | - * @var string $recaptcha_privatekey |
|
| 2446 | - */ |
|
| 2447 | - public $recaptcha_privatekey; |
|
| 2448 | 1749 | |
| 2449 | - /** |
|
| 2450 | - * ReCaptcha width |
|
| 2451 | - * |
|
| 2452 | - * @var int $recaptcha_width |
|
| 2453 | - * @deprecated |
|
| 2454 | - */ |
|
| 2455 | - public $recaptcha_width; |
|
| 1750 | +/** |
|
| 1751 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1752 | + */ |
|
| 1753 | +class EE_Core_Config extends EE_Config_Base |
|
| 1754 | +{ |
|
| 2456 | 1755 | |
| 2457 | - /** |
|
| 2458 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2459 | - * |
|
| 2460 | - * @var boolean $track_invalid_checkout_access |
|
| 2461 | - */ |
|
| 2462 | - protected $track_invalid_checkout_access = true; |
|
| 1756 | + public $current_blog_id; |
|
| 1757 | + |
|
| 1758 | + public $ee_ueip_optin; |
|
| 1759 | + |
|
| 1760 | + public $ee_ueip_has_notified; |
|
| 1761 | + |
|
| 1762 | + /** |
|
| 1763 | + * Not to be confused with the 4 critical page variables (See |
|
| 1764 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1765 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1766 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1767 | + * |
|
| 1768 | + * @var array |
|
| 1769 | + */ |
|
| 1770 | + public $post_shortcodes; |
|
| 1771 | + |
|
| 1772 | + public $module_route_map; |
|
| 1773 | + |
|
| 1774 | + public $module_forward_map; |
|
| 1775 | + |
|
| 1776 | + public $module_view_map; |
|
| 1777 | + |
|
| 1778 | + /** |
|
| 1779 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1780 | + * |
|
| 1781 | + * @var int |
|
| 1782 | + */ |
|
| 1783 | + public $reg_page_id; |
|
| 1784 | + |
|
| 1785 | + public $txn_page_id; |
|
| 1786 | + |
|
| 1787 | + public $thank_you_page_id; |
|
| 1788 | + |
|
| 1789 | + public $cancel_page_id; |
|
| 1790 | + |
|
| 1791 | + /** |
|
| 1792 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1793 | + * |
|
| 1794 | + * @var int |
|
| 1795 | + */ |
|
| 1796 | + public $reg_page_url; |
|
| 1797 | + |
|
| 1798 | + public $txn_page_url; |
|
| 1799 | + |
|
| 1800 | + public $thank_you_page_url; |
|
| 1801 | + |
|
| 1802 | + public $cancel_page_url; |
|
| 1803 | + |
|
| 1804 | + /** |
|
| 1805 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1806 | + */ |
|
| 1807 | + public $event_cpt_slug; |
|
| 1808 | + |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1812 | + * request across blog switches in a multisite context. |
|
| 1813 | + * Avoids extra queries to the db for this option. |
|
| 1814 | + * |
|
| 1815 | + * @var bool |
|
| 1816 | + */ |
|
| 1817 | + public static $ee_ueip_option; |
|
| 1818 | + |
|
| 1819 | + |
|
| 1820 | + |
|
| 1821 | + /** |
|
| 1822 | + * class constructor |
|
| 1823 | + * |
|
| 1824 | + * @access public |
|
| 1825 | + */ |
|
| 1826 | + public function __construct() |
|
| 1827 | + { |
|
| 1828 | + // set default organization settings |
|
| 1829 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1830 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1831 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1832 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1833 | + $this->post_shortcodes = array(); |
|
| 1834 | + $this->module_route_map = array(); |
|
| 1835 | + $this->module_forward_map = array(); |
|
| 1836 | + $this->module_view_map = array(); |
|
| 1837 | + // critical EE page IDs |
|
| 1838 | + $this->reg_page_id = 0; |
|
| 1839 | + $this->txn_page_id = 0; |
|
| 1840 | + $this->thank_you_page_id = 0; |
|
| 1841 | + $this->cancel_page_id = 0; |
|
| 1842 | + // critical EE page URLs |
|
| 1843 | + $this->reg_page_url = ''; |
|
| 1844 | + $this->txn_page_url = ''; |
|
| 1845 | + $this->thank_you_page_url = ''; |
|
| 1846 | + $this->cancel_page_url = ''; |
|
| 1847 | + //cpt slugs |
|
| 1848 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1849 | + //ueip constant check |
|
| 1850 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1851 | + $this->ee_ueip_optin = false; |
|
| 1852 | + $this->ee_ueip_has_notified = true; |
|
| 1853 | + } |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * @return array |
|
| 1860 | + */ |
|
| 1861 | + public function get_critical_pages_array() |
|
| 1862 | + { |
|
| 1863 | + return array( |
|
| 1864 | + $this->reg_page_id, |
|
| 1865 | + $this->txn_page_id, |
|
| 1866 | + $this->thank_you_page_id, |
|
| 1867 | + $this->cancel_page_id, |
|
| 1868 | + ); |
|
| 1869 | + } |
|
| 1870 | + |
|
| 1871 | + |
|
| 1872 | + |
|
| 1873 | + /** |
|
| 1874 | + * @return array |
|
| 1875 | + */ |
|
| 1876 | + public function get_critical_pages_shortcodes_array() |
|
| 1877 | + { |
|
| 1878 | + return array( |
|
| 1879 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1880 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1881 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1882 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1883 | + ); |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * gets/returns URL for EE reg_page |
|
| 1890 | + * |
|
| 1891 | + * @access public |
|
| 1892 | + * @return string |
|
| 1893 | + */ |
|
| 1894 | + public function reg_page_url() |
|
| 1895 | + { |
|
| 1896 | + if (! $this->reg_page_url) { |
|
| 1897 | + $this->reg_page_url = add_query_arg( |
|
| 1898 | + array('uts' => time()), |
|
| 1899 | + get_permalink($this->reg_page_id) |
|
| 1900 | + ) . '#checkout'; |
|
| 1901 | + } |
|
| 1902 | + return $this->reg_page_url; |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + |
|
| 1906 | + |
|
| 1907 | + /** |
|
| 1908 | + * gets/returns URL for EE txn_page |
|
| 1909 | + * |
|
| 1910 | + * @param array $query_args like what gets passed to |
|
| 1911 | + * add_query_arg() as the first argument |
|
| 1912 | + * @access public |
|
| 1913 | + * @return string |
|
| 1914 | + */ |
|
| 1915 | + public function txn_page_url($query_args = array()) |
|
| 1916 | + { |
|
| 1917 | + if (! $this->txn_page_url) { |
|
| 1918 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1919 | + } |
|
| 1920 | + if ($query_args) { |
|
| 1921 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1922 | + } else { |
|
| 1923 | + return $this->txn_page_url; |
|
| 1924 | + } |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + |
|
| 1928 | + |
|
| 1929 | + /** |
|
| 1930 | + * gets/returns URL for EE thank_you_page |
|
| 1931 | + * |
|
| 1932 | + * @param array $query_args like what gets passed to |
|
| 1933 | + * add_query_arg() as the first argument |
|
| 1934 | + * @access public |
|
| 1935 | + * @return string |
|
| 1936 | + */ |
|
| 1937 | + public function thank_you_page_url($query_args = array()) |
|
| 1938 | + { |
|
| 1939 | + if (! $this->thank_you_page_url) { |
|
| 1940 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1941 | + } |
|
| 1942 | + if ($query_args) { |
|
| 1943 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1944 | + } else { |
|
| 1945 | + return $this->thank_you_page_url; |
|
| 1946 | + } |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + |
|
| 1950 | + |
|
| 1951 | + /** |
|
| 1952 | + * gets/returns URL for EE cancel_page |
|
| 1953 | + * |
|
| 1954 | + * @access public |
|
| 1955 | + * @return string |
|
| 1956 | + */ |
|
| 1957 | + public function cancel_page_url() |
|
| 1958 | + { |
|
| 1959 | + if (! $this->cancel_page_url) { |
|
| 1960 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1961 | + } |
|
| 1962 | + return $this->cancel_page_url; |
|
| 1963 | + } |
|
| 1964 | + |
|
| 1965 | + |
|
| 1966 | + |
|
| 1967 | + /** |
|
| 1968 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1969 | + * |
|
| 1970 | + * @since 4.7.5 |
|
| 1971 | + */ |
|
| 1972 | + protected function _reset_urls() |
|
| 1973 | + { |
|
| 1974 | + $this->reg_page_url = ''; |
|
| 1975 | + $this->txn_page_url = ''; |
|
| 1976 | + $this->cancel_page_url = ''; |
|
| 1977 | + $this->thank_you_page_url = ''; |
|
| 1978 | + } |
|
| 1979 | + |
|
| 1980 | + |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1984 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1985 | + * on the main site only. |
|
| 1986 | + * |
|
| 1987 | + * @return mixed|void |
|
| 1988 | + */ |
|
| 1989 | + protected function _get_main_ee_ueip_optin() |
|
| 1990 | + { |
|
| 1991 | + //if this is the main site then we can just bypass our direct query. |
|
| 1992 | + if (is_main_site()) { |
|
| 1993 | + return get_option('ee_ueip_optin', false); |
|
| 1994 | + } |
|
| 1995 | + //is this already cached for this request? If so use it. |
|
| 1996 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1997 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1998 | + } |
|
| 1999 | + global $wpdb; |
|
| 2000 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 2001 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 2002 | + $option = 'ee_ueip_optin'; |
|
| 2003 | + //set correct table for query |
|
| 2004 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 2005 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 2006 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 2007 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 2008 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 2009 | + //for the purpose of caching. |
|
| 2010 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 2011 | + if (false !== $pre) { |
|
| 2012 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 2013 | + return EE_Core_Config::$ee_ueip_option; |
|
| 2014 | + } |
|
| 2015 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 2016 | + $option)); |
|
| 2017 | + if (is_object($row)) { |
|
| 2018 | + $value = $row->option_value; |
|
| 2019 | + } else { //option does not exist so use default. |
|
| 2020 | + return apply_filters('default_option_' . $option, false, $option); |
|
| 2021 | + } |
|
| 2022 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 2023 | + return EE_Core_Config::$ee_ueip_option; |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + |
|
| 2027 | + |
|
| 2028 | + /** |
|
| 2029 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 2030 | + * on the object. |
|
| 2031 | + * |
|
| 2032 | + * @return array |
|
| 2033 | + */ |
|
| 2034 | + public function __sleep() |
|
| 2035 | + { |
|
| 2036 | + //reset all url properties |
|
| 2037 | + $this->_reset_urls(); |
|
| 2038 | + //return what to save to db |
|
| 2039 | + return array_keys(get_object_vars($this)); |
|
| 2040 | + } |
|
| 2463 | 2041 | |
| 2042 | +} |
|
| 2464 | 2043 | |
| 2465 | 2044 | |
| 2466 | - /** |
|
| 2467 | - * class constructor |
|
| 2468 | - * |
|
| 2469 | - * @access public |
|
| 2470 | - */ |
|
| 2471 | - public function __construct() |
|
| 2472 | - { |
|
| 2473 | - // set default registration settings |
|
| 2474 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2475 | - $this->email_validation_level = 'wp_default'; |
|
| 2476 | - $this->show_pending_payment_options = true; |
|
| 2477 | - $this->skip_reg_confirmation = false; |
|
| 2478 | - $this->reg_steps = array(); |
|
| 2479 | - $this->reg_confirmation_last = false; |
|
| 2480 | - $this->use_bot_trap = true; |
|
| 2481 | - $this->use_encryption = true; |
|
| 2482 | - $this->use_captcha = false; |
|
| 2483 | - $this->recaptcha_theme = 'light'; |
|
| 2484 | - $this->recaptcha_type = 'image'; |
|
| 2485 | - $this->recaptcha_language = 'en'; |
|
| 2486 | - $this->recaptcha_publickey = null; |
|
| 2487 | - $this->recaptcha_privatekey = null; |
|
| 2488 | - $this->recaptcha_width = 500; |
|
| 2489 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2490 | - } |
|
| 2491 | - |
|
| 2492 | - |
|
| 2493 | - |
|
| 2494 | - /** |
|
| 2495 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2496 | - * |
|
| 2497 | - * @since 4.8.8.rc.019 |
|
| 2498 | - */ |
|
| 2499 | - public function do_hooks() |
|
| 2500 | - { |
|
| 2501 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2502 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2503 | - } |
|
| 2504 | 2045 | |
| 2046 | +/** |
|
| 2047 | + * Config class for storing info on the Organization |
|
| 2048 | + */ |
|
| 2049 | +class EE_Organization_Config extends EE_Config_Base |
|
| 2050 | +{ |
|
| 2505 | 2051 | |
| 2052 | + /** |
|
| 2053 | + * @var string $name |
|
| 2054 | + * eg EE4.1 |
|
| 2055 | + */ |
|
| 2056 | + public $name; |
|
| 2057 | + |
|
| 2058 | + /** |
|
| 2059 | + * @var string $address_1 |
|
| 2060 | + * eg 123 Onna Road |
|
| 2061 | + */ |
|
| 2062 | + public $address_1; |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * @var string $address_2 |
|
| 2066 | + * eg PO Box 123 |
|
| 2067 | + */ |
|
| 2068 | + public $address_2; |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * @var string $city |
|
| 2072 | + * eg Inna City |
|
| 2073 | + */ |
|
| 2074 | + public $city; |
|
| 2075 | + |
|
| 2076 | + /** |
|
| 2077 | + * @var int $STA_ID |
|
| 2078 | + * eg 4 |
|
| 2079 | + */ |
|
| 2080 | + public $STA_ID; |
|
| 2081 | + |
|
| 2082 | + /** |
|
| 2083 | + * @var string $CNT_ISO |
|
| 2084 | + * eg US |
|
| 2085 | + */ |
|
| 2086 | + public $CNT_ISO; |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * @var string $zip |
|
| 2090 | + * eg 12345 or V1A 2B3 |
|
| 2091 | + */ |
|
| 2092 | + public $zip; |
|
| 2093 | + |
|
| 2094 | + /** |
|
| 2095 | + * @var string $email |
|
| 2096 | + * eg [email protected] |
|
| 2097 | + */ |
|
| 2098 | + public $email; |
|
| 2099 | + |
|
| 2100 | + |
|
| 2101 | + /** |
|
| 2102 | + * @var string $phone |
|
| 2103 | + * eg. 111-111-1111 |
|
| 2104 | + */ |
|
| 2105 | + public $phone; |
|
| 2106 | + |
|
| 2107 | + |
|
| 2108 | + /** |
|
| 2109 | + * @var string $vat |
|
| 2110 | + * VAT/Tax Number |
|
| 2111 | + */ |
|
| 2112 | + public $vat; |
|
| 2113 | + |
|
| 2114 | + /** |
|
| 2115 | + * @var string $logo_url |
|
| 2116 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2117 | + */ |
|
| 2118 | + public $logo_url; |
|
| 2119 | + |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2123 | + * |
|
| 2124 | + * @var string |
|
| 2125 | + */ |
|
| 2126 | + /** |
|
| 2127 | + * facebook (facebook.com/profile.name) |
|
| 2128 | + * |
|
| 2129 | + * @var string |
|
| 2130 | + */ |
|
| 2131 | + public $facebook; |
|
| 2132 | + |
|
| 2133 | + |
|
| 2134 | + /** |
|
| 2135 | + * twitter (twitter.com/twitter_handle) |
|
| 2136 | + * |
|
| 2137 | + * @var string |
|
| 2138 | + */ |
|
| 2139 | + public $twitter; |
|
| 2140 | + |
|
| 2141 | + |
|
| 2142 | + /** |
|
| 2143 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2144 | + * |
|
| 2145 | + * @var string |
|
| 2146 | + */ |
|
| 2147 | + public $linkedin; |
|
| 2148 | + |
|
| 2149 | + |
|
| 2150 | + /** |
|
| 2151 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2152 | + * |
|
| 2153 | + * @var string |
|
| 2154 | + */ |
|
| 2155 | + public $pinterest; |
|
| 2156 | + |
|
| 2157 | + |
|
| 2158 | + /** |
|
| 2159 | + * google+ (google.com/+profileName) |
|
| 2160 | + * |
|
| 2161 | + * @var string |
|
| 2162 | + */ |
|
| 2163 | + public $google; |
|
| 2164 | + |
|
| 2165 | + |
|
| 2166 | + /** |
|
| 2167 | + * instagram (instagram.com/handle) |
|
| 2168 | + * |
|
| 2169 | + * @var string |
|
| 2170 | + */ |
|
| 2171 | + public $instagram; |
|
| 2172 | + |
|
| 2173 | + |
|
| 2174 | + |
|
| 2175 | + /** |
|
| 2176 | + * class constructor |
|
| 2177 | + * |
|
| 2178 | + * @access public |
|
| 2179 | + */ |
|
| 2180 | + public function __construct() |
|
| 2181 | + { |
|
| 2182 | + // set default organization settings |
|
| 2183 | + $this->name = get_bloginfo('name'); |
|
| 2184 | + $this->address_1 = '123 Onna Road'; |
|
| 2185 | + $this->address_2 = 'PO Box 123'; |
|
| 2186 | + $this->city = 'Inna City'; |
|
| 2187 | + $this->STA_ID = 4; |
|
| 2188 | + $this->CNT_ISO = 'US'; |
|
| 2189 | + $this->zip = '12345'; |
|
| 2190 | + $this->email = get_bloginfo('admin_email'); |
|
| 2191 | + $this->phone = ''; |
|
| 2192 | + $this->vat = '123456789'; |
|
| 2193 | + $this->logo_url = ''; |
|
| 2194 | + $this->facebook = ''; |
|
| 2195 | + $this->twitter = ''; |
|
| 2196 | + $this->linkedin = ''; |
|
| 2197 | + $this->pinterest = ''; |
|
| 2198 | + $this->google = ''; |
|
| 2199 | + $this->instagram = ''; |
|
| 2200 | + } |
|
| 2506 | 2201 | |
| 2507 | - /** |
|
| 2508 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2509 | - * field matches the config setting for default_STS_ID. |
|
| 2510 | - */ |
|
| 2511 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2512 | - { |
|
| 2513 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2514 | - } |
|
| 2202 | +} |
|
| 2515 | 2203 | |
| 2516 | 2204 | |
| 2517 | - /** |
|
| 2518 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2519 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2520 | - */ |
|
| 2521 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2522 | - { |
|
| 2523 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2524 | - } |
|
| 2525 | 2205 | |
| 2206 | +/** |
|
| 2207 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2208 | + */ |
|
| 2209 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2210 | +{ |
|
| 2526 | 2211 | |
| 2212 | + /** |
|
| 2213 | + * @var string $code |
|
| 2214 | + * eg 'US' |
|
| 2215 | + */ |
|
| 2216 | + public $code; |
|
| 2217 | + |
|
| 2218 | + /** |
|
| 2219 | + * @var string $name |
|
| 2220 | + * eg 'Dollar' |
|
| 2221 | + */ |
|
| 2222 | + public $name; |
|
| 2223 | + |
|
| 2224 | + /** |
|
| 2225 | + * plural name |
|
| 2226 | + * |
|
| 2227 | + * @var string $plural |
|
| 2228 | + * eg 'Dollars' |
|
| 2229 | + */ |
|
| 2230 | + public $plural; |
|
| 2231 | + |
|
| 2232 | + /** |
|
| 2233 | + * currency sign |
|
| 2234 | + * |
|
| 2235 | + * @var string $sign |
|
| 2236 | + * eg '$' |
|
| 2237 | + */ |
|
| 2238 | + public $sign; |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * Whether the currency sign should come before the number or not |
|
| 2242 | + * |
|
| 2243 | + * @var boolean $sign_b4 |
|
| 2244 | + */ |
|
| 2245 | + public $sign_b4; |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * How many digits should come after the decimal place |
|
| 2249 | + * |
|
| 2250 | + * @var int $dec_plc |
|
| 2251 | + */ |
|
| 2252 | + public $dec_plc; |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * Symbol to use for decimal mark |
|
| 2256 | + * |
|
| 2257 | + * @var string $dec_mrk |
|
| 2258 | + * eg '.' |
|
| 2259 | + */ |
|
| 2260 | + public $dec_mrk; |
|
| 2261 | + |
|
| 2262 | + /** |
|
| 2263 | + * Symbol to use for thousands |
|
| 2264 | + * |
|
| 2265 | + * @var string $thsnds |
|
| 2266 | + * eg ',' |
|
| 2267 | + */ |
|
| 2268 | + public $thsnds; |
|
| 2269 | + |
|
| 2270 | + |
|
| 2271 | + |
|
| 2272 | + /** |
|
| 2273 | + * class constructor |
|
| 2274 | + * |
|
| 2275 | + * @access public |
|
| 2276 | + * @param string $CNT_ISO |
|
| 2277 | + * @throws \EE_Error |
|
| 2278 | + */ |
|
| 2279 | + public function __construct($CNT_ISO = '') |
|
| 2280 | + { |
|
| 2281 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2282 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2283 | + // get country code from organization settings or use default |
|
| 2284 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2285 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2286 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2287 | + : ''; |
|
| 2288 | + // but override if requested |
|
| 2289 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2290 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2291 | + if ( |
|
| 2292 | + ! empty($CNT_ISO) |
|
| 2293 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2294 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2295 | + ) { |
|
| 2296 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2297 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2298 | + if ($country instanceof EE_Country) { |
|
| 2299 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2300 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2301 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2302 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2303 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2304 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2305 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2306 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2307 | + } |
|
| 2308 | + } |
|
| 2309 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2310 | + if (empty($this->code)) { |
|
| 2311 | + // set default currency settings |
|
| 2312 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2313 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2314 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2315 | + $this->sign = '$'; // currency sign: $ |
|
| 2316 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2317 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2318 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2319 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2320 | + } |
|
| 2321 | + } |
|
| 2322 | +} |
|
| 2527 | 2323 | |
| 2528 | - /** |
|
| 2529 | - * @return boolean |
|
| 2530 | - */ |
|
| 2531 | - public function track_invalid_checkout_access() |
|
| 2532 | - { |
|
| 2533 | - return $this->track_invalid_checkout_access; |
|
| 2534 | - } |
|
| 2535 | 2324 | |
| 2536 | 2325 | |
| 2326 | +/** |
|
| 2327 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2328 | + */ |
|
| 2329 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2330 | +{ |
|
| 2537 | 2331 | |
| 2538 | - /** |
|
| 2539 | - * @param boolean $track_invalid_checkout_access |
|
| 2540 | - */ |
|
| 2541 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2542 | - { |
|
| 2543 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2544 | - $track_invalid_checkout_access, |
|
| 2545 | - FILTER_VALIDATE_BOOLEAN |
|
| 2546 | - ); |
|
| 2547 | - } |
|
| 2332 | + /** |
|
| 2333 | + * Default registration status |
|
| 2334 | + * |
|
| 2335 | + * @var string $default_STS_ID |
|
| 2336 | + * eg 'RPP' |
|
| 2337 | + */ |
|
| 2338 | + public $default_STS_ID; |
|
| 2339 | + |
|
| 2340 | + |
|
| 2341 | + /** |
|
| 2342 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2343 | + * registrations) |
|
| 2344 | + * @var int |
|
| 2345 | + */ |
|
| 2346 | + public $default_maximum_number_of_tickets; |
|
| 2347 | + |
|
| 2348 | + |
|
| 2349 | + /** |
|
| 2350 | + * level of validation to apply to email addresses |
|
| 2351 | + * |
|
| 2352 | + * @var string $email_validation_level |
|
| 2353 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2354 | + */ |
|
| 2355 | + public $email_validation_level; |
|
| 2356 | + |
|
| 2357 | + /** |
|
| 2358 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2359 | + * |
|
| 2360 | + * @var boolean $show_pending_payment_options |
|
| 2361 | + */ |
|
| 2362 | + public $show_pending_payment_options; |
|
| 2363 | + |
|
| 2364 | + /** |
|
| 2365 | + * Whether to skip the registration confirmation page |
|
| 2366 | + * |
|
| 2367 | + * @var boolean $skip_reg_confirmation |
|
| 2368 | + */ |
|
| 2369 | + public $skip_reg_confirmation; |
|
| 2370 | + |
|
| 2371 | + /** |
|
| 2372 | + * an array of SPCO reg steps where: |
|
| 2373 | + * the keys denotes the reg step order |
|
| 2374 | + * each element consists of an array with the following elements: |
|
| 2375 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2376 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2377 | + * "slug" => the URL param used to trigger the reg step |
|
| 2378 | + * |
|
| 2379 | + * @var array $reg_steps |
|
| 2380 | + */ |
|
| 2381 | + public $reg_steps; |
|
| 2382 | + |
|
| 2383 | + /** |
|
| 2384 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2385 | + * |
|
| 2386 | + * @var boolean $reg_confirmation_last |
|
| 2387 | + */ |
|
| 2388 | + public $reg_confirmation_last; |
|
| 2389 | + |
|
| 2390 | + /** |
|
| 2391 | + * Whether or not to enable the EE Bot Trap |
|
| 2392 | + * |
|
| 2393 | + * @var boolean $use_bot_trap |
|
| 2394 | + */ |
|
| 2395 | + public $use_bot_trap; |
|
| 2396 | + |
|
| 2397 | + /** |
|
| 2398 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2399 | + * |
|
| 2400 | + * @var boolean $use_encryption |
|
| 2401 | + */ |
|
| 2402 | + public $use_encryption; |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * Whether or not to use ReCaptcha |
|
| 2406 | + * |
|
| 2407 | + * @var boolean $use_captcha |
|
| 2408 | + */ |
|
| 2409 | + public $use_captcha; |
|
| 2410 | + |
|
| 2411 | + /** |
|
| 2412 | + * ReCaptcha Theme |
|
| 2413 | + * |
|
| 2414 | + * @var string $recaptcha_theme |
|
| 2415 | + * options: 'dark ', 'light' |
|
| 2416 | + */ |
|
| 2417 | + public $recaptcha_theme; |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * ReCaptcha Type |
|
| 2421 | + * |
|
| 2422 | + * @var string $recaptcha_type |
|
| 2423 | + * options: 'audio', 'image' |
|
| 2424 | + */ |
|
| 2425 | + public $recaptcha_type; |
|
| 2426 | + |
|
| 2427 | + /** |
|
| 2428 | + * ReCaptcha language |
|
| 2429 | + * |
|
| 2430 | + * @var string $recaptcha_language |
|
| 2431 | + * eg 'en' |
|
| 2432 | + */ |
|
| 2433 | + public $recaptcha_language; |
|
| 2434 | + |
|
| 2435 | + /** |
|
| 2436 | + * ReCaptcha public key |
|
| 2437 | + * |
|
| 2438 | + * @var string $recaptcha_publickey |
|
| 2439 | + */ |
|
| 2440 | + public $recaptcha_publickey; |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * ReCaptcha private key |
|
| 2444 | + * |
|
| 2445 | + * @var string $recaptcha_privatekey |
|
| 2446 | + */ |
|
| 2447 | + public $recaptcha_privatekey; |
|
| 2448 | + |
|
| 2449 | + /** |
|
| 2450 | + * ReCaptcha width |
|
| 2451 | + * |
|
| 2452 | + * @var int $recaptcha_width |
|
| 2453 | + * @deprecated |
|
| 2454 | + */ |
|
| 2455 | + public $recaptcha_width; |
|
| 2456 | + |
|
| 2457 | + /** |
|
| 2458 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2459 | + * |
|
| 2460 | + * @var boolean $track_invalid_checkout_access |
|
| 2461 | + */ |
|
| 2462 | + protected $track_invalid_checkout_access = true; |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + |
|
| 2466 | + /** |
|
| 2467 | + * class constructor |
|
| 2468 | + * |
|
| 2469 | + * @access public |
|
| 2470 | + */ |
|
| 2471 | + public function __construct() |
|
| 2472 | + { |
|
| 2473 | + // set default registration settings |
|
| 2474 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2475 | + $this->email_validation_level = 'wp_default'; |
|
| 2476 | + $this->show_pending_payment_options = true; |
|
| 2477 | + $this->skip_reg_confirmation = false; |
|
| 2478 | + $this->reg_steps = array(); |
|
| 2479 | + $this->reg_confirmation_last = false; |
|
| 2480 | + $this->use_bot_trap = true; |
|
| 2481 | + $this->use_encryption = true; |
|
| 2482 | + $this->use_captcha = false; |
|
| 2483 | + $this->recaptcha_theme = 'light'; |
|
| 2484 | + $this->recaptcha_type = 'image'; |
|
| 2485 | + $this->recaptcha_language = 'en'; |
|
| 2486 | + $this->recaptcha_publickey = null; |
|
| 2487 | + $this->recaptcha_privatekey = null; |
|
| 2488 | + $this->recaptcha_width = 500; |
|
| 2489 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + |
|
| 2493 | + |
|
| 2494 | + /** |
|
| 2495 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2496 | + * |
|
| 2497 | + * @since 4.8.8.rc.019 |
|
| 2498 | + */ |
|
| 2499 | + public function do_hooks() |
|
| 2500 | + { |
|
| 2501 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2502 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2503 | + } |
|
| 2504 | + |
|
| 2505 | + |
|
| 2506 | + |
|
| 2507 | + /** |
|
| 2508 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2509 | + * field matches the config setting for default_STS_ID. |
|
| 2510 | + */ |
|
| 2511 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2512 | + { |
|
| 2513 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2514 | + } |
|
| 2515 | + |
|
| 2516 | + |
|
| 2517 | + /** |
|
| 2518 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2519 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2520 | + */ |
|
| 2521 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2522 | + { |
|
| 2523 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2524 | + } |
|
| 2525 | + |
|
| 2526 | + |
|
| 2527 | + |
|
| 2528 | + /** |
|
| 2529 | + * @return boolean |
|
| 2530 | + */ |
|
| 2531 | + public function track_invalid_checkout_access() |
|
| 2532 | + { |
|
| 2533 | + return $this->track_invalid_checkout_access; |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * @param boolean $track_invalid_checkout_access |
|
| 2540 | + */ |
|
| 2541 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2542 | + { |
|
| 2543 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2544 | + $track_invalid_checkout_access, |
|
| 2545 | + FILTER_VALIDATE_BOOLEAN |
|
| 2546 | + ); |
|
| 2547 | + } |
|
| 2548 | 2548 | |
| 2549 | 2549 | |
| 2550 | 2550 | } |
@@ -2557,160 +2557,160 @@ discard block |
||
| 2557 | 2557 | class EE_Admin_Config extends EE_Config_Base |
| 2558 | 2558 | { |
| 2559 | 2559 | |
| 2560 | - /** |
|
| 2561 | - * @var boolean $use_personnel_manager |
|
| 2562 | - */ |
|
| 2563 | - public $use_personnel_manager; |
|
| 2564 | - |
|
| 2565 | - /** |
|
| 2566 | - * @var boolean $use_dashboard_widget |
|
| 2567 | - */ |
|
| 2568 | - public $use_dashboard_widget; |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * @var int $events_in_dashboard |
|
| 2572 | - */ |
|
| 2573 | - public $events_in_dashboard; |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * @var boolean $use_event_timezones |
|
| 2577 | - */ |
|
| 2578 | - public $use_event_timezones; |
|
| 2579 | - |
|
| 2580 | - /** |
|
| 2581 | - * @var boolean $use_full_logging |
|
| 2582 | - */ |
|
| 2583 | - public $use_full_logging; |
|
| 2584 | - |
|
| 2585 | - /** |
|
| 2586 | - * @var string $log_file_name |
|
| 2587 | - */ |
|
| 2588 | - public $log_file_name; |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * @var string $debug_file_name |
|
| 2592 | - */ |
|
| 2593 | - public $debug_file_name; |
|
| 2594 | - |
|
| 2595 | - /** |
|
| 2596 | - * @var boolean $use_remote_logging |
|
| 2597 | - */ |
|
| 2598 | - public $use_remote_logging; |
|
| 2599 | - |
|
| 2600 | - /** |
|
| 2601 | - * @var string $remote_logging_url |
|
| 2602 | - */ |
|
| 2603 | - public $remote_logging_url; |
|
| 2604 | - |
|
| 2605 | - /** |
|
| 2606 | - * @var boolean $show_reg_footer |
|
| 2607 | - */ |
|
| 2608 | - public $show_reg_footer; |
|
| 2609 | - |
|
| 2610 | - /** |
|
| 2611 | - * @var string $affiliate_id |
|
| 2612 | - */ |
|
| 2613 | - public $affiliate_id; |
|
| 2614 | - |
|
| 2615 | - /** |
|
| 2616 | - * help tours on or off (global setting) |
|
| 2617 | - * |
|
| 2618 | - * @var boolean |
|
| 2619 | - */ |
|
| 2620 | - public $help_tour_activation; |
|
| 2621 | - |
|
| 2622 | - /** |
|
| 2623 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2624 | - * but is incompatible with some server configuration errors |
|
| 2625 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2626 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2627 | - * |
|
| 2628 | - * @var boolean $encode_session_data |
|
| 2629 | - */ |
|
| 2630 | - private $encode_session_data = false; |
|
| 2631 | - |
|
| 2632 | - |
|
| 2633 | - |
|
| 2634 | - /** |
|
| 2635 | - * class constructor |
|
| 2636 | - * |
|
| 2637 | - * @access public |
|
| 2638 | - */ |
|
| 2639 | - public function __construct() |
|
| 2640 | - { |
|
| 2641 | - // set default general admin settings |
|
| 2642 | - $this->use_personnel_manager = true; |
|
| 2643 | - $this->use_dashboard_widget = true; |
|
| 2644 | - $this->events_in_dashboard = 30; |
|
| 2645 | - $this->use_event_timezones = false; |
|
| 2646 | - $this->use_full_logging = false; |
|
| 2647 | - $this->use_remote_logging = false; |
|
| 2648 | - $this->remote_logging_url = null; |
|
| 2649 | - $this->show_reg_footer = true; |
|
| 2650 | - $this->affiliate_id = 'default'; |
|
| 2651 | - $this->help_tour_activation = true; |
|
| 2652 | - $this->encode_session_data = false; |
|
| 2653 | - } |
|
| 2654 | - |
|
| 2655 | - |
|
| 2656 | - |
|
| 2657 | - /** |
|
| 2658 | - * @param bool $reset |
|
| 2659 | - * @return string |
|
| 2660 | - */ |
|
| 2661 | - public function log_file_name($reset = false) |
|
| 2662 | - { |
|
| 2663 | - if (empty($this->log_file_name) || $reset) { |
|
| 2664 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2665 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2666 | - } |
|
| 2667 | - return $this->log_file_name; |
|
| 2668 | - } |
|
| 2669 | - |
|
| 2670 | - |
|
| 2671 | - |
|
| 2672 | - /** |
|
| 2673 | - * @param bool $reset |
|
| 2674 | - * @return string |
|
| 2675 | - */ |
|
| 2676 | - public function debug_file_name($reset = false) |
|
| 2677 | - { |
|
| 2678 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2679 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2680 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2681 | - } |
|
| 2682 | - return $this->debug_file_name; |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - |
|
| 2686 | - |
|
| 2687 | - /** |
|
| 2688 | - * @return string |
|
| 2689 | - */ |
|
| 2690 | - public function affiliate_id() |
|
| 2691 | - { |
|
| 2692 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2693 | - } |
|
| 2694 | - |
|
| 2695 | - |
|
| 2696 | - |
|
| 2697 | - /** |
|
| 2698 | - * @return boolean |
|
| 2699 | - */ |
|
| 2700 | - public function encode_session_data() |
|
| 2701 | - { |
|
| 2702 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2703 | - } |
|
| 2704 | - |
|
| 2705 | - |
|
| 2706 | - |
|
| 2707 | - /** |
|
| 2708 | - * @param boolean $encode_session_data |
|
| 2709 | - */ |
|
| 2710 | - public function set_encode_session_data($encode_session_data) |
|
| 2711 | - { |
|
| 2712 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2713 | - } |
|
| 2560 | + /** |
|
| 2561 | + * @var boolean $use_personnel_manager |
|
| 2562 | + */ |
|
| 2563 | + public $use_personnel_manager; |
|
| 2564 | + |
|
| 2565 | + /** |
|
| 2566 | + * @var boolean $use_dashboard_widget |
|
| 2567 | + */ |
|
| 2568 | + public $use_dashboard_widget; |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * @var int $events_in_dashboard |
|
| 2572 | + */ |
|
| 2573 | + public $events_in_dashboard; |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * @var boolean $use_event_timezones |
|
| 2577 | + */ |
|
| 2578 | + public $use_event_timezones; |
|
| 2579 | + |
|
| 2580 | + /** |
|
| 2581 | + * @var boolean $use_full_logging |
|
| 2582 | + */ |
|
| 2583 | + public $use_full_logging; |
|
| 2584 | + |
|
| 2585 | + /** |
|
| 2586 | + * @var string $log_file_name |
|
| 2587 | + */ |
|
| 2588 | + public $log_file_name; |
|
| 2589 | + |
|
| 2590 | + /** |
|
| 2591 | + * @var string $debug_file_name |
|
| 2592 | + */ |
|
| 2593 | + public $debug_file_name; |
|
| 2594 | + |
|
| 2595 | + /** |
|
| 2596 | + * @var boolean $use_remote_logging |
|
| 2597 | + */ |
|
| 2598 | + public $use_remote_logging; |
|
| 2599 | + |
|
| 2600 | + /** |
|
| 2601 | + * @var string $remote_logging_url |
|
| 2602 | + */ |
|
| 2603 | + public $remote_logging_url; |
|
| 2604 | + |
|
| 2605 | + /** |
|
| 2606 | + * @var boolean $show_reg_footer |
|
| 2607 | + */ |
|
| 2608 | + public $show_reg_footer; |
|
| 2609 | + |
|
| 2610 | + /** |
|
| 2611 | + * @var string $affiliate_id |
|
| 2612 | + */ |
|
| 2613 | + public $affiliate_id; |
|
| 2614 | + |
|
| 2615 | + /** |
|
| 2616 | + * help tours on or off (global setting) |
|
| 2617 | + * |
|
| 2618 | + * @var boolean |
|
| 2619 | + */ |
|
| 2620 | + public $help_tour_activation; |
|
| 2621 | + |
|
| 2622 | + /** |
|
| 2623 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2624 | + * but is incompatible with some server configuration errors |
|
| 2625 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2626 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2627 | + * |
|
| 2628 | + * @var boolean $encode_session_data |
|
| 2629 | + */ |
|
| 2630 | + private $encode_session_data = false; |
|
| 2631 | + |
|
| 2632 | + |
|
| 2633 | + |
|
| 2634 | + /** |
|
| 2635 | + * class constructor |
|
| 2636 | + * |
|
| 2637 | + * @access public |
|
| 2638 | + */ |
|
| 2639 | + public function __construct() |
|
| 2640 | + { |
|
| 2641 | + // set default general admin settings |
|
| 2642 | + $this->use_personnel_manager = true; |
|
| 2643 | + $this->use_dashboard_widget = true; |
|
| 2644 | + $this->events_in_dashboard = 30; |
|
| 2645 | + $this->use_event_timezones = false; |
|
| 2646 | + $this->use_full_logging = false; |
|
| 2647 | + $this->use_remote_logging = false; |
|
| 2648 | + $this->remote_logging_url = null; |
|
| 2649 | + $this->show_reg_footer = true; |
|
| 2650 | + $this->affiliate_id = 'default'; |
|
| 2651 | + $this->help_tour_activation = true; |
|
| 2652 | + $this->encode_session_data = false; |
|
| 2653 | + } |
|
| 2654 | + |
|
| 2655 | + |
|
| 2656 | + |
|
| 2657 | + /** |
|
| 2658 | + * @param bool $reset |
|
| 2659 | + * @return string |
|
| 2660 | + */ |
|
| 2661 | + public function log_file_name($reset = false) |
|
| 2662 | + { |
|
| 2663 | + if (empty($this->log_file_name) || $reset) { |
|
| 2664 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2665 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2666 | + } |
|
| 2667 | + return $this->log_file_name; |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + |
|
| 2671 | + |
|
| 2672 | + /** |
|
| 2673 | + * @param bool $reset |
|
| 2674 | + * @return string |
|
| 2675 | + */ |
|
| 2676 | + public function debug_file_name($reset = false) |
|
| 2677 | + { |
|
| 2678 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2679 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2680 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2681 | + } |
|
| 2682 | + return $this->debug_file_name; |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + |
|
| 2686 | + |
|
| 2687 | + /** |
|
| 2688 | + * @return string |
|
| 2689 | + */ |
|
| 2690 | + public function affiliate_id() |
|
| 2691 | + { |
|
| 2692 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2693 | + } |
|
| 2694 | + |
|
| 2695 | + |
|
| 2696 | + |
|
| 2697 | + /** |
|
| 2698 | + * @return boolean |
|
| 2699 | + */ |
|
| 2700 | + public function encode_session_data() |
|
| 2701 | + { |
|
| 2702 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2703 | + } |
|
| 2704 | + |
|
| 2705 | + |
|
| 2706 | + |
|
| 2707 | + /** |
|
| 2708 | + * @param boolean $encode_session_data |
|
| 2709 | + */ |
|
| 2710 | + public function set_encode_session_data($encode_session_data) |
|
| 2711 | + { |
|
| 2712 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2713 | + } |
|
| 2714 | 2714 | |
| 2715 | 2715 | |
| 2716 | 2716 | } |
@@ -2723,71 +2723,71 @@ discard block |
||
| 2723 | 2723 | class EE_Template_Config extends EE_Config_Base |
| 2724 | 2724 | { |
| 2725 | 2725 | |
| 2726 | - /** |
|
| 2727 | - * @var boolean $enable_default_style |
|
| 2728 | - */ |
|
| 2729 | - public $enable_default_style; |
|
| 2730 | - |
|
| 2731 | - /** |
|
| 2732 | - * @var string $custom_style_sheet |
|
| 2733 | - */ |
|
| 2734 | - public $custom_style_sheet; |
|
| 2735 | - |
|
| 2736 | - /** |
|
| 2737 | - * @var boolean $display_address_in_regform |
|
| 2738 | - */ |
|
| 2739 | - public $display_address_in_regform; |
|
| 2740 | - |
|
| 2741 | - /** |
|
| 2742 | - * @var int $display_description_on_multi_reg_page |
|
| 2743 | - */ |
|
| 2744 | - public $display_description_on_multi_reg_page; |
|
| 2745 | - |
|
| 2746 | - /** |
|
| 2747 | - * @var boolean $use_custom_templates |
|
| 2748 | - */ |
|
| 2749 | - public $use_custom_templates; |
|
| 2750 | - |
|
| 2751 | - /** |
|
| 2752 | - * @var string $current_espresso_theme |
|
| 2753 | - */ |
|
| 2754 | - public $current_espresso_theme; |
|
| 2755 | - |
|
| 2756 | - /** |
|
| 2757 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2758 | - */ |
|
| 2759 | - public $EED_Ticket_Selector; |
|
| 2760 | - |
|
| 2761 | - /** |
|
| 2762 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2763 | - */ |
|
| 2764 | - public $EED_Event_Single; |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2768 | - */ |
|
| 2769 | - public $EED_Events_Archive; |
|
| 2770 | - |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * class constructor |
|
| 2775 | - * |
|
| 2776 | - * @access public |
|
| 2777 | - */ |
|
| 2778 | - public function __construct() |
|
| 2779 | - { |
|
| 2780 | - // set default template settings |
|
| 2781 | - $this->enable_default_style = true; |
|
| 2782 | - $this->custom_style_sheet = null; |
|
| 2783 | - $this->display_address_in_regform = true; |
|
| 2784 | - $this->display_description_on_multi_reg_page = false; |
|
| 2785 | - $this->use_custom_templates = false; |
|
| 2786 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2787 | - $this->EED_Event_Single = null; |
|
| 2788 | - $this->EED_Events_Archive = null; |
|
| 2789 | - $this->EED_Ticket_Selector = null; |
|
| 2790 | - } |
|
| 2726 | + /** |
|
| 2727 | + * @var boolean $enable_default_style |
|
| 2728 | + */ |
|
| 2729 | + public $enable_default_style; |
|
| 2730 | + |
|
| 2731 | + /** |
|
| 2732 | + * @var string $custom_style_sheet |
|
| 2733 | + */ |
|
| 2734 | + public $custom_style_sheet; |
|
| 2735 | + |
|
| 2736 | + /** |
|
| 2737 | + * @var boolean $display_address_in_regform |
|
| 2738 | + */ |
|
| 2739 | + public $display_address_in_regform; |
|
| 2740 | + |
|
| 2741 | + /** |
|
| 2742 | + * @var int $display_description_on_multi_reg_page |
|
| 2743 | + */ |
|
| 2744 | + public $display_description_on_multi_reg_page; |
|
| 2745 | + |
|
| 2746 | + /** |
|
| 2747 | + * @var boolean $use_custom_templates |
|
| 2748 | + */ |
|
| 2749 | + public $use_custom_templates; |
|
| 2750 | + |
|
| 2751 | + /** |
|
| 2752 | + * @var string $current_espresso_theme |
|
| 2753 | + */ |
|
| 2754 | + public $current_espresso_theme; |
|
| 2755 | + |
|
| 2756 | + /** |
|
| 2757 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2758 | + */ |
|
| 2759 | + public $EED_Ticket_Selector; |
|
| 2760 | + |
|
| 2761 | + /** |
|
| 2762 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2763 | + */ |
|
| 2764 | + public $EED_Event_Single; |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2768 | + */ |
|
| 2769 | + public $EED_Events_Archive; |
|
| 2770 | + |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * class constructor |
|
| 2775 | + * |
|
| 2776 | + * @access public |
|
| 2777 | + */ |
|
| 2778 | + public function __construct() |
|
| 2779 | + { |
|
| 2780 | + // set default template settings |
|
| 2781 | + $this->enable_default_style = true; |
|
| 2782 | + $this->custom_style_sheet = null; |
|
| 2783 | + $this->display_address_in_regform = true; |
|
| 2784 | + $this->display_description_on_multi_reg_page = false; |
|
| 2785 | + $this->use_custom_templates = false; |
|
| 2786 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2787 | + $this->EED_Event_Single = null; |
|
| 2788 | + $this->EED_Events_Archive = null; |
|
| 2789 | + $this->EED_Ticket_Selector = null; |
|
| 2790 | + } |
|
| 2791 | 2791 | |
| 2792 | 2792 | } |
| 2793 | 2793 | |
@@ -2799,115 +2799,115 @@ discard block |
||
| 2799 | 2799 | class EE_Map_Config extends EE_Config_Base |
| 2800 | 2800 | { |
| 2801 | 2801 | |
| 2802 | - /** |
|
| 2803 | - * @var boolean $use_google_maps |
|
| 2804 | - */ |
|
| 2805 | - public $use_google_maps; |
|
| 2806 | - |
|
| 2807 | - /** |
|
| 2808 | - * @var string $api_key |
|
| 2809 | - */ |
|
| 2810 | - public $google_map_api_key; |
|
| 2811 | - |
|
| 2812 | - /** |
|
| 2813 | - * @var int $event_details_map_width |
|
| 2814 | - */ |
|
| 2815 | - public $event_details_map_width; |
|
| 2816 | - |
|
| 2817 | - /** |
|
| 2818 | - * @var int $event_details_map_height |
|
| 2819 | - */ |
|
| 2820 | - public $event_details_map_height; |
|
| 2821 | - |
|
| 2822 | - /** |
|
| 2823 | - * @var int $event_details_map_zoom |
|
| 2824 | - */ |
|
| 2825 | - public $event_details_map_zoom; |
|
| 2826 | - |
|
| 2827 | - /** |
|
| 2828 | - * @var boolean $event_details_display_nav |
|
| 2829 | - */ |
|
| 2830 | - public $event_details_display_nav; |
|
| 2831 | - |
|
| 2832 | - /** |
|
| 2833 | - * @var boolean $event_details_nav_size |
|
| 2834 | - */ |
|
| 2835 | - public $event_details_nav_size; |
|
| 2836 | - |
|
| 2837 | - /** |
|
| 2838 | - * @var string $event_details_control_type |
|
| 2839 | - */ |
|
| 2840 | - public $event_details_control_type; |
|
| 2841 | - |
|
| 2842 | - /** |
|
| 2843 | - * @var string $event_details_map_align |
|
| 2844 | - */ |
|
| 2845 | - public $event_details_map_align; |
|
| 2846 | - |
|
| 2847 | - /** |
|
| 2848 | - * @var int $event_list_map_width |
|
| 2849 | - */ |
|
| 2850 | - public $event_list_map_width; |
|
| 2851 | - |
|
| 2852 | - /** |
|
| 2853 | - * @var int $event_list_map_height |
|
| 2854 | - */ |
|
| 2855 | - public $event_list_map_height; |
|
| 2856 | - |
|
| 2857 | - /** |
|
| 2858 | - * @var int $event_list_map_zoom |
|
| 2859 | - */ |
|
| 2860 | - public $event_list_map_zoom; |
|
| 2861 | - |
|
| 2862 | - /** |
|
| 2863 | - * @var boolean $event_list_display_nav |
|
| 2864 | - */ |
|
| 2865 | - public $event_list_display_nav; |
|
| 2866 | - |
|
| 2867 | - /** |
|
| 2868 | - * @var boolean $event_list_nav_size |
|
| 2869 | - */ |
|
| 2870 | - public $event_list_nav_size; |
|
| 2871 | - |
|
| 2872 | - /** |
|
| 2873 | - * @var string $event_list_control_type |
|
| 2874 | - */ |
|
| 2875 | - public $event_list_control_type; |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * @var string $event_list_map_align |
|
| 2879 | - */ |
|
| 2880 | - public $event_list_map_align; |
|
| 2881 | - |
|
| 2882 | - |
|
| 2883 | - |
|
| 2884 | - /** |
|
| 2885 | - * class constructor |
|
| 2886 | - * |
|
| 2887 | - * @access public |
|
| 2888 | - */ |
|
| 2889 | - public function __construct() |
|
| 2890 | - { |
|
| 2891 | - // set default map settings |
|
| 2892 | - $this->use_google_maps = true; |
|
| 2893 | - $this->google_map_api_key = ''; |
|
| 2894 | - // for event details pages (reg page) |
|
| 2895 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2896 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2897 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2898 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2899 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2900 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2901 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2902 | - // for event list pages |
|
| 2903 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2904 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2905 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2906 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2907 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2908 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2909 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2910 | - } |
|
| 2802 | + /** |
|
| 2803 | + * @var boolean $use_google_maps |
|
| 2804 | + */ |
|
| 2805 | + public $use_google_maps; |
|
| 2806 | + |
|
| 2807 | + /** |
|
| 2808 | + * @var string $api_key |
|
| 2809 | + */ |
|
| 2810 | + public $google_map_api_key; |
|
| 2811 | + |
|
| 2812 | + /** |
|
| 2813 | + * @var int $event_details_map_width |
|
| 2814 | + */ |
|
| 2815 | + public $event_details_map_width; |
|
| 2816 | + |
|
| 2817 | + /** |
|
| 2818 | + * @var int $event_details_map_height |
|
| 2819 | + */ |
|
| 2820 | + public $event_details_map_height; |
|
| 2821 | + |
|
| 2822 | + /** |
|
| 2823 | + * @var int $event_details_map_zoom |
|
| 2824 | + */ |
|
| 2825 | + public $event_details_map_zoom; |
|
| 2826 | + |
|
| 2827 | + /** |
|
| 2828 | + * @var boolean $event_details_display_nav |
|
| 2829 | + */ |
|
| 2830 | + public $event_details_display_nav; |
|
| 2831 | + |
|
| 2832 | + /** |
|
| 2833 | + * @var boolean $event_details_nav_size |
|
| 2834 | + */ |
|
| 2835 | + public $event_details_nav_size; |
|
| 2836 | + |
|
| 2837 | + /** |
|
| 2838 | + * @var string $event_details_control_type |
|
| 2839 | + */ |
|
| 2840 | + public $event_details_control_type; |
|
| 2841 | + |
|
| 2842 | + /** |
|
| 2843 | + * @var string $event_details_map_align |
|
| 2844 | + */ |
|
| 2845 | + public $event_details_map_align; |
|
| 2846 | + |
|
| 2847 | + /** |
|
| 2848 | + * @var int $event_list_map_width |
|
| 2849 | + */ |
|
| 2850 | + public $event_list_map_width; |
|
| 2851 | + |
|
| 2852 | + /** |
|
| 2853 | + * @var int $event_list_map_height |
|
| 2854 | + */ |
|
| 2855 | + public $event_list_map_height; |
|
| 2856 | + |
|
| 2857 | + /** |
|
| 2858 | + * @var int $event_list_map_zoom |
|
| 2859 | + */ |
|
| 2860 | + public $event_list_map_zoom; |
|
| 2861 | + |
|
| 2862 | + /** |
|
| 2863 | + * @var boolean $event_list_display_nav |
|
| 2864 | + */ |
|
| 2865 | + public $event_list_display_nav; |
|
| 2866 | + |
|
| 2867 | + /** |
|
| 2868 | + * @var boolean $event_list_nav_size |
|
| 2869 | + */ |
|
| 2870 | + public $event_list_nav_size; |
|
| 2871 | + |
|
| 2872 | + /** |
|
| 2873 | + * @var string $event_list_control_type |
|
| 2874 | + */ |
|
| 2875 | + public $event_list_control_type; |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * @var string $event_list_map_align |
|
| 2879 | + */ |
|
| 2880 | + public $event_list_map_align; |
|
| 2881 | + |
|
| 2882 | + |
|
| 2883 | + |
|
| 2884 | + /** |
|
| 2885 | + * class constructor |
|
| 2886 | + * |
|
| 2887 | + * @access public |
|
| 2888 | + */ |
|
| 2889 | + public function __construct() |
|
| 2890 | + { |
|
| 2891 | + // set default map settings |
|
| 2892 | + $this->use_google_maps = true; |
|
| 2893 | + $this->google_map_api_key = ''; |
|
| 2894 | + // for event details pages (reg page) |
|
| 2895 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2896 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2897 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2898 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2899 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2900 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2901 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2902 | + // for event list pages |
|
| 2903 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2904 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2905 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2906 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2907 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2908 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2909 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2910 | + } |
|
| 2911 | 2911 | |
| 2912 | 2912 | } |
| 2913 | 2913 | |
@@ -2919,47 +2919,47 @@ discard block |
||
| 2919 | 2919 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2920 | 2920 | { |
| 2921 | 2921 | |
| 2922 | - public $display_status_banner; |
|
| 2922 | + public $display_status_banner; |
|
| 2923 | 2923 | |
| 2924 | - public $display_description; |
|
| 2924 | + public $display_description; |
|
| 2925 | 2925 | |
| 2926 | - public $display_ticket_selector; |
|
| 2926 | + public $display_ticket_selector; |
|
| 2927 | 2927 | |
| 2928 | - public $display_datetimes; |
|
| 2928 | + public $display_datetimes; |
|
| 2929 | 2929 | |
| 2930 | - public $display_venue; |
|
| 2930 | + public $display_venue; |
|
| 2931 | 2931 | |
| 2932 | - public $display_expired_events; |
|
| 2932 | + public $display_expired_events; |
|
| 2933 | 2933 | |
| 2934 | - public $use_sortable_display_order; |
|
| 2934 | + public $use_sortable_display_order; |
|
| 2935 | 2935 | |
| 2936 | - public $display_order_tickets; |
|
| 2936 | + public $display_order_tickets; |
|
| 2937 | 2937 | |
| 2938 | - public $display_order_datetimes; |
|
| 2938 | + public $display_order_datetimes; |
|
| 2939 | 2939 | |
| 2940 | - public $display_order_event; |
|
| 2940 | + public $display_order_event; |
|
| 2941 | 2941 | |
| 2942 | - public $display_order_venue; |
|
| 2942 | + public $display_order_venue; |
|
| 2943 | 2943 | |
| 2944 | 2944 | |
| 2945 | 2945 | |
| 2946 | - /** |
|
| 2947 | - * class constructor |
|
| 2948 | - */ |
|
| 2949 | - public function __construct() |
|
| 2950 | - { |
|
| 2951 | - $this->display_status_banner = 0; |
|
| 2952 | - $this->display_description = 1; |
|
| 2953 | - $this->display_ticket_selector = 0; |
|
| 2954 | - $this->display_datetimes = 1; |
|
| 2955 | - $this->display_venue = 0; |
|
| 2956 | - $this->display_expired_events = 0; |
|
| 2957 | - $this->use_sortable_display_order = false; |
|
| 2958 | - $this->display_order_tickets = 100; |
|
| 2959 | - $this->display_order_datetimes = 110; |
|
| 2960 | - $this->display_order_event = 120; |
|
| 2961 | - $this->display_order_venue = 130; |
|
| 2962 | - } |
|
| 2946 | + /** |
|
| 2947 | + * class constructor |
|
| 2948 | + */ |
|
| 2949 | + public function __construct() |
|
| 2950 | + { |
|
| 2951 | + $this->display_status_banner = 0; |
|
| 2952 | + $this->display_description = 1; |
|
| 2953 | + $this->display_ticket_selector = 0; |
|
| 2954 | + $this->display_datetimes = 1; |
|
| 2955 | + $this->display_venue = 0; |
|
| 2956 | + $this->display_expired_events = 0; |
|
| 2957 | + $this->use_sortable_display_order = false; |
|
| 2958 | + $this->display_order_tickets = 100; |
|
| 2959 | + $this->display_order_datetimes = 110; |
|
| 2960 | + $this->display_order_event = 120; |
|
| 2961 | + $this->display_order_venue = 130; |
|
| 2962 | + } |
|
| 2963 | 2963 | } |
| 2964 | 2964 | |
| 2965 | 2965 | |
@@ -2970,35 +2970,35 @@ discard block |
||
| 2970 | 2970 | class EE_Event_Single_Config extends EE_Config_Base |
| 2971 | 2971 | { |
| 2972 | 2972 | |
| 2973 | - public $display_status_banner_single; |
|
| 2973 | + public $display_status_banner_single; |
|
| 2974 | 2974 | |
| 2975 | - public $display_venue; |
|
| 2975 | + public $display_venue; |
|
| 2976 | 2976 | |
| 2977 | - public $use_sortable_display_order; |
|
| 2977 | + public $use_sortable_display_order; |
|
| 2978 | 2978 | |
| 2979 | - public $display_order_tickets; |
|
| 2979 | + public $display_order_tickets; |
|
| 2980 | 2980 | |
| 2981 | - public $display_order_datetimes; |
|
| 2981 | + public $display_order_datetimes; |
|
| 2982 | 2982 | |
| 2983 | - public $display_order_event; |
|
| 2983 | + public $display_order_event; |
|
| 2984 | 2984 | |
| 2985 | - public $display_order_venue; |
|
| 2985 | + public $display_order_venue; |
|
| 2986 | 2986 | |
| 2987 | 2987 | |
| 2988 | 2988 | |
| 2989 | - /** |
|
| 2990 | - * class constructor |
|
| 2991 | - */ |
|
| 2992 | - public function __construct() |
|
| 2993 | - { |
|
| 2994 | - $this->display_status_banner_single = 0; |
|
| 2995 | - $this->display_venue = 1; |
|
| 2996 | - $this->use_sortable_display_order = false; |
|
| 2997 | - $this->display_order_tickets = 100; |
|
| 2998 | - $this->display_order_datetimes = 110; |
|
| 2999 | - $this->display_order_event = 120; |
|
| 3000 | - $this->display_order_venue = 130; |
|
| 3001 | - } |
|
| 2989 | + /** |
|
| 2990 | + * class constructor |
|
| 2991 | + */ |
|
| 2992 | + public function __construct() |
|
| 2993 | + { |
|
| 2994 | + $this->display_status_banner_single = 0; |
|
| 2995 | + $this->display_venue = 1; |
|
| 2996 | + $this->use_sortable_display_order = false; |
|
| 2997 | + $this->display_order_tickets = 100; |
|
| 2998 | + $this->display_order_datetimes = 110; |
|
| 2999 | + $this->display_order_event = 120; |
|
| 3000 | + $this->display_order_venue = 130; |
|
| 3001 | + } |
|
| 3002 | 3002 | } |
| 3003 | 3003 | |
| 3004 | 3004 | |
@@ -3009,151 +3009,151 @@ discard block |
||
| 3009 | 3009 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 3010 | 3010 | { |
| 3011 | 3011 | |
| 3012 | - /** |
|
| 3013 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3014 | - */ |
|
| 3015 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3016 | - |
|
| 3017 | - /** |
|
| 3018 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3019 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3020 | - */ |
|
| 3021 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3022 | - |
|
| 3023 | - /** |
|
| 3024 | - * @var boolean $show_ticket_sale_columns |
|
| 3025 | - */ |
|
| 3026 | - public $show_ticket_sale_columns; |
|
| 3027 | - |
|
| 3028 | - /** |
|
| 3029 | - * @var boolean $show_ticket_details |
|
| 3030 | - */ |
|
| 3031 | - public $show_ticket_details; |
|
| 3032 | - |
|
| 3033 | - /** |
|
| 3034 | - * @var boolean $show_expired_tickets |
|
| 3035 | - */ |
|
| 3036 | - public $show_expired_tickets; |
|
| 3037 | - |
|
| 3038 | - /** |
|
| 3039 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 3040 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3041 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3042 | - * |
|
| 3043 | - * @var string $show_datetime_selector |
|
| 3044 | - */ |
|
| 3045 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3046 | - |
|
| 3047 | - /** |
|
| 3048 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3049 | - * |
|
| 3050 | - * @var int $datetime_selector_threshold |
|
| 3051 | - */ |
|
| 3052 | - private $datetime_selector_threshold = 3; |
|
| 3053 | - |
|
| 3054 | - |
|
| 3055 | - |
|
| 3056 | - /** |
|
| 3057 | - * class constructor |
|
| 3058 | - */ |
|
| 3059 | - public function __construct() |
|
| 3060 | - { |
|
| 3061 | - $this->show_ticket_sale_columns = true; |
|
| 3062 | - $this->show_ticket_details = true; |
|
| 3063 | - $this->show_expired_tickets = true; |
|
| 3064 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3065 | - $this->datetime_selector_threshold = 3; |
|
| 3066 | - } |
|
| 3067 | - |
|
| 3068 | - |
|
| 3069 | - |
|
| 3070 | - /** |
|
| 3071 | - * returns true if a datetime selector should be displayed |
|
| 3072 | - * |
|
| 3073 | - * @param array $datetimes |
|
| 3074 | - * @return bool |
|
| 3075 | - */ |
|
| 3076 | - public function showDatetimeSelector(array $datetimes) |
|
| 3077 | - { |
|
| 3078 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3079 | - return ! ( |
|
| 3080 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3081 | - || ( |
|
| 3082 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3083 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3084 | - ) |
|
| 3085 | - ); |
|
| 3086 | - } |
|
| 3087 | - |
|
| 3088 | - |
|
| 3089 | - |
|
| 3090 | - /** |
|
| 3091 | - * @return string |
|
| 3092 | - */ |
|
| 3093 | - public function getShowDatetimeSelector() |
|
| 3094 | - { |
|
| 3095 | - return $this->show_datetime_selector; |
|
| 3096 | - } |
|
| 3097 | - |
|
| 3098 | - |
|
| 3099 | - |
|
| 3100 | - /** |
|
| 3101 | - * @param bool $keys_only |
|
| 3102 | - * @return array |
|
| 3103 | - */ |
|
| 3104 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3105 | - { |
|
| 3106 | - return $keys_only |
|
| 3107 | - ? array( |
|
| 3108 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3109 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3110 | - ) |
|
| 3111 | - : array( |
|
| 3112 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3113 | - 'Do not show date & time filter', 'event_espresso' |
|
| 3114 | - ), |
|
| 3115 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3116 | - 'Maybe show date & time filter', 'event_espresso' |
|
| 3117 | - ), |
|
| 3118 | - ); |
|
| 3119 | - } |
|
| 3120 | - |
|
| 3121 | - |
|
| 3122 | - |
|
| 3123 | - /** |
|
| 3124 | - * @param string $show_datetime_selector |
|
| 3125 | - */ |
|
| 3126 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3127 | - { |
|
| 3128 | - $this->show_datetime_selector = in_array( |
|
| 3129 | - $show_datetime_selector, |
|
| 3130 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3131 | - true |
|
| 3132 | - ) |
|
| 3133 | - ? $show_datetime_selector |
|
| 3134 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3135 | - } |
|
| 3136 | - |
|
| 3137 | - |
|
| 3138 | - |
|
| 3139 | - /** |
|
| 3140 | - * @return int |
|
| 3141 | - */ |
|
| 3142 | - public function getDatetimeSelectorThreshold() |
|
| 3143 | - { |
|
| 3144 | - return $this->datetime_selector_threshold; |
|
| 3145 | - } |
|
| 3146 | - |
|
| 3147 | - |
|
| 3148 | - |
|
| 3149 | - /** |
|
| 3150 | - * @param int $datetime_selector_threshold |
|
| 3151 | - */ |
|
| 3152 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3153 | - { |
|
| 3154 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3155 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3156 | - } |
|
| 3012 | + /** |
|
| 3013 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3014 | + */ |
|
| 3015 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3016 | + |
|
| 3017 | + /** |
|
| 3018 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3019 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3020 | + */ |
|
| 3021 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3022 | + |
|
| 3023 | + /** |
|
| 3024 | + * @var boolean $show_ticket_sale_columns |
|
| 3025 | + */ |
|
| 3026 | + public $show_ticket_sale_columns; |
|
| 3027 | + |
|
| 3028 | + /** |
|
| 3029 | + * @var boolean $show_ticket_details |
|
| 3030 | + */ |
|
| 3031 | + public $show_ticket_details; |
|
| 3032 | + |
|
| 3033 | + /** |
|
| 3034 | + * @var boolean $show_expired_tickets |
|
| 3035 | + */ |
|
| 3036 | + public $show_expired_tickets; |
|
| 3037 | + |
|
| 3038 | + /** |
|
| 3039 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 3040 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3041 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3042 | + * |
|
| 3043 | + * @var string $show_datetime_selector |
|
| 3044 | + */ |
|
| 3045 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3046 | + |
|
| 3047 | + /** |
|
| 3048 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3049 | + * |
|
| 3050 | + * @var int $datetime_selector_threshold |
|
| 3051 | + */ |
|
| 3052 | + private $datetime_selector_threshold = 3; |
|
| 3053 | + |
|
| 3054 | + |
|
| 3055 | + |
|
| 3056 | + /** |
|
| 3057 | + * class constructor |
|
| 3058 | + */ |
|
| 3059 | + public function __construct() |
|
| 3060 | + { |
|
| 3061 | + $this->show_ticket_sale_columns = true; |
|
| 3062 | + $this->show_ticket_details = true; |
|
| 3063 | + $this->show_expired_tickets = true; |
|
| 3064 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3065 | + $this->datetime_selector_threshold = 3; |
|
| 3066 | + } |
|
| 3067 | + |
|
| 3068 | + |
|
| 3069 | + |
|
| 3070 | + /** |
|
| 3071 | + * returns true if a datetime selector should be displayed |
|
| 3072 | + * |
|
| 3073 | + * @param array $datetimes |
|
| 3074 | + * @return bool |
|
| 3075 | + */ |
|
| 3076 | + public function showDatetimeSelector(array $datetimes) |
|
| 3077 | + { |
|
| 3078 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3079 | + return ! ( |
|
| 3080 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3081 | + || ( |
|
| 3082 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3083 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3084 | + ) |
|
| 3085 | + ); |
|
| 3086 | + } |
|
| 3087 | + |
|
| 3088 | + |
|
| 3089 | + |
|
| 3090 | + /** |
|
| 3091 | + * @return string |
|
| 3092 | + */ |
|
| 3093 | + public function getShowDatetimeSelector() |
|
| 3094 | + { |
|
| 3095 | + return $this->show_datetime_selector; |
|
| 3096 | + } |
|
| 3097 | + |
|
| 3098 | + |
|
| 3099 | + |
|
| 3100 | + /** |
|
| 3101 | + * @param bool $keys_only |
|
| 3102 | + * @return array |
|
| 3103 | + */ |
|
| 3104 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3105 | + { |
|
| 3106 | + return $keys_only |
|
| 3107 | + ? array( |
|
| 3108 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3109 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3110 | + ) |
|
| 3111 | + : array( |
|
| 3112 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3113 | + 'Do not show date & time filter', 'event_espresso' |
|
| 3114 | + ), |
|
| 3115 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3116 | + 'Maybe show date & time filter', 'event_espresso' |
|
| 3117 | + ), |
|
| 3118 | + ); |
|
| 3119 | + } |
|
| 3120 | + |
|
| 3121 | + |
|
| 3122 | + |
|
| 3123 | + /** |
|
| 3124 | + * @param string $show_datetime_selector |
|
| 3125 | + */ |
|
| 3126 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3127 | + { |
|
| 3128 | + $this->show_datetime_selector = in_array( |
|
| 3129 | + $show_datetime_selector, |
|
| 3130 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3131 | + true |
|
| 3132 | + ) |
|
| 3133 | + ? $show_datetime_selector |
|
| 3134 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3135 | + } |
|
| 3136 | + |
|
| 3137 | + |
|
| 3138 | + |
|
| 3139 | + /** |
|
| 3140 | + * @return int |
|
| 3141 | + */ |
|
| 3142 | + public function getDatetimeSelectorThreshold() |
|
| 3143 | + { |
|
| 3144 | + return $this->datetime_selector_threshold; |
|
| 3145 | + } |
|
| 3146 | + |
|
| 3147 | + |
|
| 3148 | + |
|
| 3149 | + /** |
|
| 3150 | + * @param int $datetime_selector_threshold |
|
| 3151 | + */ |
|
| 3152 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3153 | + { |
|
| 3154 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3155 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3156 | + } |
|
| 3157 | 3157 | |
| 3158 | 3158 | |
| 3159 | 3159 | } |
@@ -3170,85 +3170,85 @@ discard block |
||
| 3170 | 3170 | class EE_Environment_Config extends EE_Config_Base |
| 3171 | 3171 | { |
| 3172 | 3172 | |
| 3173 | - /** |
|
| 3174 | - * Hold any php environment variables that we want to track. |
|
| 3175 | - * |
|
| 3176 | - * @var stdClass; |
|
| 3177 | - */ |
|
| 3178 | - public $php; |
|
| 3179 | - |
|
| 3180 | - |
|
| 3181 | - |
|
| 3182 | - /** |
|
| 3183 | - * constructor |
|
| 3184 | - */ |
|
| 3185 | - public function __construct() |
|
| 3186 | - { |
|
| 3187 | - $this->php = new stdClass(); |
|
| 3188 | - $this->_set_php_values(); |
|
| 3189 | - } |
|
| 3190 | - |
|
| 3191 | - |
|
| 3192 | - |
|
| 3193 | - /** |
|
| 3194 | - * This sets the php environment variables. |
|
| 3195 | - * |
|
| 3196 | - * @since 4.4.0 |
|
| 3197 | - * @return void |
|
| 3198 | - */ |
|
| 3199 | - protected function _set_php_values() |
|
| 3200 | - { |
|
| 3201 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3202 | - $this->php->version = phpversion(); |
|
| 3203 | - } |
|
| 3204 | - |
|
| 3205 | - |
|
| 3206 | - |
|
| 3207 | - /** |
|
| 3208 | - * helper method for determining whether input_count is |
|
| 3209 | - * reaching the potential maximum the server can handle |
|
| 3210 | - * according to max_input_vars |
|
| 3211 | - * |
|
| 3212 | - * @param int $input_count the count of input vars. |
|
| 3213 | - * @return array { |
|
| 3214 | - * An array that represents whether available space and if no available space the error |
|
| 3215 | - * message. |
|
| 3216 | - * @type bool $has_space whether more inputs can be added. |
|
| 3217 | - * @type string $msg Any message to be displayed. |
|
| 3218 | - * } |
|
| 3219 | - */ |
|
| 3220 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3221 | - { |
|
| 3222 | - if (! empty($this->php->max_input_vars) |
|
| 3223 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3224 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3225 | - ) { |
|
| 3226 | - return sprintf( |
|
| 3227 | - __( |
|
| 3228 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3229 | - 'event_espresso' |
|
| 3230 | - ), |
|
| 3231 | - '<br>', |
|
| 3232 | - $input_count, |
|
| 3233 | - $this->php->max_input_vars |
|
| 3234 | - ); |
|
| 3235 | - } else { |
|
| 3236 | - return ''; |
|
| 3237 | - } |
|
| 3238 | - } |
|
| 3239 | - |
|
| 3240 | - |
|
| 3241 | - |
|
| 3242 | - /** |
|
| 3243 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3244 | - * |
|
| 3245 | - * @since 4.4.1 |
|
| 3246 | - * @return void |
|
| 3247 | - */ |
|
| 3248 | - public function recheck_values() |
|
| 3249 | - { |
|
| 3250 | - $this->_set_php_values(); |
|
| 3251 | - } |
|
| 3173 | + /** |
|
| 3174 | + * Hold any php environment variables that we want to track. |
|
| 3175 | + * |
|
| 3176 | + * @var stdClass; |
|
| 3177 | + */ |
|
| 3178 | + public $php; |
|
| 3179 | + |
|
| 3180 | + |
|
| 3181 | + |
|
| 3182 | + /** |
|
| 3183 | + * constructor |
|
| 3184 | + */ |
|
| 3185 | + public function __construct() |
|
| 3186 | + { |
|
| 3187 | + $this->php = new stdClass(); |
|
| 3188 | + $this->_set_php_values(); |
|
| 3189 | + } |
|
| 3190 | + |
|
| 3191 | + |
|
| 3192 | + |
|
| 3193 | + /** |
|
| 3194 | + * This sets the php environment variables. |
|
| 3195 | + * |
|
| 3196 | + * @since 4.4.0 |
|
| 3197 | + * @return void |
|
| 3198 | + */ |
|
| 3199 | + protected function _set_php_values() |
|
| 3200 | + { |
|
| 3201 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3202 | + $this->php->version = phpversion(); |
|
| 3203 | + } |
|
| 3204 | + |
|
| 3205 | + |
|
| 3206 | + |
|
| 3207 | + /** |
|
| 3208 | + * helper method for determining whether input_count is |
|
| 3209 | + * reaching the potential maximum the server can handle |
|
| 3210 | + * according to max_input_vars |
|
| 3211 | + * |
|
| 3212 | + * @param int $input_count the count of input vars. |
|
| 3213 | + * @return array { |
|
| 3214 | + * An array that represents whether available space and if no available space the error |
|
| 3215 | + * message. |
|
| 3216 | + * @type bool $has_space whether more inputs can be added. |
|
| 3217 | + * @type string $msg Any message to be displayed. |
|
| 3218 | + * } |
|
| 3219 | + */ |
|
| 3220 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3221 | + { |
|
| 3222 | + if (! empty($this->php->max_input_vars) |
|
| 3223 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3224 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3225 | + ) { |
|
| 3226 | + return sprintf( |
|
| 3227 | + __( |
|
| 3228 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3229 | + 'event_espresso' |
|
| 3230 | + ), |
|
| 3231 | + '<br>', |
|
| 3232 | + $input_count, |
|
| 3233 | + $this->php->max_input_vars |
|
| 3234 | + ); |
|
| 3235 | + } else { |
|
| 3236 | + return ''; |
|
| 3237 | + } |
|
| 3238 | + } |
|
| 3239 | + |
|
| 3240 | + |
|
| 3241 | + |
|
| 3242 | + /** |
|
| 3243 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3244 | + * |
|
| 3245 | + * @since 4.4.1 |
|
| 3246 | + * @return void |
|
| 3247 | + */ |
|
| 3248 | + public function recheck_values() |
|
| 3249 | + { |
|
| 3250 | + $this->_set_php_values(); |
|
| 3251 | + } |
|
| 3252 | 3252 | |
| 3253 | 3253 | |
| 3254 | 3254 | } |
@@ -3265,22 +3265,22 @@ discard block |
||
| 3265 | 3265 | class EE_Tax_Config extends EE_Config_Base |
| 3266 | 3266 | { |
| 3267 | 3267 | |
| 3268 | - /* |
|
| 3268 | + /* |
|
| 3269 | 3269 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3270 | 3270 | * |
| 3271 | 3271 | * @var boolean $prices_displayed_including_taxes |
| 3272 | 3272 | */ |
| 3273 | - public $prices_displayed_including_taxes; |
|
| 3273 | + public $prices_displayed_including_taxes; |
|
| 3274 | 3274 | |
| 3275 | 3275 | |
| 3276 | 3276 | |
| 3277 | - /** |
|
| 3278 | - * class constructor |
|
| 3279 | - */ |
|
| 3280 | - public function __construct() |
|
| 3281 | - { |
|
| 3282 | - $this->prices_displayed_including_taxes = true; |
|
| 3283 | - } |
|
| 3277 | + /** |
|
| 3278 | + * class constructor |
|
| 3279 | + */ |
|
| 3280 | + public function __construct() |
|
| 3281 | + { |
|
| 3282 | + $this->prices_displayed_including_taxes = true; |
|
| 3283 | + } |
|
| 3284 | 3284 | } |
| 3285 | 3285 | |
| 3286 | 3286 | |
@@ -3295,17 +3295,17 @@ discard block |
||
| 3295 | 3295 | class EE_Messages_Config extends EE_Config_Base |
| 3296 | 3296 | { |
| 3297 | 3297 | |
| 3298 | - /** |
|
| 3299 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3300 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3301 | - * |
|
| 3302 | - * @var integer |
|
| 3303 | - */ |
|
| 3304 | - public $delete_threshold; |
|
| 3305 | - |
|
| 3306 | - public function __construct() { |
|
| 3307 | - $this->delete_threshold = 0; |
|
| 3308 | - } |
|
| 3298 | + /** |
|
| 3299 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3300 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3301 | + * |
|
| 3302 | + * @var integer |
|
| 3303 | + */ |
|
| 3304 | + public $delete_threshold; |
|
| 3305 | + |
|
| 3306 | + public function __construct() { |
|
| 3307 | + $this->delete_threshold = 0; |
|
| 3308 | + } |
|
| 3309 | 3309 | } |
| 3310 | 3310 | |
| 3311 | 3311 | |
@@ -3317,34 +3317,34 @@ discard block |
||
| 3317 | 3317 | class EE_Gateway_Config extends EE_Config_Base |
| 3318 | 3318 | { |
| 3319 | 3319 | |
| 3320 | - /** |
|
| 3321 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3322 | - * with any config info the gateway wants to store |
|
| 3323 | - * |
|
| 3324 | - * @var array |
|
| 3325 | - */ |
|
| 3326 | - public $payment_settings; |
|
| 3327 | - |
|
| 3328 | - /** |
|
| 3329 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3330 | - * the gateway is stored in the uploads directory |
|
| 3331 | - * |
|
| 3332 | - * @var array |
|
| 3333 | - */ |
|
| 3334 | - public $active_gateways; |
|
| 3335 | - |
|
| 3336 | - |
|
| 3337 | - |
|
| 3338 | - /** |
|
| 3339 | - * class constructor |
|
| 3340 | - * |
|
| 3341 | - * @deprecated |
|
| 3342 | - */ |
|
| 3343 | - public function __construct() |
|
| 3344 | - { |
|
| 3345 | - $this->payment_settings = array(); |
|
| 3346 | - $this->active_gateways = array('Invoice' => false); |
|
| 3347 | - } |
|
| 3320 | + /** |
|
| 3321 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3322 | + * with any config info the gateway wants to store |
|
| 3323 | + * |
|
| 3324 | + * @var array |
|
| 3325 | + */ |
|
| 3326 | + public $payment_settings; |
|
| 3327 | + |
|
| 3328 | + /** |
|
| 3329 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3330 | + * the gateway is stored in the uploads directory |
|
| 3331 | + * |
|
| 3332 | + * @var array |
|
| 3333 | + */ |
|
| 3334 | + public $active_gateways; |
|
| 3335 | + |
|
| 3336 | + |
|
| 3337 | + |
|
| 3338 | + /** |
|
| 3339 | + * class constructor |
|
| 3340 | + * |
|
| 3341 | + * @deprecated |
|
| 3342 | + */ |
|
| 3343 | + public function __construct() |
|
| 3344 | + { |
|
| 3345 | + $this->payment_settings = array(); |
|
| 3346 | + $this->active_gateways = array('Invoice' => false); |
|
| 3347 | + } |
|
| 3348 | 3348 | } |
| 3349 | 3349 | |
| 3350 | 3350 | // End of file EE_Config.core.php |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -17,2634 +17,2634 @@ discard block |
||
| 17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will hold the event object for event_details screen. |
|
| 22 | - * |
|
| 23 | - * @access protected |
|
| 24 | - * @var EE_Event $_event |
|
| 25 | - */ |
|
| 26 | - protected $_event; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This will hold the category object for category_details screen. |
|
| 31 | - * |
|
| 32 | - * @var stdClass $_category |
|
| 33 | - */ |
|
| 34 | - protected $_category; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This will hold the event model instance |
|
| 39 | - * |
|
| 40 | - * @var EEM_Event $_event_model |
|
| 41 | - */ |
|
| 42 | - protected $_event_model; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Event |
|
| 48 | - */ |
|
| 49 | - protected $_cpt_model_obj = false; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - protected function _init_page_props() |
|
| 54 | - { |
|
| 55 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | - $this->page_label = EVENTS_LABEL; |
|
| 57 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | - $this->_cpt_model_names = array( |
|
| 60 | - 'create_new' => 'EEM_Event', |
|
| 61 | - 'edit' => 'EEM_Event', |
|
| 62 | - ); |
|
| 63 | - $this->_cpt_edit_routes = array( |
|
| 64 | - 'espresso_events' => 'edit', |
|
| 65 | - ); |
|
| 66 | - add_action( |
|
| 67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | - array($this, 'verify_event_edit') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - protected function _ajax_hooks() |
|
| 75 | - { |
|
| 76 | - //todo: all hooks for events ajax goes in here. |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - protected function _define_page_props() |
|
| 82 | - { |
|
| 83 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | - $this->_labels = array( |
|
| 85 | - 'buttons' => array( |
|
| 86 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | - ), |
|
| 93 | - 'editor_title' => array( |
|
| 94 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | - ), |
|
| 96 | - 'publishbox' => array( |
|
| 97 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | - ), |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - protected function _set_page_routes() |
|
| 109 | - { |
|
| 110 | - //load formatter helper |
|
| 111 | - //load field generator helper |
|
| 112 | - //is there a evt_id in the request? |
|
| 113 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | - $this->_page_routes = array( |
|
| 117 | - 'default' => array( |
|
| 118 | - 'func' => '_events_overview_list_table', |
|
| 119 | - 'capability' => 'ee_read_events', |
|
| 120 | - ), |
|
| 121 | - 'create_new' => array( |
|
| 122 | - 'func' => '_create_new_cpt_item', |
|
| 123 | - 'capability' => 'ee_edit_events', |
|
| 124 | - ), |
|
| 125 | - 'edit' => array( |
|
| 126 | - 'func' => '_edit_cpt_item', |
|
| 127 | - 'capability' => 'ee_edit_event', |
|
| 128 | - 'obj_id' => $evt_id, |
|
| 129 | - ), |
|
| 130 | - 'copy_event' => array( |
|
| 131 | - 'func' => '_copy_events', |
|
| 132 | - 'capability' => 'ee_edit_event', |
|
| 133 | - 'obj_id' => $evt_id, |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ), |
|
| 136 | - 'trash_event' => array( |
|
| 137 | - 'func' => '_trash_or_restore_event', |
|
| 138 | - 'args' => array('event_status' => 'trash'), |
|
| 139 | - 'capability' => 'ee_delete_event', |
|
| 140 | - 'obj_id' => $evt_id, |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ), |
|
| 143 | - 'trash_events' => array( |
|
| 144 | - 'func' => '_trash_or_restore_events', |
|
| 145 | - 'args' => array('event_status' => 'trash'), |
|
| 146 | - 'capability' => 'ee_delete_events', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ), |
|
| 149 | - 'restore_event' => array( |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => array('event_status' => 'draft'), |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $evt_id, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ), |
|
| 156 | - 'restore_events' => array( |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => array('event_status' => 'draft'), |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ), |
|
| 162 | - 'delete_event' => array( |
|
| 163 | - 'func' => '_delete_event', |
|
| 164 | - 'capability' => 'ee_delete_event', |
|
| 165 | - 'obj_id' => $evt_id, |
|
| 166 | - 'noheader' => true, |
|
| 167 | - ), |
|
| 168 | - 'delete_events' => array( |
|
| 169 | - 'func' => '_delete_events', |
|
| 170 | - 'capability' => 'ee_delete_events', |
|
| 171 | - 'noheader' => true, |
|
| 172 | - ), |
|
| 173 | - 'view_report' => array( |
|
| 174 | - 'func' => '_view_report', |
|
| 175 | - 'capablity' => 'ee_edit_events', |
|
| 176 | - ), |
|
| 177 | - 'default_event_settings' => array( |
|
| 178 | - 'func' => '_default_event_settings', |
|
| 179 | - 'capability' => 'manage_options', |
|
| 180 | - ), |
|
| 181 | - 'update_default_event_settings' => array( |
|
| 182 | - 'func' => '_update_default_event_settings', |
|
| 183 | - 'capability' => 'manage_options', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ), |
|
| 186 | - 'template_settings' => array( |
|
| 187 | - 'func' => '_template_settings', |
|
| 188 | - 'capability' => 'manage_options', |
|
| 189 | - ), |
|
| 190 | - //event category tab related |
|
| 191 | - 'add_category' => array( |
|
| 192 | - 'func' => '_category_details', |
|
| 193 | - 'capability' => 'ee_edit_event_category', |
|
| 194 | - 'args' => array('add'), |
|
| 195 | - ), |
|
| 196 | - 'edit_category' => array( |
|
| 197 | - 'func' => '_category_details', |
|
| 198 | - 'capability' => 'ee_edit_event_category', |
|
| 199 | - 'args' => array('edit'), |
|
| 200 | - ), |
|
| 201 | - 'delete_categories' => array( |
|
| 202 | - 'func' => '_delete_categories', |
|
| 203 | - 'capability' => 'ee_delete_event_category', |
|
| 204 | - 'noheader' => true, |
|
| 205 | - ), |
|
| 206 | - 'delete_category' => array( |
|
| 207 | - 'func' => '_delete_categories', |
|
| 208 | - 'capability' => 'ee_delete_event_category', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - ), |
|
| 211 | - 'insert_category' => array( |
|
| 212 | - 'func' => '_insert_or_update_category', |
|
| 213 | - 'args' => array('new_category' => true), |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - ), |
|
| 217 | - 'update_category' => array( |
|
| 218 | - 'func' => '_insert_or_update_category', |
|
| 219 | - 'args' => array('new_category' => false), |
|
| 220 | - 'capability' => 'ee_edit_event_category', |
|
| 221 | - 'noheader' => true, |
|
| 222 | - ), |
|
| 223 | - 'category_list' => array( |
|
| 224 | - 'func' => '_category_list_table', |
|
| 225 | - 'capability' => 'ee_manage_event_categories', |
|
| 226 | - ), |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - protected function _set_page_config() |
|
| 233 | - { |
|
| 234 | - $this->_page_config = array( |
|
| 235 | - 'default' => array( |
|
| 236 | - 'nav' => array( |
|
| 237 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | - 'order' => 10, |
|
| 239 | - ), |
|
| 240 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | - 'help_tabs' => array( |
|
| 242 | - 'events_overview_help_tab' => array( |
|
| 243 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | - 'filename' => 'events_overview', |
|
| 245 | - ), |
|
| 246 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | - 'filename' => 'events_overview_table_column_headings', |
|
| 249 | - ), |
|
| 250 | - 'events_overview_filters_help_tab' => array( |
|
| 251 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | - 'filename' => 'events_overview_filters', |
|
| 253 | - ), |
|
| 254 | - 'events_overview_view_help_tab' => array( |
|
| 255 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | - 'filename' => 'events_overview_views', |
|
| 257 | - ), |
|
| 258 | - 'events_overview_other_help_tab' => array( |
|
| 259 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | - 'filename' => 'events_overview_other', |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - 'help_tour' => array( |
|
| 264 | - 'Event_Overview_Help_Tour', |
|
| 265 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | - ), |
|
| 267 | - 'qtips' => array( |
|
| 268 | - 'EE_Event_List_Table_Tips', |
|
| 269 | - ), |
|
| 270 | - 'require_nonce' => false, |
|
| 271 | - ), |
|
| 272 | - 'create_new' => array( |
|
| 273 | - 'nav' => array( |
|
| 274 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | - 'order' => 5, |
|
| 276 | - 'persistent' => false, |
|
| 277 | - ), |
|
| 278 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | - 'help_tabs' => array( |
|
| 280 | - 'event_editor_help_tab' => array( |
|
| 281 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | - 'filename' => 'event_editor', |
|
| 283 | - ), |
|
| 284 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | - ), |
|
| 288 | - 'event_editor_venue_details_help_tab' => array( |
|
| 289 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | - 'filename' => 'event_editor_venue_details', |
|
| 291 | - ), |
|
| 292 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | - 'filename' => 'event_editor_event_datetimes', |
|
| 295 | - ), |
|
| 296 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | - 'filename' => 'event_editor_event_tickets', |
|
| 299 | - ), |
|
| 300 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | - 'filename' => 'event_editor_event_registration_options', |
|
| 303 | - ), |
|
| 304 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | - 'filename' => 'event_editor_tags_categories', |
|
| 307 | - ), |
|
| 308 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | - 'filename' => 'event_editor_questions_registrants', |
|
| 311 | - ), |
|
| 312 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | - 'filename' => 'event_editor_save_new_event', |
|
| 315 | - ), |
|
| 316 | - 'event_editor_other_help_tab' => array( |
|
| 317 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | - 'filename' => 'event_editor_other', |
|
| 319 | - ), |
|
| 320 | - ), |
|
| 321 | - 'help_tour' => array( |
|
| 322 | - 'Event_Editor_Help_Tour', |
|
| 323 | - ), |
|
| 324 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | - 'require_nonce' => false, |
|
| 326 | - ), |
|
| 327 | - 'edit' => array( |
|
| 328 | - 'nav' => array( |
|
| 329 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | - 'order' => 5, |
|
| 331 | - 'persistent' => false, |
|
| 332 | - 'url' => isset($this->_req_data['post']) |
|
| 333 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | - $this->_current_page_view_url |
|
| 336 | - ) |
|
| 337 | - : $this->_admin_base_url, |
|
| 338 | - ), |
|
| 339 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | - 'help_tabs' => array( |
|
| 341 | - 'event_editor_help_tab' => array( |
|
| 342 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor', |
|
| 344 | - ), |
|
| 345 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | - ), |
|
| 349 | - 'event_editor_venue_details_help_tab' => array( |
|
| 350 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | - 'filename' => 'event_editor_venue_details', |
|
| 352 | - ), |
|
| 353 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | - 'filename' => 'event_editor_event_datetimes', |
|
| 356 | - ), |
|
| 357 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | - 'filename' => 'event_editor_event_tickets', |
|
| 360 | - ), |
|
| 361 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | - 'filename' => 'event_editor_event_registration_options', |
|
| 364 | - ), |
|
| 365 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | - 'filename' => 'event_editor_tags_categories', |
|
| 368 | - ), |
|
| 369 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor_questions_registrants', |
|
| 372 | - ), |
|
| 373 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_save_new_event', |
|
| 376 | - ), |
|
| 377 | - 'event_editor_other_help_tab' => array( |
|
| 378 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_other', |
|
| 380 | - ), |
|
| 381 | - ), |
|
| 382 | - /*'help_tour' => array( |
|
| 20 | + /** |
|
| 21 | + * This will hold the event object for event_details screen. |
|
| 22 | + * |
|
| 23 | + * @access protected |
|
| 24 | + * @var EE_Event $_event |
|
| 25 | + */ |
|
| 26 | + protected $_event; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This will hold the category object for category_details screen. |
|
| 31 | + * |
|
| 32 | + * @var stdClass $_category |
|
| 33 | + */ |
|
| 34 | + protected $_category; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This will hold the event model instance |
|
| 39 | + * |
|
| 40 | + * @var EEM_Event $_event_model |
|
| 41 | + */ |
|
| 42 | + protected $_event_model; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Event |
|
| 48 | + */ |
|
| 49 | + protected $_cpt_model_obj = false; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + protected function _init_page_props() |
|
| 54 | + { |
|
| 55 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | + $this->page_label = EVENTS_LABEL; |
|
| 57 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | + $this->_cpt_model_names = array( |
|
| 60 | + 'create_new' => 'EEM_Event', |
|
| 61 | + 'edit' => 'EEM_Event', |
|
| 62 | + ); |
|
| 63 | + $this->_cpt_edit_routes = array( |
|
| 64 | + 'espresso_events' => 'edit', |
|
| 65 | + ); |
|
| 66 | + add_action( |
|
| 67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | + array($this, 'verify_event_edit') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + protected function _ajax_hooks() |
|
| 75 | + { |
|
| 76 | + //todo: all hooks for events ajax goes in here. |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + protected function _define_page_props() |
|
| 82 | + { |
|
| 83 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | + $this->_labels = array( |
|
| 85 | + 'buttons' => array( |
|
| 86 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | + ), |
|
| 93 | + 'editor_title' => array( |
|
| 94 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | + ), |
|
| 96 | + 'publishbox' => array( |
|
| 97 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | + ), |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + protected function _set_page_routes() |
|
| 109 | + { |
|
| 110 | + //load formatter helper |
|
| 111 | + //load field generator helper |
|
| 112 | + //is there a evt_id in the request? |
|
| 113 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | + $this->_page_routes = array( |
|
| 117 | + 'default' => array( |
|
| 118 | + 'func' => '_events_overview_list_table', |
|
| 119 | + 'capability' => 'ee_read_events', |
|
| 120 | + ), |
|
| 121 | + 'create_new' => array( |
|
| 122 | + 'func' => '_create_new_cpt_item', |
|
| 123 | + 'capability' => 'ee_edit_events', |
|
| 124 | + ), |
|
| 125 | + 'edit' => array( |
|
| 126 | + 'func' => '_edit_cpt_item', |
|
| 127 | + 'capability' => 'ee_edit_event', |
|
| 128 | + 'obj_id' => $evt_id, |
|
| 129 | + ), |
|
| 130 | + 'copy_event' => array( |
|
| 131 | + 'func' => '_copy_events', |
|
| 132 | + 'capability' => 'ee_edit_event', |
|
| 133 | + 'obj_id' => $evt_id, |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ), |
|
| 136 | + 'trash_event' => array( |
|
| 137 | + 'func' => '_trash_or_restore_event', |
|
| 138 | + 'args' => array('event_status' => 'trash'), |
|
| 139 | + 'capability' => 'ee_delete_event', |
|
| 140 | + 'obj_id' => $evt_id, |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ), |
|
| 143 | + 'trash_events' => array( |
|
| 144 | + 'func' => '_trash_or_restore_events', |
|
| 145 | + 'args' => array('event_status' => 'trash'), |
|
| 146 | + 'capability' => 'ee_delete_events', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ), |
|
| 149 | + 'restore_event' => array( |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => array('event_status' => 'draft'), |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $evt_id, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ), |
|
| 156 | + 'restore_events' => array( |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => array('event_status' => 'draft'), |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ), |
|
| 162 | + 'delete_event' => array( |
|
| 163 | + 'func' => '_delete_event', |
|
| 164 | + 'capability' => 'ee_delete_event', |
|
| 165 | + 'obj_id' => $evt_id, |
|
| 166 | + 'noheader' => true, |
|
| 167 | + ), |
|
| 168 | + 'delete_events' => array( |
|
| 169 | + 'func' => '_delete_events', |
|
| 170 | + 'capability' => 'ee_delete_events', |
|
| 171 | + 'noheader' => true, |
|
| 172 | + ), |
|
| 173 | + 'view_report' => array( |
|
| 174 | + 'func' => '_view_report', |
|
| 175 | + 'capablity' => 'ee_edit_events', |
|
| 176 | + ), |
|
| 177 | + 'default_event_settings' => array( |
|
| 178 | + 'func' => '_default_event_settings', |
|
| 179 | + 'capability' => 'manage_options', |
|
| 180 | + ), |
|
| 181 | + 'update_default_event_settings' => array( |
|
| 182 | + 'func' => '_update_default_event_settings', |
|
| 183 | + 'capability' => 'manage_options', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ), |
|
| 186 | + 'template_settings' => array( |
|
| 187 | + 'func' => '_template_settings', |
|
| 188 | + 'capability' => 'manage_options', |
|
| 189 | + ), |
|
| 190 | + //event category tab related |
|
| 191 | + 'add_category' => array( |
|
| 192 | + 'func' => '_category_details', |
|
| 193 | + 'capability' => 'ee_edit_event_category', |
|
| 194 | + 'args' => array('add'), |
|
| 195 | + ), |
|
| 196 | + 'edit_category' => array( |
|
| 197 | + 'func' => '_category_details', |
|
| 198 | + 'capability' => 'ee_edit_event_category', |
|
| 199 | + 'args' => array('edit'), |
|
| 200 | + ), |
|
| 201 | + 'delete_categories' => array( |
|
| 202 | + 'func' => '_delete_categories', |
|
| 203 | + 'capability' => 'ee_delete_event_category', |
|
| 204 | + 'noheader' => true, |
|
| 205 | + ), |
|
| 206 | + 'delete_category' => array( |
|
| 207 | + 'func' => '_delete_categories', |
|
| 208 | + 'capability' => 'ee_delete_event_category', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + ), |
|
| 211 | + 'insert_category' => array( |
|
| 212 | + 'func' => '_insert_or_update_category', |
|
| 213 | + 'args' => array('new_category' => true), |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + ), |
|
| 217 | + 'update_category' => array( |
|
| 218 | + 'func' => '_insert_or_update_category', |
|
| 219 | + 'args' => array('new_category' => false), |
|
| 220 | + 'capability' => 'ee_edit_event_category', |
|
| 221 | + 'noheader' => true, |
|
| 222 | + ), |
|
| 223 | + 'category_list' => array( |
|
| 224 | + 'func' => '_category_list_table', |
|
| 225 | + 'capability' => 'ee_manage_event_categories', |
|
| 226 | + ), |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + protected function _set_page_config() |
|
| 233 | + { |
|
| 234 | + $this->_page_config = array( |
|
| 235 | + 'default' => array( |
|
| 236 | + 'nav' => array( |
|
| 237 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | + 'order' => 10, |
|
| 239 | + ), |
|
| 240 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | + 'help_tabs' => array( |
|
| 242 | + 'events_overview_help_tab' => array( |
|
| 243 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | + 'filename' => 'events_overview', |
|
| 245 | + ), |
|
| 246 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | + 'filename' => 'events_overview_table_column_headings', |
|
| 249 | + ), |
|
| 250 | + 'events_overview_filters_help_tab' => array( |
|
| 251 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | + 'filename' => 'events_overview_filters', |
|
| 253 | + ), |
|
| 254 | + 'events_overview_view_help_tab' => array( |
|
| 255 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | + 'filename' => 'events_overview_views', |
|
| 257 | + ), |
|
| 258 | + 'events_overview_other_help_tab' => array( |
|
| 259 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | + 'filename' => 'events_overview_other', |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + 'help_tour' => array( |
|
| 264 | + 'Event_Overview_Help_Tour', |
|
| 265 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | + ), |
|
| 267 | + 'qtips' => array( |
|
| 268 | + 'EE_Event_List_Table_Tips', |
|
| 269 | + ), |
|
| 270 | + 'require_nonce' => false, |
|
| 271 | + ), |
|
| 272 | + 'create_new' => array( |
|
| 273 | + 'nav' => array( |
|
| 274 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | + 'order' => 5, |
|
| 276 | + 'persistent' => false, |
|
| 277 | + ), |
|
| 278 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | + 'help_tabs' => array( |
|
| 280 | + 'event_editor_help_tab' => array( |
|
| 281 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | + 'filename' => 'event_editor', |
|
| 283 | + ), |
|
| 284 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | + ), |
|
| 288 | + 'event_editor_venue_details_help_tab' => array( |
|
| 289 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | + 'filename' => 'event_editor_venue_details', |
|
| 291 | + ), |
|
| 292 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | + 'filename' => 'event_editor_event_datetimes', |
|
| 295 | + ), |
|
| 296 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | + 'filename' => 'event_editor_event_tickets', |
|
| 299 | + ), |
|
| 300 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | + 'filename' => 'event_editor_event_registration_options', |
|
| 303 | + ), |
|
| 304 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | + 'filename' => 'event_editor_tags_categories', |
|
| 307 | + ), |
|
| 308 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | + 'filename' => 'event_editor_questions_registrants', |
|
| 311 | + ), |
|
| 312 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | + 'filename' => 'event_editor_save_new_event', |
|
| 315 | + ), |
|
| 316 | + 'event_editor_other_help_tab' => array( |
|
| 317 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | + 'filename' => 'event_editor_other', |
|
| 319 | + ), |
|
| 320 | + ), |
|
| 321 | + 'help_tour' => array( |
|
| 322 | + 'Event_Editor_Help_Tour', |
|
| 323 | + ), |
|
| 324 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | + 'require_nonce' => false, |
|
| 326 | + ), |
|
| 327 | + 'edit' => array( |
|
| 328 | + 'nav' => array( |
|
| 329 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | + 'order' => 5, |
|
| 331 | + 'persistent' => false, |
|
| 332 | + 'url' => isset($this->_req_data['post']) |
|
| 333 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | + $this->_current_page_view_url |
|
| 336 | + ) |
|
| 337 | + : $this->_admin_base_url, |
|
| 338 | + ), |
|
| 339 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | + 'help_tabs' => array( |
|
| 341 | + 'event_editor_help_tab' => array( |
|
| 342 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor', |
|
| 344 | + ), |
|
| 345 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | + ), |
|
| 349 | + 'event_editor_venue_details_help_tab' => array( |
|
| 350 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | + 'filename' => 'event_editor_venue_details', |
|
| 352 | + ), |
|
| 353 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | + 'filename' => 'event_editor_event_datetimes', |
|
| 356 | + ), |
|
| 357 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | + 'filename' => 'event_editor_event_tickets', |
|
| 360 | + ), |
|
| 361 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | + 'filename' => 'event_editor_event_registration_options', |
|
| 364 | + ), |
|
| 365 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | + 'filename' => 'event_editor_tags_categories', |
|
| 368 | + ), |
|
| 369 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor_questions_registrants', |
|
| 372 | + ), |
|
| 373 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_save_new_event', |
|
| 376 | + ), |
|
| 377 | + 'event_editor_other_help_tab' => array( |
|
| 378 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_other', |
|
| 380 | + ), |
|
| 381 | + ), |
|
| 382 | + /*'help_tour' => array( |
|
| 383 | 383 | 'Event_Edit_Help_Tour' |
| 384 | 384 | ),*/ |
| 385 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | - 'require_nonce' => false, |
|
| 387 | - ), |
|
| 388 | - 'default_event_settings' => array( |
|
| 389 | - 'nav' => array( |
|
| 390 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | - 'order' => 40, |
|
| 392 | - ), |
|
| 393 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | - 'labels' => array( |
|
| 395 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | - ), |
|
| 397 | - 'help_tabs' => array( |
|
| 398 | - 'default_settings_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | - 'filename' => 'events_default_settings', |
|
| 401 | - ), |
|
| 402 | - 'default_settings_status_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | - 'filename' => 'events_default_settings_status', |
|
| 405 | - ), |
|
| 406 | - 'default_maximum_tickets_help_tab' => array( |
|
| 407 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 408 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 409 | - ) |
|
| 410 | - ), |
|
| 411 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 412 | - 'require_nonce' => false, |
|
| 413 | - ), |
|
| 414 | - //template settings |
|
| 415 | - 'template_settings' => array( |
|
| 416 | - 'nav' => array( |
|
| 417 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 418 | - 'order' => 30, |
|
| 419 | - ), |
|
| 420 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 421 | - 'help_tabs' => array( |
|
| 422 | - 'general_settings_templates_help_tab' => array( |
|
| 423 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 424 | - 'filename' => 'general_settings_templates', |
|
| 425 | - ), |
|
| 426 | - ), |
|
| 427 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 428 | - 'require_nonce' => false, |
|
| 429 | - ), |
|
| 430 | - //event category stuff |
|
| 431 | - 'add_category' => array( |
|
| 432 | - 'nav' => array( |
|
| 433 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 434 | - 'order' => 15, |
|
| 435 | - 'persistent' => false, |
|
| 436 | - ), |
|
| 437 | - 'help_tabs' => array( |
|
| 438 | - 'add_category_help_tab' => array( |
|
| 439 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 440 | - 'filename' => 'events_add_category', |
|
| 441 | - ), |
|
| 442 | - ), |
|
| 443 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 444 | - 'metaboxes' => array('_publish_post_box'), |
|
| 445 | - 'require_nonce' => false, |
|
| 446 | - ), |
|
| 447 | - 'edit_category' => array( |
|
| 448 | - 'nav' => array( |
|
| 449 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 450 | - 'order' => 15, |
|
| 451 | - 'persistent' => false, |
|
| 452 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 453 | - ? add_query_arg( |
|
| 454 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 455 | - $this->_current_page_view_url |
|
| 456 | - ) |
|
| 457 | - : $this->_admin_base_url, |
|
| 458 | - ), |
|
| 459 | - 'help_tabs' => array( |
|
| 460 | - 'edit_category_help_tab' => array( |
|
| 461 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 462 | - 'filename' => 'events_edit_category', |
|
| 463 | - ), |
|
| 464 | - ), |
|
| 465 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 466 | - 'metaboxes' => array('_publish_post_box'), |
|
| 467 | - 'require_nonce' => false, |
|
| 468 | - ), |
|
| 469 | - 'category_list' => array( |
|
| 470 | - 'nav' => array( |
|
| 471 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 472 | - 'order' => 20, |
|
| 473 | - ), |
|
| 474 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 475 | - 'help_tabs' => array( |
|
| 476 | - 'events_categories_help_tab' => array( |
|
| 477 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 478 | - 'filename' => 'events_categories', |
|
| 479 | - ), |
|
| 480 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 481 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 482 | - 'filename' => 'events_categories_table_column_headings', |
|
| 483 | - ), |
|
| 484 | - 'events_categories_view_help_tab' => array( |
|
| 485 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 486 | - 'filename' => 'events_categories_views', |
|
| 487 | - ), |
|
| 488 | - 'events_categories_other_help_tab' => array( |
|
| 489 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 490 | - 'filename' => 'events_categories_other', |
|
| 491 | - ), |
|
| 492 | - ), |
|
| 493 | - 'help_tour' => array( |
|
| 494 | - 'Event_Categories_Help_Tour', |
|
| 495 | - ), |
|
| 496 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 497 | - 'require_nonce' => false, |
|
| 498 | - ), |
|
| 499 | - ); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - protected function _add_screen_options() |
|
| 505 | - { |
|
| 506 | - //todo |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - protected function _add_screen_options_default() |
|
| 512 | - { |
|
| 513 | - $this->_per_page_screen_option(); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - protected function _add_screen_options_category_list() |
|
| 519 | - { |
|
| 520 | - $page_title = $this->_admin_page_title; |
|
| 521 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 522 | - $this->_per_page_screen_option(); |
|
| 523 | - $this->_admin_page_title = $page_title; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - protected function _add_feature_pointers() |
|
| 529 | - { |
|
| 530 | - //todo |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - public function load_scripts_styles() |
|
| 536 | - { |
|
| 537 | - wp_register_style( |
|
| 538 | - 'events-admin-css', |
|
| 539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 540 | - array(), |
|
| 541 | - EVENT_ESPRESSO_VERSION |
|
| 542 | - ); |
|
| 543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | - wp_enqueue_style('events-admin-css'); |
|
| 545 | - wp_enqueue_style('ee-cat-admin'); |
|
| 546 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 547 | - //registers for all views |
|
| 548 | - //scripts |
|
| 549 | - wp_register_script( |
|
| 550 | - 'event_editor_js', |
|
| 551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 552 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 553 | - EVENT_ESPRESSO_VERSION, |
|
| 554 | - true |
|
| 555 | - ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueuing scripts and styles specific to this view |
|
| 562 | - * |
|
| 563 | - * @return void |
|
| 564 | - */ |
|
| 565 | - public function load_scripts_styles_create_new() |
|
| 566 | - { |
|
| 567 | - $this->load_scripts_styles_edit(); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * enqueuing scripts and styles specific to this view |
|
| 574 | - * |
|
| 575 | - * @return void |
|
| 576 | - */ |
|
| 577 | - public function load_scripts_styles_edit() |
|
| 578 | - { |
|
| 579 | - //styles |
|
| 580 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 581 | - wp_register_style( |
|
| 582 | - 'event-editor-css', |
|
| 583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 584 | - array('ee-admin-css'), |
|
| 585 | - EVENT_ESPRESSO_VERSION |
|
| 586 | - ); |
|
| 587 | - wp_enqueue_style('event-editor-css'); |
|
| 588 | - //scripts |
|
| 589 | - wp_register_script( |
|
| 590 | - 'event-datetime-metabox', |
|
| 591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 592 | - array('event_editor_js', 'ee-datepicker'), |
|
| 593 | - EVENT_ESPRESSO_VERSION |
|
| 594 | - ); |
|
| 595 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - public function load_scripts_styles_add_category() |
|
| 601 | - { |
|
| 602 | - $this->load_scripts_styles_edit_category(); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - public function load_scripts_styles_edit_category() |
|
| 608 | - { |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - protected function _set_list_table_views_category_list() |
|
| 614 | - { |
|
| 615 | - $this->_views = array( |
|
| 616 | - 'all' => array( |
|
| 617 | - 'slug' => 'all', |
|
| 618 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 619 | - 'count' => 0, |
|
| 620 | - 'bulk_action' => array( |
|
| 621 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 622 | - ), |
|
| 623 | - ), |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - public function admin_init() |
|
| 630 | - { |
|
| 631 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 632 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 633 | - 'event_espresso' |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - //nothing needed for events with these methods. |
|
| 640 | - public function admin_notices() |
|
| 641 | - { |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - public function admin_footer_scripts() |
|
| 647 | - { |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 654 | - * warning (via EE_Error::add_error()); |
|
| 655 | - * |
|
| 656 | - * @param EE_Event $event Event object |
|
| 657 | - * @access public |
|
| 658 | - * @return void |
|
| 659 | - */ |
|
| 660 | - public function verify_event_edit($event = null) |
|
| 661 | - { |
|
| 662 | - // no event? |
|
| 663 | - if (empty($event)) { |
|
| 664 | - // set event |
|
| 665 | - $event = $this->_cpt_model_obj; |
|
| 666 | - } |
|
| 667 | - // STILL no event? |
|
| 668 | - if (empty ($event)) { |
|
| 669 | - return; |
|
| 670 | - } |
|
| 671 | - $orig_status = $event->status(); |
|
| 672 | - // first check if event is active. |
|
| 673 | - if ( |
|
| 674 | - $orig_status === EEM_Event::cancelled |
|
| 675 | - || $orig_status === EEM_Event::postponed |
|
| 676 | - || $event->is_expired() |
|
| 677 | - || $event->is_inactive() |
|
| 678 | - ) { |
|
| 679 | - return; |
|
| 680 | - } |
|
| 681 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 682 | - if ($event->is_sold_out(true)) { |
|
| 683 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 684 | - EE_Error::add_attention( |
|
| 685 | - sprintf( |
|
| 686 | - esc_html__( |
|
| 687 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 688 | - 'event_espresso' |
|
| 689 | - ), |
|
| 690 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - } |
|
| 694 | - return; |
|
| 695 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 696 | - EE_Error::add_attention( |
|
| 697 | - sprintf( |
|
| 698 | - esc_html__( |
|
| 699 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 700 | - 'event_espresso' |
|
| 701 | - ), |
|
| 702 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 703 | - ) |
|
| 704 | - ); |
|
| 705 | - } |
|
| 706 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 707 | - if ( ! $event->tickets_on_sale()) { |
|
| 708 | - return; |
|
| 709 | - } |
|
| 710 | - //made it here so show warning |
|
| 711 | - $this->_edit_event_warning(); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 718 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 719 | - * |
|
| 720 | - * @access protected |
|
| 721 | - * @return void |
|
| 722 | - */ |
|
| 723 | - protected function _edit_event_warning() |
|
| 724 | - { |
|
| 725 | - // we don't want to add warnings during these requests |
|
| 726 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 727 | - return; |
|
| 728 | - } |
|
| 729 | - EE_Error::add_attention( |
|
| 730 | - esc_html__( |
|
| 731 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 732 | - 'event_espresso' |
|
| 733 | - ) |
|
| 734 | - ); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 741 | - * Otherwise, do the normal logic |
|
| 742 | - * |
|
| 743 | - * @return string |
|
| 744 | - * @throws \EE_Error |
|
| 745 | - */ |
|
| 746 | - protected function _create_new_cpt_item() |
|
| 747 | - { |
|
| 748 | - $gmt_offset = get_option('gmt_offset'); |
|
| 749 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 750 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 751 | - EE_Error::add_attention( |
|
| 752 | - sprintf( |
|
| 753 | - __( |
|
| 754 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 755 | - 'event_espresso' |
|
| 756 | - ), |
|
| 757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 758 | - '</a>' |
|
| 759 | - ), |
|
| 760 | - __FILE__, |
|
| 761 | - __FUNCTION__, |
|
| 762 | - __LINE__ |
|
| 763 | - ); |
|
| 764 | - } |
|
| 765 | - return parent::_create_new_cpt_item(); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - protected function _set_list_table_views_default() |
|
| 771 | - { |
|
| 772 | - $this->_views = array( |
|
| 773 | - 'all' => array( |
|
| 774 | - 'slug' => 'all', |
|
| 775 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 776 | - 'count' => 0, |
|
| 777 | - 'bulk_action' => array( |
|
| 778 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 779 | - ), |
|
| 780 | - ), |
|
| 781 | - 'draft' => array( |
|
| 782 | - 'slug' => 'draft', |
|
| 783 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 784 | - 'count' => 0, |
|
| 785 | - 'bulk_action' => array( |
|
| 786 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 787 | - ), |
|
| 788 | - ), |
|
| 789 | - ); |
|
| 790 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 791 | - $this->_views['trash'] = array( |
|
| 792 | - 'slug' => 'trash', |
|
| 793 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 794 | - 'count' => 0, |
|
| 795 | - 'bulk_action' => array( |
|
| 796 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 797 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 798 | - ), |
|
| 799 | - ); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * @return array |
|
| 807 | - */ |
|
| 808 | - protected function _event_legend_items() |
|
| 809 | - { |
|
| 810 | - $items = array( |
|
| 811 | - 'view_details' => array( |
|
| 812 | - 'class' => 'dashicons dashicons-search', |
|
| 813 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 814 | - ), |
|
| 815 | - 'edit_event' => array( |
|
| 816 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 817 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 818 | - ), |
|
| 819 | - 'view_attendees' => array( |
|
| 820 | - 'class' => 'dashicons dashicons-groups', |
|
| 821 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 822 | - ), |
|
| 823 | - ); |
|
| 824 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 825 | - $statuses = array( |
|
| 826 | - 'sold_out_status' => array( |
|
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 828 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 829 | - ), |
|
| 830 | - 'active_status' => array( |
|
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 832 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 833 | - ), |
|
| 834 | - 'upcoming_status' => array( |
|
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 836 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 837 | - ), |
|
| 838 | - 'postponed_status' => array( |
|
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 840 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 841 | - ), |
|
| 842 | - 'cancelled_status' => array( |
|
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 844 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 845 | - ), |
|
| 846 | - 'expired_status' => array( |
|
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 848 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 849 | - ), |
|
| 850 | - 'inactive_status' => array( |
|
| 851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 852 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 853 | - ), |
|
| 854 | - ); |
|
| 855 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 856 | - return array_merge($items, $statuses); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * _event_model |
|
| 863 | - * |
|
| 864 | - * @return EEM_Event |
|
| 865 | - */ |
|
| 866 | - private function _event_model() |
|
| 867 | - { |
|
| 868 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 869 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 870 | - } |
|
| 871 | - return $this->_event_model; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 878 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 879 | - * |
|
| 880 | - * @param string $return the current html |
|
| 881 | - * @param int $id the post id for the page |
|
| 882 | - * @param string $new_title What the title is |
|
| 883 | - * @param string $new_slug what the slug is |
|
| 884 | - * @return string The new html string for the permalink area |
|
| 885 | - */ |
|
| 886 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 887 | - { |
|
| 888 | - //make sure this is only when editing |
|
| 889 | - if ( ! empty($id)) { |
|
| 890 | - $post = get_post($id); |
|
| 891 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 892 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 893 | - . '</a> '; |
|
| 894 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 895 | - . $post->ID |
|
| 896 | - . ']">'; |
|
| 897 | - } |
|
| 898 | - return $return; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * _events_overview_list_table |
|
| 905 | - * This contains the logic for showing the events_overview list |
|
| 906 | - * |
|
| 907 | - * @access protected |
|
| 908 | - * @return void |
|
| 909 | - * @throws \EE_Error |
|
| 910 | - */ |
|
| 911 | - protected function _events_overview_list_table() |
|
| 912 | - { |
|
| 913 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 914 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 915 | - ? (array)$this->_template_args['after_list_table'] |
|
| 916 | - : array(); |
|
| 917 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 918 | - . EEH_Template::get_button_or_link( |
|
| 919 | - get_post_type_archive_link('espresso_events'), |
|
| 920 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 921 | - 'button' |
|
| 922 | - ); |
|
| 923 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 925 | - 'create_new', |
|
| 926 | - 'add', |
|
| 927 | - array(), |
|
| 928 | - 'add-new-h2' |
|
| 929 | - ); |
|
| 930 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * this allows for extra misc actions in the default WP publish box |
|
| 937 | - * |
|
| 938 | - * @return void |
|
| 939 | - */ |
|
| 940 | - public function extra_misc_actions_publish_box() |
|
| 941 | - { |
|
| 942 | - $this->_generate_publish_box_extra_content(); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 949 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 950 | - * data. |
|
| 951 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 952 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 953 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 954 | - * you handle this accordingly. |
|
| 955 | - * |
|
| 956 | - * @access protected |
|
| 957 | - * @abstract |
|
| 958 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 959 | - * @param object $post The post object of the cpt that was saved. |
|
| 960 | - * @return void |
|
| 961 | - */ |
|
| 962 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 963 | - { |
|
| 964 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 965 | - //get out we're not processing an event save. |
|
| 966 | - return; |
|
| 967 | - } |
|
| 968 | - $event_values = array( |
|
| 969 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 970 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 971 | - 'EVT_additional_limit' => min( |
|
| 972 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 973 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 974 | - ), |
|
| 975 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 976 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 977 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 978 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 979 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 980 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 981 | - ? $this->_req_data['timezone_string'] : null, |
|
| 982 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 983 | - ? $this->_req_data['externalURL'] : null, |
|
| 984 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 985 | - ? $this->_req_data['event_phone'] : null, |
|
| 986 | - ); |
|
| 987 | - //update event |
|
| 988 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 989 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 990 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 991 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 992 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 993 | - $event_update_callbacks = apply_filters( |
|
| 994 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 995 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 996 | - ); |
|
| 997 | - $att_success = true; |
|
| 998 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 999 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 1000 | - $att_success = ! $att_success ? $att_success |
|
| 1001 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 1002 | - } |
|
| 1003 | - //any errors? |
|
| 1004 | - if ($success && false === $att_success) { |
|
| 1005 | - EE_Error::add_error( |
|
| 1006 | - esc_html__( |
|
| 1007 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1008 | - 'event_espresso' |
|
| 1009 | - ), |
|
| 1010 | - __FILE__, |
|
| 1011 | - __FUNCTION__, |
|
| 1012 | - __LINE__ |
|
| 1013 | - ); |
|
| 1014 | - } else if ($success === false) { |
|
| 1015 | - EE_Error::add_error( |
|
| 1016 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1017 | - __FILE__, |
|
| 1018 | - __FUNCTION__, |
|
| 1019 | - __LINE__ |
|
| 1020 | - ); |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * @see parent::restore_item() |
|
| 1028 | - * @param int $post_id |
|
| 1029 | - * @param int $revision_id |
|
| 1030 | - */ |
|
| 1031 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1032 | - { |
|
| 1033 | - //copy existing event meta to new post |
|
| 1034 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1035 | - if ($post_evt instanceof EE_Event) { |
|
| 1036 | - //meta revision restore |
|
| 1037 | - $post_evt->restore_revision($revision_id); |
|
| 1038 | - //related objs restore |
|
| 1039 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * Attach the venue to the Event |
|
| 1047 | - * |
|
| 1048 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1049 | - * @param array $data The request data from the form |
|
| 1050 | - * @return bool Success or fail. |
|
| 1051 | - */ |
|
| 1052 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1053 | - { |
|
| 1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1055 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1056 | - $rows_affected = null; |
|
| 1057 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1058 | - // very important. If we don't have a venue name... |
|
| 1059 | - // then we'll get out because not necessary to create empty venue |
|
| 1060 | - if (empty($data['venue_title'])) { |
|
| 1061 | - return false; |
|
| 1062 | - } |
|
| 1063 | - $venue_array = array( |
|
| 1064 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1065 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1066 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1067 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1068 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1069 | - : null, |
|
| 1070 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1071 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1072 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1073 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1074 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1075 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1076 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1077 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1078 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1079 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1080 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1081 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1082 | - 'status' => 'publish', |
|
| 1083 | - ); |
|
| 1084 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1085 | - if ( ! empty($venue_id)) { |
|
| 1086 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1087 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1088 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1089 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | - return $rows_affected > 0 ? true : false; |
|
| 1091 | - } else { |
|
| 1092 | - //we insert the venue |
|
| 1093 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1094 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1095 | - return ! empty($venue_id) ? true : false; |
|
| 1096 | - } |
|
| 1097 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1104 | - * |
|
| 1105 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1106 | - * @param array $data The request data from the form |
|
| 1107 | - * @return array |
|
| 1108 | - */ |
|
| 1109 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1110 | - { |
|
| 1111 | - $success = true; |
|
| 1112 | - $saved_dtt = null; |
|
| 1113 | - $saved_tickets = array(); |
|
| 1114 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1115 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1116 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1117 | - $dtt = array_map('trim', $dtt); |
|
| 1118 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1119 | - : $dtt['DTT_EVT_start']; |
|
| 1120 | - $datetime_values = array( |
|
| 1121 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1122 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1123 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1124 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1125 | - 'DTT_order' => $row, |
|
| 1126 | - ); |
|
| 1127 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1128 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1129 | - $DTM = EE_Registry::instance() |
|
| 1130 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1131 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1132 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1133 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1134 | - foreach ($datetime_values as $field => $value) { |
|
| 1135 | - $DTM->set($field, $value); |
|
| 1136 | - } |
|
| 1137 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1138 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1139 | - } else { |
|
| 1140 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1141 | - 'Datetime', |
|
| 1142 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1143 | - false, |
|
| 1144 | - false |
|
| 1145 | - ); |
|
| 1146 | - foreach ($datetime_values as $field => $value) { |
|
| 1147 | - $DTM->set($field, $value); |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - $DTM->save(); |
|
| 1151 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1152 | - //load DTT helper |
|
| 1153 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1154 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1155 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1156 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1157 | - $DTT->save(); |
|
| 1158 | - } |
|
| 1159 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1160 | - $saved_dtt = $DTT; |
|
| 1161 | - $success = ! $success ? $success : $DTT; |
|
| 1162 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1163 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1164 | - } |
|
| 1165 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1166 | - //update tickets next |
|
| 1167 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1168 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1169 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | - $update_prices = false; |
|
| 1171 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1172 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1173 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1174 | - $tkt = array_map('trim', $tkt); |
|
| 1175 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1176 | - //let's use now in the set timezone. |
|
| 1177 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1179 | - } |
|
| 1180 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1181 | - //use the start date of the first datetime |
|
| 1182 | - $dtt = $evtobj->first_datetime(); |
|
| 1183 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1184 | - $incoming_date_formats[0], |
|
| 1185 | - $incoming_date_formats[1] |
|
| 1186 | - ); |
|
| 1187 | - } |
|
| 1188 | - $TKT_values = array( |
|
| 1189 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1190 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1191 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1192 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1193 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1194 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1195 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1196 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1197 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1198 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1199 | - 'TKT_row' => $row, |
|
| 1200 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1201 | - 'TKT_price' => $ticket_price, |
|
| 1202 | - ); |
|
| 1203 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1204 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1205 | - $TKT_values['TKT_ID'] = 0; |
|
| 1206 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1207 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1208 | - $update_prices = true; |
|
| 1209 | - } |
|
| 1210 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1211 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1212 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1213 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1214 | - $TKT = EE_Registry::instance() |
|
| 1215 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1216 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1217 | - if ($TKT instanceof EE_Ticket) { |
|
| 1218 | - $ticket_sold = $TKT->count_related( |
|
| 1219 | - 'Registration', |
|
| 1220 | - array( |
|
| 1221 | - array( |
|
| 1222 | - 'STS_ID' => array( |
|
| 1223 | - 'NOT IN', |
|
| 1224 | - array(EEM_Registration::status_id_incomplete), |
|
| 1225 | - ), |
|
| 1226 | - ), |
|
| 1227 | - ) |
|
| 1228 | - ) > 0 ? true : false; |
|
| 1229 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1230 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1231 | - && ! $TKT->get( |
|
| 1232 | - 'TKT_deleted' |
|
| 1233 | - ) ? true : false; |
|
| 1234 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1235 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1236 | - //set new values |
|
| 1237 | - foreach ($TKT_values as $field => $value) { |
|
| 1238 | - if ($field == 'TKT_qty') { |
|
| 1239 | - $TKT->set_qty($value); |
|
| 1240 | - } else { |
|
| 1241 | - $TKT->set($field, $value); |
|
| 1242 | - } |
|
| 1243 | - } |
|
| 1244 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1245 | - if ($create_new_TKT) { |
|
| 1246 | - //archive the old ticket first |
|
| 1247 | - $TKT->set('TKT_deleted', 1); |
|
| 1248 | - $TKT->save(); |
|
| 1249 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1250 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1251 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1252 | - $TKT = clone $TKT; |
|
| 1253 | - $TKT->set('TKT_ID', 0); |
|
| 1254 | - $TKT->set('TKT_deleted', 0); |
|
| 1255 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1256 | - $TKT->set('TKT_sold', 0); |
|
| 1257 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1258 | - $update_prices = true; |
|
| 1259 | - } |
|
| 1260 | - //make sure price is set if it hasn't been already |
|
| 1261 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1262 | - } |
|
| 1263 | - } else { |
|
| 1264 | - //no TKT_id so a new TKT |
|
| 1265 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1266 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1267 | - if ($TKT instanceof EE_Ticket) { |
|
| 1268 | - //need to reset values to properly account for the date formats |
|
| 1269 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1270 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1271 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1272 | - //set new values |
|
| 1273 | - foreach ($TKT_values as $field => $value) { |
|
| 1274 | - if ($field == 'TKT_qty') { |
|
| 1275 | - $TKT->set_qty($value); |
|
| 1276 | - } else { |
|
| 1277 | - $TKT->set($field, $value); |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - $update_prices = true; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - // cap ticket qty by datetime reg limits |
|
| 1284 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1285 | - //update ticket. |
|
| 1286 | - $TKT->save(); |
|
| 1287 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1288 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1289 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1290 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1291 | - $TKT->save(); |
|
| 1292 | - } |
|
| 1293 | - //initially let's add the ticket to the dtt |
|
| 1294 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1295 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1296 | - //add prices to ticket |
|
| 1297 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1298 | - } |
|
| 1299 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1300 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1301 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1302 | - foreach ($tickets_removed as $id) { |
|
| 1303 | - $id = absint($id); |
|
| 1304 | - //get the ticket for this id |
|
| 1305 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1306 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1307 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1308 | - foreach ($dtts as $dtt) { |
|
| 1309 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1310 | - } |
|
| 1311 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1312 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1313 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1314 | - $tkt_to_remove->delete_permanently(); |
|
| 1315 | - } |
|
| 1316 | - return array($saved_dtt, $saved_tickets); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * This attaches a list of given prices to a ticket. |
|
| 1323 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1324 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1325 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1326 | - * |
|
| 1327 | - * @access private |
|
| 1328 | - * @param array $prices Array of prices from the form. |
|
| 1329 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1330 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1331 | - * @return void |
|
| 1332 | - */ |
|
| 1333 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1334 | - { |
|
| 1335 | - foreach ($prices as $row => $prc) { |
|
| 1336 | - $PRC_values = array( |
|
| 1337 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1338 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1339 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1340 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1341 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1342 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1343 | - 'PRC_order' => $row, |
|
| 1344 | - ); |
|
| 1345 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1346 | - $PRC_values['PRC_ID'] = 0; |
|
| 1347 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1348 | - } else { |
|
| 1349 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1350 | - //update this price with new values |
|
| 1351 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1352 | - $PRC->set($field, $newprc); |
|
| 1353 | - } |
|
| 1354 | - $PRC->save(); |
|
| 1355 | - } |
|
| 1356 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Add in our autosave ajax handlers |
|
| 1364 | - * |
|
| 1365 | - * @return void |
|
| 1366 | - */ |
|
| 1367 | - protected function _ee_autosave_create_new() |
|
| 1368 | - { |
|
| 1369 | - // $this->_ee_autosave_edit(); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - protected function _ee_autosave_edit() |
|
| 1375 | - { |
|
| 1376 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * _generate_publish_box_extra_content |
|
| 1383 | - * |
|
| 1384 | - * @access private |
|
| 1385 | - * @return void |
|
| 1386 | - */ |
|
| 1387 | - private function _generate_publish_box_extra_content() |
|
| 1388 | - { |
|
| 1389 | - //load formatter helper |
|
| 1390 | - //args for getting related registrations |
|
| 1391 | - $approved_query_args = array( |
|
| 1392 | - array( |
|
| 1393 | - 'REG_deleted' => 0, |
|
| 1394 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1395 | - ), |
|
| 1396 | - ); |
|
| 1397 | - $not_approved_query_args = array( |
|
| 1398 | - array( |
|
| 1399 | - 'REG_deleted' => 0, |
|
| 1400 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1401 | - ), |
|
| 1402 | - ); |
|
| 1403 | - $pending_payment_query_args = array( |
|
| 1404 | - array( |
|
| 1405 | - 'REG_deleted' => 0, |
|
| 1406 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1407 | - ), |
|
| 1408 | - ); |
|
| 1409 | - // publish box |
|
| 1410 | - $publish_box_extra_args = array( |
|
| 1411 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1412 | - array( |
|
| 1413 | - 'action' => 'default', |
|
| 1414 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1415 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1416 | - ), |
|
| 1417 | - REG_ADMIN_URL |
|
| 1418 | - ), |
|
| 1419 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1420 | - array( |
|
| 1421 | - 'action' => 'default', |
|
| 1422 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1423 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1424 | - ), |
|
| 1425 | - REG_ADMIN_URL |
|
| 1426 | - ), |
|
| 1427 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1428 | - array( |
|
| 1429 | - 'action' => 'default', |
|
| 1430 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1431 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1432 | - ), |
|
| 1433 | - REG_ADMIN_URL |
|
| 1434 | - ), |
|
| 1435 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | - 'Registration', |
|
| 1437 | - $approved_query_args |
|
| 1438 | - ), |
|
| 1439 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | - 'Registration', |
|
| 1441 | - $not_approved_query_args |
|
| 1442 | - ), |
|
| 1443 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1444 | - 'Registration', |
|
| 1445 | - $pending_payment_query_args |
|
| 1446 | - ), |
|
| 1447 | - 'misc_pub_section_class' => apply_filters( |
|
| 1448 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1449 | - 'misc-pub-section' |
|
| 1450 | - ), |
|
| 1451 | - //'email_attendees_url' => add_query_arg( |
|
| 1452 | - // array( |
|
| 1453 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1454 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1455 | - // ), |
|
| 1456 | - // 'admin.php?page=espresso_registrations' |
|
| 1457 | - //), |
|
| 1458 | - ); |
|
| 1459 | - ob_start(); |
|
| 1460 | - do_action( |
|
| 1461 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1462 | - $this->_cpt_model_obj |
|
| 1463 | - ); |
|
| 1464 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1465 | - // load template |
|
| 1466 | - EEH_Template::display_template( |
|
| 1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1468 | - $publish_box_extra_args |
|
| 1469 | - ); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * This just returns whatever is set as the _event object property |
|
| 1476 | - * //todo this will become obsolete once the models are in place |
|
| 1477 | - * |
|
| 1478 | - * @return object |
|
| 1479 | - */ |
|
| 1480 | - public function get_event_object() |
|
| 1481 | - { |
|
| 1482 | - return $this->_cpt_model_obj; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - /** METABOXES * */ |
|
| 1489 | - /** |
|
| 1490 | - * _register_event_editor_meta_boxes |
|
| 1491 | - * add all metaboxes related to the event_editor |
|
| 1492 | - * |
|
| 1493 | - * @return void |
|
| 1494 | - */ |
|
| 1495 | - protected function _register_event_editor_meta_boxes() |
|
| 1496 | - { |
|
| 1497 | - $this->verify_cpt_object(); |
|
| 1498 | - add_meta_box( |
|
| 1499 | - 'espresso_event_editor_tickets', |
|
| 1500 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1501 | - array($this, 'ticket_metabox'), |
|
| 1502 | - $this->page_slug, |
|
| 1503 | - 'normal', |
|
| 1504 | - 'high' |
|
| 1505 | - ); |
|
| 1506 | - add_meta_box( |
|
| 1507 | - 'espresso_event_editor_event_options', |
|
| 1508 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1509 | - array($this, 'registration_options_meta_box'), |
|
| 1510 | - $this->page_slug, |
|
| 1511 | - 'side', |
|
| 1512 | - 'default' |
|
| 1513 | - ); |
|
| 1514 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1515 | - // where a metabox has a related management page in the admin |
|
| 1516 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1517 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - public function ticket_metabox() |
|
| 1523 | - { |
|
| 1524 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1525 | - //defaults for template args |
|
| 1526 | - $template_args = array( |
|
| 1527 | - 'existing_datetime_ids' => '', |
|
| 1528 | - 'event_datetime_help_link' => '', |
|
| 1529 | - 'ticket_options_help_link' => '', |
|
| 1530 | - 'time' => null, |
|
| 1531 | - 'ticket_rows' => '', |
|
| 1532 | - 'existing_ticket_ids' => '', |
|
| 1533 | - 'total_ticket_rows' => 1, |
|
| 1534 | - 'ticket_js_structure' => '', |
|
| 1535 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1536 | - 'disabled' => '', |
|
| 1537 | - ); |
|
| 1538 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1539 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1540 | - /** |
|
| 1541 | - * 1. Start with retrieving Datetimes |
|
| 1542 | - * 2. Fore each datetime get related tickets |
|
| 1543 | - * 3. For each ticket get related prices |
|
| 1544 | - */ |
|
| 1545 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1546 | - /** @type EE_Datetime $first_datetime */ |
|
| 1547 | - $first_datetime = reset($times); |
|
| 1548 | - //do we get related tickets? |
|
| 1549 | - if ($first_datetime instanceof EE_Datetime |
|
| 1550 | - && $first_datetime->ID() !== 0 |
|
| 1551 | - ) { |
|
| 1552 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1553 | - $template_args['time'] = $first_datetime; |
|
| 1554 | - $related_tickets = $first_datetime->tickets( |
|
| 1555 | - array( |
|
| 1556 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1557 | - 'default_where_conditions' => 'none', |
|
| 1558 | - ) |
|
| 1559 | - ); |
|
| 1560 | - if ( ! empty($related_tickets)) { |
|
| 1561 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1562 | - $row = 0; |
|
| 1563 | - foreach ($related_tickets as $ticket) { |
|
| 1564 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1565 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1566 | - $row++; |
|
| 1567 | - } |
|
| 1568 | - } else { |
|
| 1569 | - $template_args['total_ticket_rows'] = 1; |
|
| 1570 | - /** @type EE_Ticket $ticket */ |
|
| 1571 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1572 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1573 | - } |
|
| 1574 | - } else { |
|
| 1575 | - $template_args['time'] = $times[0]; |
|
| 1576 | - /** @type EE_Ticket $ticket */ |
|
| 1577 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1578 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1579 | - // NOTE: we're just sending the first default row |
|
| 1580 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1581 | - } |
|
| 1582 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1583 | - 'event_editor_event_datetimes_help_tab' |
|
| 1584 | - ); |
|
| 1585 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1586 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1587 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1588 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1589 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1590 | - true |
|
| 1591 | - ); |
|
| 1592 | - $template = apply_filters( |
|
| 1593 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1595 | - ); |
|
| 1596 | - EEH_Template::display_template($template, $template_args); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - /** |
|
| 1602 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1603 | - * |
|
| 1604 | - * @access private |
|
| 1605 | - * @param EE_Ticket $ticket the ticket object |
|
| 1606 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1607 | - * @param int $row |
|
| 1608 | - * @return string generated html for the ticket row. |
|
| 1609 | - */ |
|
| 1610 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1611 | - { |
|
| 1612 | - $template_args = array( |
|
| 1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1614 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1615 | - : '', |
|
| 1616 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1617 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1618 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1619 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1620 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1621 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1622 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1623 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1624 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1625 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1626 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1627 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1628 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1629 | - : ' disabled=disabled', |
|
| 1630 | - ); |
|
| 1631 | - $price = $ticket->ID() !== 0 |
|
| 1632 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1633 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1634 | - $price_args = array( |
|
| 1635 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1636 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1637 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1638 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1639 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1640 | - ); |
|
| 1641 | - //make sure we have default start and end dates if skeleton |
|
| 1642 | - //handle rows that should NOT be empty |
|
| 1643 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1644 | - //if empty then the start date will be now. |
|
| 1645 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1646 | - } |
|
| 1647 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1648 | - //get the earliest datetime (if present); |
|
| 1649 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1650 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1651 | - 'Datetime', |
|
| 1652 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1653 | - ) |
|
| 1654 | - : null; |
|
| 1655 | - if ( ! empty($earliest_dtt)) { |
|
| 1656 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1657 | - } else { |
|
| 1658 | - $template_args['TKT_end_date'] = date( |
|
| 1659 | - 'Y-m-d h:i a', |
|
| 1660 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1661 | - ); |
|
| 1662 | - } |
|
| 1663 | - } |
|
| 1664 | - $template_args = array_merge($template_args, $price_args); |
|
| 1665 | - $template = apply_filters( |
|
| 1666 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | - $ticket |
|
| 1669 | - ); |
|
| 1670 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - public function registration_options_meta_box() |
|
| 1676 | - { |
|
| 1677 | - $yes_no_values = array( |
|
| 1678 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1679 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1680 | - ); |
|
| 1681 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1682 | - array( |
|
| 1683 | - EEM_Registration::status_id_cancelled, |
|
| 1684 | - EEM_Registration::status_id_declined, |
|
| 1685 | - EEM_Registration::status_id_incomplete, |
|
| 1686 | - ), |
|
| 1687 | - true |
|
| 1688 | - ); |
|
| 1689 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1690 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1691 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1692 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1693 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1694 | - 'default_reg_status', |
|
| 1695 | - $default_reg_status_values, |
|
| 1696 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1697 | - ); |
|
| 1698 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1699 | - 'display_desc', |
|
| 1700 | - $yes_no_values, |
|
| 1701 | - $this->_cpt_model_obj->display_description() |
|
| 1702 | - ); |
|
| 1703 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1704 | - 'display_ticket_selector', |
|
| 1705 | - $yes_no_values, |
|
| 1706 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1707 | - '', |
|
| 1708 | - '', |
|
| 1709 | - false |
|
| 1710 | - ); |
|
| 1711 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1712 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1713 | - '', |
|
| 1714 | - $template_args, |
|
| 1715 | - $yes_no_values, |
|
| 1716 | - $default_reg_status_values |
|
| 1717 | - ); |
|
| 1718 | - EEH_Template::display_template( |
|
| 1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1720 | - $template_args |
|
| 1721 | - ); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * _get_events() |
|
| 1728 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1729 | - * |
|
| 1730 | - * @access public |
|
| 1731 | - * @param int $per_page count of items per page (20 default); |
|
| 1732 | - * @param int $current_page what is the current page being viewed. |
|
| 1733 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1734 | - * If FALSE then we return an array of event objects |
|
| 1735 | - * that match the given _view and paging parameters. |
|
| 1736 | - * @return array an array of event objects. |
|
| 1737 | - */ |
|
| 1738 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1739 | - { |
|
| 1740 | - $EEME = $this->_event_model(); |
|
| 1741 | - $offset = ($current_page - 1) * $per_page; |
|
| 1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1743 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1744 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1745 | - if (isset($this->_req_data['month_range'])) { |
|
| 1746 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1747 | - //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1748 | - //where PHP doesn't know what to assume for date. |
|
| 1749 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1750 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1751 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1752 | - } |
|
| 1753 | - $where = array(); |
|
| 1754 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1755 | - //determine what post_status our condition will have for the query. |
|
| 1756 | - switch ($status) { |
|
| 1757 | - case 'month' : |
|
| 1758 | - case 'today' : |
|
| 1759 | - case null : |
|
| 1760 | - case 'all' : |
|
| 1761 | - break; |
|
| 1762 | - case 'draft' : |
|
| 1763 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1764 | - break; |
|
| 1765 | - default : |
|
| 1766 | - $where['status'] = $status; |
|
| 1767 | - } |
|
| 1768 | - //categories? |
|
| 1769 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1770 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1771 | - if ( ! empty ($category)) { |
|
| 1772 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1773 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1774 | - } |
|
| 1775 | - //date where conditions |
|
| 1776 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1777 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1778 | - $DateTime = new DateTime( |
|
| 1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1780 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1781 | - ); |
|
| 1782 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1783 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1784 | - ->format('t'))->setTime(23, 59, 59) |
|
| 1785 | - ->format(implode(' ', $start_formats)); |
|
| 1786 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1787 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1788 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1789 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1790 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1791 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1793 | - $now = date('Y-m-01'); |
|
| 1794 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1795 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1796 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1797 | - ->setTime(23, 59, 59) |
|
| 1798 | - ->format(implode(' ', $start_formats)); |
|
| 1799 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1800 | - } |
|
| 1801 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1802 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1803 | - } else { |
|
| 1804 | - if ( ! isset($where['status'])) { |
|
| 1805 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1806 | - $where['OR'] = array( |
|
| 1807 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1808 | - 'AND' => array( |
|
| 1809 | - 'status*inclusive' => array('=', 'private'), |
|
| 1810 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1811 | - ), |
|
| 1812 | - ); |
|
| 1813 | - } |
|
| 1814 | - } |
|
| 1815 | - } |
|
| 1816 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1817 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1818 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1819 | - ) { |
|
| 1820 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1821 | - } |
|
| 1822 | - } |
|
| 1823 | - //search query handling |
|
| 1824 | - if (isset($this->_req_data['s'])) { |
|
| 1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1826 | - $where['OR'] = array( |
|
| 1827 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1828 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1829 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1830 | - ); |
|
| 1831 | - } |
|
| 1832 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1833 | - $query_params = apply_filters( |
|
| 1834 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1835 | - array( |
|
| 1836 | - $where, |
|
| 1837 | - 'limit' => $limit, |
|
| 1838 | - 'order_by' => $orderby, |
|
| 1839 | - 'order' => $order, |
|
| 1840 | - 'group_by' => 'EVT_ID', |
|
| 1841 | - ), |
|
| 1842 | - $this->_req_data |
|
| 1843 | - ); |
|
| 1844 | - //let's first check if we have special requests coming in. |
|
| 1845 | - if (isset($this->_req_data['active_status'])) { |
|
| 1846 | - switch ($this->_req_data['active_status']) { |
|
| 1847 | - case 'upcoming' : |
|
| 1848 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1849 | - break; |
|
| 1850 | - case 'expired' : |
|
| 1851 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1852 | - break; |
|
| 1853 | - case 'active' : |
|
| 1854 | - return $EEME->get_active_events($query_params, $count); |
|
| 1855 | - break; |
|
| 1856 | - case 'inactive' : |
|
| 1857 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1858 | - break; |
|
| 1859 | - } |
|
| 1860 | - } |
|
| 1861 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1862 | - return $events; |
|
| 1863 | - } |
|
| 1864 | - |
|
| 1865 | - |
|
| 1866 | - |
|
| 1867 | - /** |
|
| 1868 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1869 | - * |
|
| 1870 | - * @param string $post_id |
|
| 1871 | - */ |
|
| 1872 | - public function trash_cpt_item($post_id) |
|
| 1873 | - { |
|
| 1874 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1875 | - $this->_trash_or_restore_event('trash', false); |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * @param string $post_id |
|
| 1882 | - */ |
|
| 1883 | - public function restore_cpt_item($post_id) |
|
| 1884 | - { |
|
| 1885 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1886 | - $this->_trash_or_restore_event('draft', false); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - |
|
| 1890 | - |
|
| 1891 | - /** |
|
| 1892 | - * @param string $post_id |
|
| 1893 | - */ |
|
| 1894 | - public function delete_cpt_item($post_id) |
|
| 1895 | - { |
|
| 1896 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1897 | - $this->_delete_event(false); |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * _trash_or_restore_event |
|
| 1904 | - * |
|
| 1905 | - * @access protected |
|
| 1906 | - * @param string $event_status |
|
| 1907 | - * @param bool $redirect_after |
|
| 1908 | - */ |
|
| 1909 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1910 | - { |
|
| 1911 | - //determine the event id and set to array. |
|
| 1912 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1913 | - // loop thru events |
|
| 1914 | - if ($EVT_ID) { |
|
| 1915 | - // clean status |
|
| 1916 | - $event_status = sanitize_key($event_status); |
|
| 1917 | - // grab status |
|
| 1918 | - if ( ! empty($event_status)) { |
|
| 1919 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1920 | - } else { |
|
| 1921 | - $success = false; |
|
| 1922 | - $msg = esc_html__( |
|
| 1923 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1924 | - 'event_espresso' |
|
| 1925 | - ); |
|
| 1926 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | - } |
|
| 1928 | - } else { |
|
| 1929 | - $success = false; |
|
| 1930 | - $msg = esc_html__( |
|
| 1931 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1932 | - 'event_espresso' |
|
| 1933 | - ); |
|
| 1934 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1935 | - } |
|
| 1936 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1937 | - if ($redirect_after) { |
|
| 1938 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1939 | - } |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * _trash_or_restore_events |
|
| 1946 | - * |
|
| 1947 | - * @access protected |
|
| 1948 | - * @param string $event_status |
|
| 1949 | - * @return void |
|
| 1950 | - */ |
|
| 1951 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1952 | - { |
|
| 1953 | - // clean status |
|
| 1954 | - $event_status = sanitize_key($event_status); |
|
| 1955 | - // grab status |
|
| 1956 | - if ( ! empty($event_status)) { |
|
| 1957 | - $success = true; |
|
| 1958 | - //determine the event id and set to array. |
|
| 1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | - // loop thru events |
|
| 1961 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1962 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1963 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1964 | - $success = $results !== false ? $success : false; |
|
| 1965 | - } else { |
|
| 1966 | - $msg = sprintf( |
|
| 1967 | - esc_html__( |
|
| 1968 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1969 | - 'event_espresso' |
|
| 1970 | - ), |
|
| 1971 | - $EVT_ID |
|
| 1972 | - ); |
|
| 1973 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1974 | - $success = false; |
|
| 1975 | - } |
|
| 1976 | - } |
|
| 1977 | - } else { |
|
| 1978 | - $success = false; |
|
| 1979 | - $msg = esc_html__( |
|
| 1980 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1981 | - 'event_espresso' |
|
| 1982 | - ); |
|
| 1983 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1984 | - } |
|
| 1985 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1986 | - $success = $success ? 2 : false; |
|
| 1987 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1988 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * _trash_or_restore_events |
|
| 1995 | - * |
|
| 1996 | - * @access private |
|
| 1997 | - * @param int $EVT_ID |
|
| 1998 | - * @param string $event_status |
|
| 1999 | - * @return bool |
|
| 2000 | - */ |
|
| 2001 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2002 | - { |
|
| 2003 | - // grab event id |
|
| 2004 | - if ( ! $EVT_ID) { |
|
| 2005 | - $msg = esc_html__( |
|
| 2006 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2007 | - 'event_espresso' |
|
| 2008 | - ); |
|
| 2009 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2010 | - return false; |
|
| 2011 | - } |
|
| 2012 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2013 | - // clean status |
|
| 2014 | - $event_status = sanitize_key($event_status); |
|
| 2015 | - // grab status |
|
| 2016 | - if (empty($event_status)) { |
|
| 2017 | - $msg = esc_html__( |
|
| 2018 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2019 | - 'event_espresso' |
|
| 2020 | - ); |
|
| 2021 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2022 | - return false; |
|
| 2023 | - } |
|
| 2024 | - // was event trashed or restored ? |
|
| 2025 | - switch ($event_status) { |
|
| 2026 | - case 'draft' : |
|
| 2027 | - $action = 'restored from the trash'; |
|
| 2028 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2029 | - break; |
|
| 2030 | - case 'trash' : |
|
| 2031 | - $action = 'moved to the trash'; |
|
| 2032 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2033 | - break; |
|
| 2034 | - default : |
|
| 2035 | - $action = 'updated'; |
|
| 2036 | - $hook = false; |
|
| 2037 | - } |
|
| 2038 | - //use class to change status |
|
| 2039 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2040 | - $success = $this->_cpt_model_obj->save(); |
|
| 2041 | - if ($success === false) { |
|
| 2042 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2043 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2044 | - return false; |
|
| 2045 | - } |
|
| 2046 | - if ($hook) { |
|
| 2047 | - do_action($hook); |
|
| 2048 | - } |
|
| 2049 | - return true; |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * _delete_event |
|
| 2056 | - * |
|
| 2057 | - * @access protected |
|
| 2058 | - * @param bool $redirect_after |
|
| 2059 | - */ |
|
| 2060 | - protected function _delete_event($redirect_after = true) |
|
| 2061 | - { |
|
| 2062 | - //determine the event id and set to array. |
|
| 2063 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2064 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2065 | - // loop thru events |
|
| 2066 | - if ($EVT_ID) { |
|
| 2067 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2068 | - // get list of events with no prices |
|
| 2069 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2070 | - // remove this event from the list of events with no prices |
|
| 2071 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2072 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2073 | - } |
|
| 2074 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2075 | - } else { |
|
| 2076 | - $success = false; |
|
| 2077 | - $msg = esc_html__( |
|
| 2078 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2079 | - 'event_espresso' |
|
| 2080 | - ); |
|
| 2081 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2082 | - } |
|
| 2083 | - if ($redirect_after) { |
|
| 2084 | - $this->_redirect_after_action( |
|
| 2085 | - $success, |
|
| 2086 | - 'Event', |
|
| 2087 | - 'deleted', |
|
| 2088 | - array('action' => 'default', 'status' => 'trash') |
|
| 2089 | - ); |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - |
|
| 2094 | - |
|
| 2095 | - /** |
|
| 2096 | - * _delete_events |
|
| 2097 | - * |
|
| 2098 | - * @access protected |
|
| 2099 | - * @return void |
|
| 2100 | - */ |
|
| 2101 | - protected function _delete_events() |
|
| 2102 | - { |
|
| 2103 | - $success = true; |
|
| 2104 | - // get list of events with no prices |
|
| 2105 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2106 | - //determine the event id and set to array. |
|
| 2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | - // loop thru events |
|
| 2109 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2110 | - $EVT_ID = absint($EVT_ID); |
|
| 2111 | - if ($EVT_ID) { |
|
| 2112 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2113 | - $success = $results !== false ? $success : false; |
|
| 2114 | - // remove this event from the list of events with no prices |
|
| 2115 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2116 | - } else { |
|
| 2117 | - $success = false; |
|
| 2118 | - $msg = esc_html__( |
|
| 2119 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2120 | - 'event_espresso' |
|
| 2121 | - ); |
|
| 2122 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | - } |
|
| 2124 | - } |
|
| 2125 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2126 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2127 | - $success = $success ? 2 : false; |
|
| 2128 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - |
|
| 2132 | - |
|
| 2133 | - /** |
|
| 2134 | - * _permanently_delete_event |
|
| 2135 | - * |
|
| 2136 | - * @access private |
|
| 2137 | - * @param int $EVT_ID |
|
| 2138 | - * @return bool |
|
| 2139 | - */ |
|
| 2140 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2141 | - { |
|
| 2142 | - // grab event id |
|
| 2143 | - if ( ! $EVT_ID) { |
|
| 2144 | - $msg = esc_html__( |
|
| 2145 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2146 | - 'event_espresso' |
|
| 2147 | - ); |
|
| 2148 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2149 | - return false; |
|
| 2150 | - } |
|
| 2151 | - if ( |
|
| 2152 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2153 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2154 | - ) { |
|
| 2155 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2156 | - } |
|
| 2157 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2158 | - return false; |
|
| 2159 | - } |
|
| 2160 | - //need to delete related tickets and prices first. |
|
| 2161 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2162 | - foreach ($datetimes as $datetime) { |
|
| 2163 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2164 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2165 | - foreach ($tickets as $ticket) { |
|
| 2166 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2167 | - $ticket->delete_related_permanently('Price'); |
|
| 2168 | - $ticket->delete_permanently(); |
|
| 2169 | - } |
|
| 2170 | - $datetime->delete(); |
|
| 2171 | - } |
|
| 2172 | - //what about related venues or terms? |
|
| 2173 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2174 | - foreach ($venues as $venue) { |
|
| 2175 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2176 | - } |
|
| 2177 | - //any attached question groups? |
|
| 2178 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2179 | - if ( ! empty($question_groups)) { |
|
| 2180 | - foreach ($question_groups as $question_group) { |
|
| 2181 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2182 | - } |
|
| 2183 | - } |
|
| 2184 | - //Message Template Groups |
|
| 2185 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2186 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2187 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2188 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2189 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2190 | - } |
|
| 2191 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2192 | - // did it all go as planned ? |
|
| 2193 | - if ($success) { |
|
| 2194 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2195 | - EE_Error::add_success($msg); |
|
| 2196 | - } else { |
|
| 2197 | - $msg = sprintf( |
|
| 2198 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2199 | - $EVT_ID |
|
| 2200 | - ); |
|
| 2201 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2202 | - return false; |
|
| 2203 | - } |
|
| 2204 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2205 | - return true; |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - |
|
| 2209 | - |
|
| 2210 | - /** |
|
| 2211 | - * get total number of events |
|
| 2212 | - * |
|
| 2213 | - * @access public |
|
| 2214 | - * @return int |
|
| 2215 | - */ |
|
| 2216 | - public function total_events() |
|
| 2217 | - { |
|
| 2218 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2219 | - return $count; |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - |
|
| 2223 | - |
|
| 2224 | - /** |
|
| 2225 | - * get total number of draft events |
|
| 2226 | - * |
|
| 2227 | - * @access public |
|
| 2228 | - * @return int |
|
| 2229 | - */ |
|
| 2230 | - public function total_events_draft() |
|
| 2231 | - { |
|
| 2232 | - $where = array( |
|
| 2233 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2234 | - ); |
|
| 2235 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2236 | - return $count; |
|
| 2237 | - } |
|
| 2238 | - |
|
| 2239 | - |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * get total number of trashed events |
|
| 2243 | - * |
|
| 2244 | - * @access public |
|
| 2245 | - * @return int |
|
| 2246 | - */ |
|
| 2247 | - public function total_trashed_events() |
|
| 2248 | - { |
|
| 2249 | - $where = array( |
|
| 2250 | - 'status' => 'trash', |
|
| 2251 | - ); |
|
| 2252 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2253 | - return $count; |
|
| 2254 | - } |
|
| 2255 | - |
|
| 2256 | - |
|
| 2257 | - /** |
|
| 2258 | - * _default_event_settings |
|
| 2259 | - * This generates the Default Settings Tab |
|
| 2260 | - * |
|
| 2261 | - * @return void |
|
| 2262 | - * @throws \EE_Error |
|
| 2263 | - */ |
|
| 2264 | - protected function _default_event_settings() |
|
| 2265 | - { |
|
| 2266 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2267 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2268 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2269 | - $this->display_admin_page_with_sidebar(); |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - |
|
| 2273 | - /** |
|
| 2274 | - * Return the form for event settings. |
|
| 2275 | - * @return \EE_Form_Section_Proper |
|
| 2276 | - */ |
|
| 2277 | - protected function _default_event_settings_form() |
|
| 2278 | - { |
|
| 2279 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2280 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2281 | - //exclude |
|
| 2282 | - array( |
|
| 2283 | - EEM_Registration::status_id_cancelled, |
|
| 2284 | - EEM_Registration::status_id_declined, |
|
| 2285 | - EEM_Registration::status_id_incomplete, |
|
| 2286 | - EEM_Registration::status_id_wait_list, |
|
| 2287 | - ), |
|
| 2288 | - true |
|
| 2289 | - ); |
|
| 2290 | - return new EE_Form_Section_Proper( |
|
| 2291 | - array( |
|
| 2292 | - 'name' => 'update_default_event_settings', |
|
| 2293 | - 'html_id' => 'update_default_event_settings', |
|
| 2294 | - 'html_class' => 'form-table', |
|
| 2295 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2296 | - 'subsections' => apply_filters( |
|
| 2297 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2298 | - array( |
|
| 2299 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2300 | - $registration_stati_for_selection, |
|
| 2301 | - array( |
|
| 2302 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2303 | - && array_key_exists( |
|
| 2304 | - $registration_config->default_STS_ID, |
|
| 2305 | - $registration_stati_for_selection |
|
| 2306 | - ) |
|
| 2307 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2308 | - : EEM_Registration::status_id_pending_payment, |
|
| 2309 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2310 | - . EEH_Template::get_help_tab_link( |
|
| 2311 | - 'default_settings_status_help_tab' |
|
| 2312 | - ), |
|
| 2313 | - 'html_help_text' => esc_html__( |
|
| 2314 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2315 | - 'event_espresso' |
|
| 2316 | - ) |
|
| 2317 | - ) |
|
| 2318 | - ), |
|
| 2319 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2320 | - array( |
|
| 2321 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2322 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2323 | - : EEM_Event::get_default_additional_limit(), |
|
| 2324 | - 'html_label_text' => esc_html__( |
|
| 2325 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2326 | - 'event_espresso' |
|
| 2327 | - ) . EEH_Template::get_help_tab_link( |
|
| 2328 | - 'default_maximum_tickets_help_tab"' |
|
| 2329 | - ), |
|
| 2330 | - 'html_help_text' => esc_html__( |
|
| 2331 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2332 | - 'event_espresso' |
|
| 2333 | - ) |
|
| 2334 | - ) |
|
| 2335 | - ) |
|
| 2336 | - ) |
|
| 2337 | - ) |
|
| 2338 | - ) |
|
| 2339 | - ); |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - |
|
| 2343 | - /** |
|
| 2344 | - * _update_default_event_settings |
|
| 2345 | - * |
|
| 2346 | - * @access protected |
|
| 2347 | - * @return void |
|
| 2348 | - * @throws \EE_Error |
|
| 2349 | - */ |
|
| 2350 | - protected function _update_default_event_settings() |
|
| 2351 | - { |
|
| 2352 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2353 | - $form = $this->_default_event_settings_form(); |
|
| 2354 | - if ($form->was_submitted()) { |
|
| 2355 | - $form->receive_form_submission(); |
|
| 2356 | - if ($form->is_valid()) { |
|
| 2357 | - $valid_data = $form->valid_data(); |
|
| 2358 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2359 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2360 | - } |
|
| 2361 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2362 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2363 | - } |
|
| 2364 | - //update because data was valid! |
|
| 2365 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2366 | - EE_Error::overwrite_success(); |
|
| 2367 | - EE_Error::add_success( |
|
| 2368 | - __('Default Event Settings were updated', 'event_espresso') |
|
| 2369 | - ); |
|
| 2370 | - } |
|
| 2371 | - } |
|
| 2372 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - |
|
| 2377 | - /************* Templates *************/ |
|
| 2378 | - protected function _template_settings() |
|
| 2379 | - { |
|
| 2380 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2381 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2382 | - . EVENTS_ASSETS_URL |
|
| 2383 | - . DS |
|
| 2384 | - . 'images' |
|
| 2385 | - . DS |
|
| 2386 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2387 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2388 | - . '" />'; |
|
| 2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2390 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2391 | - 'event_espresso' |
|
| 2392 | - ) . '</strong>'; |
|
| 2393 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2394 | - } |
|
| 2395 | - |
|
| 2396 | - |
|
| 2397 | - /** Event Category Stuff **/ |
|
| 2398 | - /** |
|
| 2399 | - * set the _category property with the category object for the loaded page. |
|
| 2400 | - * |
|
| 2401 | - * @access private |
|
| 2402 | - * @return void |
|
| 2403 | - */ |
|
| 2404 | - private function _set_category_object() |
|
| 2405 | - { |
|
| 2406 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2407 | - return; |
|
| 2408 | - } //already have the category object so get out. |
|
| 2409 | - //set default category object |
|
| 2410 | - $this->_set_empty_category_object(); |
|
| 2411 | - //only set if we've got an id |
|
| 2412 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2413 | - return; |
|
| 2414 | - } |
|
| 2415 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2416 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2417 | - if ( ! empty($term)) { |
|
| 2418 | - $this->_category->category_name = $term->name; |
|
| 2419 | - $this->_category->category_identifier = $term->slug; |
|
| 2420 | - $this->_category->category_desc = $term->description; |
|
| 2421 | - $this->_category->id = $term->term_id; |
|
| 2422 | - $this->_category->parent = $term->parent; |
|
| 2423 | - } |
|
| 2424 | - } |
|
| 2425 | - |
|
| 2426 | - |
|
| 2427 | - |
|
| 2428 | - private function _set_empty_category_object() |
|
| 2429 | - { |
|
| 2430 | - $this->_category = new stdClass(); |
|
| 2431 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2432 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2433 | - } |
|
| 2434 | - |
|
| 2435 | - |
|
| 2436 | - |
|
| 2437 | - protected function _category_list_table() |
|
| 2438 | - { |
|
| 2439 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2440 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2442 | - 'add_category', |
|
| 2443 | - 'add_category', |
|
| 2444 | - array(), |
|
| 2445 | - 'add-new-h2' |
|
| 2446 | - ); |
|
| 2447 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * @param $view |
|
| 2454 | - */ |
|
| 2455 | - protected function _category_details($view) |
|
| 2456 | - { |
|
| 2457 | - //load formatter helper |
|
| 2458 | - //load field generator helper |
|
| 2459 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2460 | - $this->_set_add_edit_form_tags($route); |
|
| 2461 | - $this->_set_category_object(); |
|
| 2462 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2463 | - $delete_action = 'delete_category'; |
|
| 2464 | - //custom redirect |
|
| 2465 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2466 | - array('action' => 'category_list'), |
|
| 2467 | - $this->_admin_base_url |
|
| 2468 | - ); |
|
| 2469 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2470 | - //take care of contents |
|
| 2471 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2472 | - $this->display_admin_page_with_sidebar(); |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - |
|
| 2476 | - |
|
| 2477 | - /** |
|
| 2478 | - * @return mixed |
|
| 2479 | - */ |
|
| 2480 | - protected function _category_details_content() |
|
| 2481 | - { |
|
| 2482 | - $editor_args['category_desc'] = array( |
|
| 2483 | - 'type' => 'wp_editor', |
|
| 2484 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2485 | - 'class' => 'my_editor_custom', |
|
| 2486 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2487 | - ); |
|
| 2488 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2489 | - $all_terms = get_terms( |
|
| 2490 | - array('espresso_event_categories'), |
|
| 2491 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2492 | - ); |
|
| 2493 | - //setup category select for term parents. |
|
| 2494 | - $category_select_values[] = array( |
|
| 2495 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2496 | - 'id' => 0, |
|
| 2497 | - ); |
|
| 2498 | - foreach ($all_terms as $term) { |
|
| 2499 | - $category_select_values[] = array( |
|
| 2500 | - 'text' => $term->name, |
|
| 2501 | - 'id' => $term->term_id, |
|
| 2502 | - ); |
|
| 2503 | - } |
|
| 2504 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2505 | - 'category_parent', |
|
| 2506 | - $category_select_values, |
|
| 2507 | - $this->_category->parent |
|
| 2508 | - ); |
|
| 2509 | - $template_args = array( |
|
| 2510 | - 'category' => $this->_category, |
|
| 2511 | - 'category_select' => $category_select, |
|
| 2512 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2513 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2514 | - 'disable' => '', |
|
| 2515 | - 'disabled_message' => false, |
|
| 2516 | - ); |
|
| 2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2518 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - |
|
| 2522 | - |
|
| 2523 | - protected function _delete_categories() |
|
| 2524 | - { |
|
| 2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | - : (array)$this->_req_data['category_id']; |
|
| 2527 | - foreach ($cat_ids as $cat_id) { |
|
| 2528 | - $this->_delete_category($cat_id); |
|
| 2529 | - } |
|
| 2530 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2531 | - $query_args = array( |
|
| 2532 | - 'action' => 'category_list', |
|
| 2533 | - ); |
|
| 2534 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - /** |
|
| 2540 | - * @param $cat_id |
|
| 2541 | - */ |
|
| 2542 | - protected function _delete_category($cat_id) |
|
| 2543 | - { |
|
| 2544 | - $cat_id = absint($cat_id); |
|
| 2545 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - /** |
|
| 2551 | - * @param $new_category |
|
| 2552 | - */ |
|
| 2553 | - protected function _insert_or_update_category($new_category) |
|
| 2554 | - { |
|
| 2555 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2556 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2557 | - if ($cat_id) { |
|
| 2558 | - $query_args = array( |
|
| 2559 | - 'action' => 'edit_category', |
|
| 2560 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2561 | - ); |
|
| 2562 | - } else { |
|
| 2563 | - $query_args = array('action' => 'add_category'); |
|
| 2564 | - } |
|
| 2565 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * @param bool $update |
|
| 2572 | - * @return bool|mixed|string |
|
| 2573 | - */ |
|
| 2574 | - private function _insert_category($update = false) |
|
| 2575 | - { |
|
| 2576 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2577 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2578 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2579 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2580 | - if (empty($category_name)) { |
|
| 2581 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2582 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2583 | - return false; |
|
| 2584 | - } |
|
| 2585 | - $term_args = array( |
|
| 2586 | - 'name' => $category_name, |
|
| 2587 | - 'description' => $category_desc, |
|
| 2588 | - 'parent' => $category_parent, |
|
| 2589 | - ); |
|
| 2590 | - //was the category_identifier input disabled? |
|
| 2591 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2592 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2593 | - } |
|
| 2594 | - $insert_ids = $update |
|
| 2595 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2596 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2597 | - if ( ! is_array($insert_ids)) { |
|
| 2598 | - $msg = esc_html__( |
|
| 2599 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2600 | - 'event_espresso' |
|
| 2601 | - ); |
|
| 2602 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2603 | - } else { |
|
| 2604 | - $cat_id = $insert_ids['term_id']; |
|
| 2605 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2606 | - EE_Error::add_success($msg); |
|
| 2607 | - } |
|
| 2608 | - return $cat_id; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * @param int $per_page |
|
| 2615 | - * @param int $current_page |
|
| 2616 | - * @param bool $count |
|
| 2617 | - * @return \EE_Base_Class[]|int |
|
| 2618 | - */ |
|
| 2619 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2620 | - { |
|
| 2621 | - //testing term stuff |
|
| 2622 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2623 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2624 | - $limit = ($current_page - 1) * $per_page; |
|
| 2625 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2626 | - if (isset($this->_req_data['s'])) { |
|
| 2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2628 | - $where['OR'] = array( |
|
| 2629 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2630 | - 'description' => array('LIKE', $sstr), |
|
| 2631 | - ); |
|
| 2632 | - } |
|
| 2633 | - $query_params = array( |
|
| 2634 | - $where, |
|
| 2635 | - 'order_by' => array($orderby => $order), |
|
| 2636 | - 'limit' => $limit . ',' . $per_page, |
|
| 2637 | - 'force_join' => array('Term'), |
|
| 2638 | - ); |
|
| 2639 | - $categories = $count |
|
| 2640 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2641 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2642 | - return $categories; |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - |
|
| 2646 | - |
|
| 2647 | - /* end category stuff */ |
|
| 2648 | - /**************/ |
|
| 385 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | + 'require_nonce' => false, |
|
| 387 | + ), |
|
| 388 | + 'default_event_settings' => array( |
|
| 389 | + 'nav' => array( |
|
| 390 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | + 'order' => 40, |
|
| 392 | + ), |
|
| 393 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | + 'labels' => array( |
|
| 395 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | + ), |
|
| 397 | + 'help_tabs' => array( |
|
| 398 | + 'default_settings_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | + 'filename' => 'events_default_settings', |
|
| 401 | + ), |
|
| 402 | + 'default_settings_status_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | + 'filename' => 'events_default_settings_status', |
|
| 405 | + ), |
|
| 406 | + 'default_maximum_tickets_help_tab' => array( |
|
| 407 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 408 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 409 | + ) |
|
| 410 | + ), |
|
| 411 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 412 | + 'require_nonce' => false, |
|
| 413 | + ), |
|
| 414 | + //template settings |
|
| 415 | + 'template_settings' => array( |
|
| 416 | + 'nav' => array( |
|
| 417 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 418 | + 'order' => 30, |
|
| 419 | + ), |
|
| 420 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 421 | + 'help_tabs' => array( |
|
| 422 | + 'general_settings_templates_help_tab' => array( |
|
| 423 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 424 | + 'filename' => 'general_settings_templates', |
|
| 425 | + ), |
|
| 426 | + ), |
|
| 427 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 428 | + 'require_nonce' => false, |
|
| 429 | + ), |
|
| 430 | + //event category stuff |
|
| 431 | + 'add_category' => array( |
|
| 432 | + 'nav' => array( |
|
| 433 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 434 | + 'order' => 15, |
|
| 435 | + 'persistent' => false, |
|
| 436 | + ), |
|
| 437 | + 'help_tabs' => array( |
|
| 438 | + 'add_category_help_tab' => array( |
|
| 439 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 440 | + 'filename' => 'events_add_category', |
|
| 441 | + ), |
|
| 442 | + ), |
|
| 443 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 444 | + 'metaboxes' => array('_publish_post_box'), |
|
| 445 | + 'require_nonce' => false, |
|
| 446 | + ), |
|
| 447 | + 'edit_category' => array( |
|
| 448 | + 'nav' => array( |
|
| 449 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 450 | + 'order' => 15, |
|
| 451 | + 'persistent' => false, |
|
| 452 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 453 | + ? add_query_arg( |
|
| 454 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 455 | + $this->_current_page_view_url |
|
| 456 | + ) |
|
| 457 | + : $this->_admin_base_url, |
|
| 458 | + ), |
|
| 459 | + 'help_tabs' => array( |
|
| 460 | + 'edit_category_help_tab' => array( |
|
| 461 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 462 | + 'filename' => 'events_edit_category', |
|
| 463 | + ), |
|
| 464 | + ), |
|
| 465 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 466 | + 'metaboxes' => array('_publish_post_box'), |
|
| 467 | + 'require_nonce' => false, |
|
| 468 | + ), |
|
| 469 | + 'category_list' => array( |
|
| 470 | + 'nav' => array( |
|
| 471 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 472 | + 'order' => 20, |
|
| 473 | + ), |
|
| 474 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 475 | + 'help_tabs' => array( |
|
| 476 | + 'events_categories_help_tab' => array( |
|
| 477 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 478 | + 'filename' => 'events_categories', |
|
| 479 | + ), |
|
| 480 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 481 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 482 | + 'filename' => 'events_categories_table_column_headings', |
|
| 483 | + ), |
|
| 484 | + 'events_categories_view_help_tab' => array( |
|
| 485 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 486 | + 'filename' => 'events_categories_views', |
|
| 487 | + ), |
|
| 488 | + 'events_categories_other_help_tab' => array( |
|
| 489 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 490 | + 'filename' => 'events_categories_other', |
|
| 491 | + ), |
|
| 492 | + ), |
|
| 493 | + 'help_tour' => array( |
|
| 494 | + 'Event_Categories_Help_Tour', |
|
| 495 | + ), |
|
| 496 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 497 | + 'require_nonce' => false, |
|
| 498 | + ), |
|
| 499 | + ); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + protected function _add_screen_options() |
|
| 505 | + { |
|
| 506 | + //todo |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + protected function _add_screen_options_default() |
|
| 512 | + { |
|
| 513 | + $this->_per_page_screen_option(); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + protected function _add_screen_options_category_list() |
|
| 519 | + { |
|
| 520 | + $page_title = $this->_admin_page_title; |
|
| 521 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 522 | + $this->_per_page_screen_option(); |
|
| 523 | + $this->_admin_page_title = $page_title; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + protected function _add_feature_pointers() |
|
| 529 | + { |
|
| 530 | + //todo |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + public function load_scripts_styles() |
|
| 536 | + { |
|
| 537 | + wp_register_style( |
|
| 538 | + 'events-admin-css', |
|
| 539 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 540 | + array(), |
|
| 541 | + EVENT_ESPRESSO_VERSION |
|
| 542 | + ); |
|
| 543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | + wp_enqueue_style('events-admin-css'); |
|
| 545 | + wp_enqueue_style('ee-cat-admin'); |
|
| 546 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 547 | + //registers for all views |
|
| 548 | + //scripts |
|
| 549 | + wp_register_script( |
|
| 550 | + 'event_editor_js', |
|
| 551 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 552 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 553 | + EVENT_ESPRESSO_VERSION, |
|
| 554 | + true |
|
| 555 | + ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueuing scripts and styles specific to this view |
|
| 562 | + * |
|
| 563 | + * @return void |
|
| 564 | + */ |
|
| 565 | + public function load_scripts_styles_create_new() |
|
| 566 | + { |
|
| 567 | + $this->load_scripts_styles_edit(); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * enqueuing scripts and styles specific to this view |
|
| 574 | + * |
|
| 575 | + * @return void |
|
| 576 | + */ |
|
| 577 | + public function load_scripts_styles_edit() |
|
| 578 | + { |
|
| 579 | + //styles |
|
| 580 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 581 | + wp_register_style( |
|
| 582 | + 'event-editor-css', |
|
| 583 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 584 | + array('ee-admin-css'), |
|
| 585 | + EVENT_ESPRESSO_VERSION |
|
| 586 | + ); |
|
| 587 | + wp_enqueue_style('event-editor-css'); |
|
| 588 | + //scripts |
|
| 589 | + wp_register_script( |
|
| 590 | + 'event-datetime-metabox', |
|
| 591 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 592 | + array('event_editor_js', 'ee-datepicker'), |
|
| 593 | + EVENT_ESPRESSO_VERSION |
|
| 594 | + ); |
|
| 595 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + public function load_scripts_styles_add_category() |
|
| 601 | + { |
|
| 602 | + $this->load_scripts_styles_edit_category(); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + public function load_scripts_styles_edit_category() |
|
| 608 | + { |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + protected function _set_list_table_views_category_list() |
|
| 614 | + { |
|
| 615 | + $this->_views = array( |
|
| 616 | + 'all' => array( |
|
| 617 | + 'slug' => 'all', |
|
| 618 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 619 | + 'count' => 0, |
|
| 620 | + 'bulk_action' => array( |
|
| 621 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 622 | + ), |
|
| 623 | + ), |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + public function admin_init() |
|
| 630 | + { |
|
| 631 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 632 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 633 | + 'event_espresso' |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + //nothing needed for events with these methods. |
|
| 640 | + public function admin_notices() |
|
| 641 | + { |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + public function admin_footer_scripts() |
|
| 647 | + { |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 654 | + * warning (via EE_Error::add_error()); |
|
| 655 | + * |
|
| 656 | + * @param EE_Event $event Event object |
|
| 657 | + * @access public |
|
| 658 | + * @return void |
|
| 659 | + */ |
|
| 660 | + public function verify_event_edit($event = null) |
|
| 661 | + { |
|
| 662 | + // no event? |
|
| 663 | + if (empty($event)) { |
|
| 664 | + // set event |
|
| 665 | + $event = $this->_cpt_model_obj; |
|
| 666 | + } |
|
| 667 | + // STILL no event? |
|
| 668 | + if (empty ($event)) { |
|
| 669 | + return; |
|
| 670 | + } |
|
| 671 | + $orig_status = $event->status(); |
|
| 672 | + // first check if event is active. |
|
| 673 | + if ( |
|
| 674 | + $orig_status === EEM_Event::cancelled |
|
| 675 | + || $orig_status === EEM_Event::postponed |
|
| 676 | + || $event->is_expired() |
|
| 677 | + || $event->is_inactive() |
|
| 678 | + ) { |
|
| 679 | + return; |
|
| 680 | + } |
|
| 681 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 682 | + if ($event->is_sold_out(true)) { |
|
| 683 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 684 | + EE_Error::add_attention( |
|
| 685 | + sprintf( |
|
| 686 | + esc_html__( |
|
| 687 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 688 | + 'event_espresso' |
|
| 689 | + ), |
|
| 690 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 691 | + ) |
|
| 692 | + ); |
|
| 693 | + } |
|
| 694 | + return; |
|
| 695 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 696 | + EE_Error::add_attention( |
|
| 697 | + sprintf( |
|
| 698 | + esc_html__( |
|
| 699 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 700 | + 'event_espresso' |
|
| 701 | + ), |
|
| 702 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 703 | + ) |
|
| 704 | + ); |
|
| 705 | + } |
|
| 706 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 707 | + if ( ! $event->tickets_on_sale()) { |
|
| 708 | + return; |
|
| 709 | + } |
|
| 710 | + //made it here so show warning |
|
| 711 | + $this->_edit_event_warning(); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 718 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 719 | + * |
|
| 720 | + * @access protected |
|
| 721 | + * @return void |
|
| 722 | + */ |
|
| 723 | + protected function _edit_event_warning() |
|
| 724 | + { |
|
| 725 | + // we don't want to add warnings during these requests |
|
| 726 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 727 | + return; |
|
| 728 | + } |
|
| 729 | + EE_Error::add_attention( |
|
| 730 | + esc_html__( |
|
| 731 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 732 | + 'event_espresso' |
|
| 733 | + ) |
|
| 734 | + ); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 741 | + * Otherwise, do the normal logic |
|
| 742 | + * |
|
| 743 | + * @return string |
|
| 744 | + * @throws \EE_Error |
|
| 745 | + */ |
|
| 746 | + protected function _create_new_cpt_item() |
|
| 747 | + { |
|
| 748 | + $gmt_offset = get_option('gmt_offset'); |
|
| 749 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 750 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 751 | + EE_Error::add_attention( |
|
| 752 | + sprintf( |
|
| 753 | + __( |
|
| 754 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 755 | + 'event_espresso' |
|
| 756 | + ), |
|
| 757 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 758 | + '</a>' |
|
| 759 | + ), |
|
| 760 | + __FILE__, |
|
| 761 | + __FUNCTION__, |
|
| 762 | + __LINE__ |
|
| 763 | + ); |
|
| 764 | + } |
|
| 765 | + return parent::_create_new_cpt_item(); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + protected function _set_list_table_views_default() |
|
| 771 | + { |
|
| 772 | + $this->_views = array( |
|
| 773 | + 'all' => array( |
|
| 774 | + 'slug' => 'all', |
|
| 775 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 776 | + 'count' => 0, |
|
| 777 | + 'bulk_action' => array( |
|
| 778 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 779 | + ), |
|
| 780 | + ), |
|
| 781 | + 'draft' => array( |
|
| 782 | + 'slug' => 'draft', |
|
| 783 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 784 | + 'count' => 0, |
|
| 785 | + 'bulk_action' => array( |
|
| 786 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 787 | + ), |
|
| 788 | + ), |
|
| 789 | + ); |
|
| 790 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 791 | + $this->_views['trash'] = array( |
|
| 792 | + 'slug' => 'trash', |
|
| 793 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 794 | + 'count' => 0, |
|
| 795 | + 'bulk_action' => array( |
|
| 796 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 797 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 798 | + ), |
|
| 799 | + ); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * @return array |
|
| 807 | + */ |
|
| 808 | + protected function _event_legend_items() |
|
| 809 | + { |
|
| 810 | + $items = array( |
|
| 811 | + 'view_details' => array( |
|
| 812 | + 'class' => 'dashicons dashicons-search', |
|
| 813 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 814 | + ), |
|
| 815 | + 'edit_event' => array( |
|
| 816 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 817 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 818 | + ), |
|
| 819 | + 'view_attendees' => array( |
|
| 820 | + 'class' => 'dashicons dashicons-groups', |
|
| 821 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 822 | + ), |
|
| 823 | + ); |
|
| 824 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 825 | + $statuses = array( |
|
| 826 | + 'sold_out_status' => array( |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 828 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 829 | + ), |
|
| 830 | + 'active_status' => array( |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 832 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 833 | + ), |
|
| 834 | + 'upcoming_status' => array( |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 836 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 837 | + ), |
|
| 838 | + 'postponed_status' => array( |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 840 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 841 | + ), |
|
| 842 | + 'cancelled_status' => array( |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 844 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 845 | + ), |
|
| 846 | + 'expired_status' => array( |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 848 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 849 | + ), |
|
| 850 | + 'inactive_status' => array( |
|
| 851 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 852 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 853 | + ), |
|
| 854 | + ); |
|
| 855 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 856 | + return array_merge($items, $statuses); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * _event_model |
|
| 863 | + * |
|
| 864 | + * @return EEM_Event |
|
| 865 | + */ |
|
| 866 | + private function _event_model() |
|
| 867 | + { |
|
| 868 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 869 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 870 | + } |
|
| 871 | + return $this->_event_model; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 878 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 879 | + * |
|
| 880 | + * @param string $return the current html |
|
| 881 | + * @param int $id the post id for the page |
|
| 882 | + * @param string $new_title What the title is |
|
| 883 | + * @param string $new_slug what the slug is |
|
| 884 | + * @return string The new html string for the permalink area |
|
| 885 | + */ |
|
| 886 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 887 | + { |
|
| 888 | + //make sure this is only when editing |
|
| 889 | + if ( ! empty($id)) { |
|
| 890 | + $post = get_post($id); |
|
| 891 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 892 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 893 | + . '</a> '; |
|
| 894 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 895 | + . $post->ID |
|
| 896 | + . ']">'; |
|
| 897 | + } |
|
| 898 | + return $return; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * _events_overview_list_table |
|
| 905 | + * This contains the logic for showing the events_overview list |
|
| 906 | + * |
|
| 907 | + * @access protected |
|
| 908 | + * @return void |
|
| 909 | + * @throws \EE_Error |
|
| 910 | + */ |
|
| 911 | + protected function _events_overview_list_table() |
|
| 912 | + { |
|
| 913 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 914 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 915 | + ? (array)$this->_template_args['after_list_table'] |
|
| 916 | + : array(); |
|
| 917 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 918 | + . EEH_Template::get_button_or_link( |
|
| 919 | + get_post_type_archive_link('espresso_events'), |
|
| 920 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 921 | + 'button' |
|
| 922 | + ); |
|
| 923 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 924 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 925 | + 'create_new', |
|
| 926 | + 'add', |
|
| 927 | + array(), |
|
| 928 | + 'add-new-h2' |
|
| 929 | + ); |
|
| 930 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * this allows for extra misc actions in the default WP publish box |
|
| 937 | + * |
|
| 938 | + * @return void |
|
| 939 | + */ |
|
| 940 | + public function extra_misc_actions_publish_box() |
|
| 941 | + { |
|
| 942 | + $this->_generate_publish_box_extra_content(); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 949 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 950 | + * data. |
|
| 951 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 952 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 953 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 954 | + * you handle this accordingly. |
|
| 955 | + * |
|
| 956 | + * @access protected |
|
| 957 | + * @abstract |
|
| 958 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 959 | + * @param object $post The post object of the cpt that was saved. |
|
| 960 | + * @return void |
|
| 961 | + */ |
|
| 962 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 963 | + { |
|
| 964 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 965 | + //get out we're not processing an event save. |
|
| 966 | + return; |
|
| 967 | + } |
|
| 968 | + $event_values = array( |
|
| 969 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 970 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 971 | + 'EVT_additional_limit' => min( |
|
| 972 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 973 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 974 | + ), |
|
| 975 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 976 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 977 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 978 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 979 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 980 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 981 | + ? $this->_req_data['timezone_string'] : null, |
|
| 982 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 983 | + ? $this->_req_data['externalURL'] : null, |
|
| 984 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 985 | + ? $this->_req_data['event_phone'] : null, |
|
| 986 | + ); |
|
| 987 | + //update event |
|
| 988 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 989 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 990 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 991 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 992 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 993 | + $event_update_callbacks = apply_filters( |
|
| 994 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 995 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 996 | + ); |
|
| 997 | + $att_success = true; |
|
| 998 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 999 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 1000 | + $att_success = ! $att_success ? $att_success |
|
| 1001 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 1002 | + } |
|
| 1003 | + //any errors? |
|
| 1004 | + if ($success && false === $att_success) { |
|
| 1005 | + EE_Error::add_error( |
|
| 1006 | + esc_html__( |
|
| 1007 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1008 | + 'event_espresso' |
|
| 1009 | + ), |
|
| 1010 | + __FILE__, |
|
| 1011 | + __FUNCTION__, |
|
| 1012 | + __LINE__ |
|
| 1013 | + ); |
|
| 1014 | + } else if ($success === false) { |
|
| 1015 | + EE_Error::add_error( |
|
| 1016 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1017 | + __FILE__, |
|
| 1018 | + __FUNCTION__, |
|
| 1019 | + __LINE__ |
|
| 1020 | + ); |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * @see parent::restore_item() |
|
| 1028 | + * @param int $post_id |
|
| 1029 | + * @param int $revision_id |
|
| 1030 | + */ |
|
| 1031 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1032 | + { |
|
| 1033 | + //copy existing event meta to new post |
|
| 1034 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1035 | + if ($post_evt instanceof EE_Event) { |
|
| 1036 | + //meta revision restore |
|
| 1037 | + $post_evt->restore_revision($revision_id); |
|
| 1038 | + //related objs restore |
|
| 1039 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Attach the venue to the Event |
|
| 1047 | + * |
|
| 1048 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1049 | + * @param array $data The request data from the form |
|
| 1050 | + * @return bool Success or fail. |
|
| 1051 | + */ |
|
| 1052 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1053 | + { |
|
| 1054 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1055 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1056 | + $rows_affected = null; |
|
| 1057 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1058 | + // very important. If we don't have a venue name... |
|
| 1059 | + // then we'll get out because not necessary to create empty venue |
|
| 1060 | + if (empty($data['venue_title'])) { |
|
| 1061 | + return false; |
|
| 1062 | + } |
|
| 1063 | + $venue_array = array( |
|
| 1064 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1065 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1066 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1067 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1068 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1069 | + : null, |
|
| 1070 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1071 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1072 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1073 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1074 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1075 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1076 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1077 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1078 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1079 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1080 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1081 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1082 | + 'status' => 'publish', |
|
| 1083 | + ); |
|
| 1084 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1085 | + if ( ! empty($venue_id)) { |
|
| 1086 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1087 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1088 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1089 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | + return $rows_affected > 0 ? true : false; |
|
| 1091 | + } else { |
|
| 1092 | + //we insert the venue |
|
| 1093 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1094 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1095 | + return ! empty($venue_id) ? true : false; |
|
| 1096 | + } |
|
| 1097 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1104 | + * |
|
| 1105 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1106 | + * @param array $data The request data from the form |
|
| 1107 | + * @return array |
|
| 1108 | + */ |
|
| 1109 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1110 | + { |
|
| 1111 | + $success = true; |
|
| 1112 | + $saved_dtt = null; |
|
| 1113 | + $saved_tickets = array(); |
|
| 1114 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1115 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1116 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1117 | + $dtt = array_map('trim', $dtt); |
|
| 1118 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1119 | + : $dtt['DTT_EVT_start']; |
|
| 1120 | + $datetime_values = array( |
|
| 1121 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1122 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1123 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1124 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1125 | + 'DTT_order' => $row, |
|
| 1126 | + ); |
|
| 1127 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1128 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1129 | + $DTM = EE_Registry::instance() |
|
| 1130 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1131 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1132 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1133 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1134 | + foreach ($datetime_values as $field => $value) { |
|
| 1135 | + $DTM->set($field, $value); |
|
| 1136 | + } |
|
| 1137 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1138 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1139 | + } else { |
|
| 1140 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1141 | + 'Datetime', |
|
| 1142 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1143 | + false, |
|
| 1144 | + false |
|
| 1145 | + ); |
|
| 1146 | + foreach ($datetime_values as $field => $value) { |
|
| 1147 | + $DTM->set($field, $value); |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + $DTM->save(); |
|
| 1151 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1152 | + //load DTT helper |
|
| 1153 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1154 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1155 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1156 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1157 | + $DTT->save(); |
|
| 1158 | + } |
|
| 1159 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1160 | + $saved_dtt = $DTT; |
|
| 1161 | + $success = ! $success ? $success : $DTT; |
|
| 1162 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1163 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1164 | + } |
|
| 1165 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1166 | + //update tickets next |
|
| 1167 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1168 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1169 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | + $update_prices = false; |
|
| 1171 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1172 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1173 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1174 | + $tkt = array_map('trim', $tkt); |
|
| 1175 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1176 | + //let's use now in the set timezone. |
|
| 1177 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1179 | + } |
|
| 1180 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1181 | + //use the start date of the first datetime |
|
| 1182 | + $dtt = $evtobj->first_datetime(); |
|
| 1183 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1184 | + $incoming_date_formats[0], |
|
| 1185 | + $incoming_date_formats[1] |
|
| 1186 | + ); |
|
| 1187 | + } |
|
| 1188 | + $TKT_values = array( |
|
| 1189 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1190 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1191 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1192 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1193 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1194 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1195 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1196 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1197 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1198 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1199 | + 'TKT_row' => $row, |
|
| 1200 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1201 | + 'TKT_price' => $ticket_price, |
|
| 1202 | + ); |
|
| 1203 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1204 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1205 | + $TKT_values['TKT_ID'] = 0; |
|
| 1206 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1207 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1208 | + $update_prices = true; |
|
| 1209 | + } |
|
| 1210 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1211 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1212 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1213 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1214 | + $TKT = EE_Registry::instance() |
|
| 1215 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1216 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1217 | + if ($TKT instanceof EE_Ticket) { |
|
| 1218 | + $ticket_sold = $TKT->count_related( |
|
| 1219 | + 'Registration', |
|
| 1220 | + array( |
|
| 1221 | + array( |
|
| 1222 | + 'STS_ID' => array( |
|
| 1223 | + 'NOT IN', |
|
| 1224 | + array(EEM_Registration::status_id_incomplete), |
|
| 1225 | + ), |
|
| 1226 | + ), |
|
| 1227 | + ) |
|
| 1228 | + ) > 0 ? true : false; |
|
| 1229 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1230 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1231 | + && ! $TKT->get( |
|
| 1232 | + 'TKT_deleted' |
|
| 1233 | + ) ? true : false; |
|
| 1234 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1235 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1236 | + //set new values |
|
| 1237 | + foreach ($TKT_values as $field => $value) { |
|
| 1238 | + if ($field == 'TKT_qty') { |
|
| 1239 | + $TKT->set_qty($value); |
|
| 1240 | + } else { |
|
| 1241 | + $TKT->set($field, $value); |
|
| 1242 | + } |
|
| 1243 | + } |
|
| 1244 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1245 | + if ($create_new_TKT) { |
|
| 1246 | + //archive the old ticket first |
|
| 1247 | + $TKT->set('TKT_deleted', 1); |
|
| 1248 | + $TKT->save(); |
|
| 1249 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1250 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1251 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1252 | + $TKT = clone $TKT; |
|
| 1253 | + $TKT->set('TKT_ID', 0); |
|
| 1254 | + $TKT->set('TKT_deleted', 0); |
|
| 1255 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1256 | + $TKT->set('TKT_sold', 0); |
|
| 1257 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1258 | + $update_prices = true; |
|
| 1259 | + } |
|
| 1260 | + //make sure price is set if it hasn't been already |
|
| 1261 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1262 | + } |
|
| 1263 | + } else { |
|
| 1264 | + //no TKT_id so a new TKT |
|
| 1265 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1266 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1267 | + if ($TKT instanceof EE_Ticket) { |
|
| 1268 | + //need to reset values to properly account for the date formats |
|
| 1269 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1270 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1271 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1272 | + //set new values |
|
| 1273 | + foreach ($TKT_values as $field => $value) { |
|
| 1274 | + if ($field == 'TKT_qty') { |
|
| 1275 | + $TKT->set_qty($value); |
|
| 1276 | + } else { |
|
| 1277 | + $TKT->set($field, $value); |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + $update_prices = true; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + // cap ticket qty by datetime reg limits |
|
| 1284 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1285 | + //update ticket. |
|
| 1286 | + $TKT->save(); |
|
| 1287 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1288 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1289 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1290 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1291 | + $TKT->save(); |
|
| 1292 | + } |
|
| 1293 | + //initially let's add the ticket to the dtt |
|
| 1294 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1295 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1296 | + //add prices to ticket |
|
| 1297 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1298 | + } |
|
| 1299 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1300 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1301 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1302 | + foreach ($tickets_removed as $id) { |
|
| 1303 | + $id = absint($id); |
|
| 1304 | + //get the ticket for this id |
|
| 1305 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1306 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1307 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1308 | + foreach ($dtts as $dtt) { |
|
| 1309 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1310 | + } |
|
| 1311 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1312 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1313 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1314 | + $tkt_to_remove->delete_permanently(); |
|
| 1315 | + } |
|
| 1316 | + return array($saved_dtt, $saved_tickets); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * This attaches a list of given prices to a ticket. |
|
| 1323 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1324 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1325 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1326 | + * |
|
| 1327 | + * @access private |
|
| 1328 | + * @param array $prices Array of prices from the form. |
|
| 1329 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1330 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1331 | + * @return void |
|
| 1332 | + */ |
|
| 1333 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1334 | + { |
|
| 1335 | + foreach ($prices as $row => $prc) { |
|
| 1336 | + $PRC_values = array( |
|
| 1337 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1338 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1339 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1340 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1341 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1342 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1343 | + 'PRC_order' => $row, |
|
| 1344 | + ); |
|
| 1345 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1346 | + $PRC_values['PRC_ID'] = 0; |
|
| 1347 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1348 | + } else { |
|
| 1349 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1350 | + //update this price with new values |
|
| 1351 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1352 | + $PRC->set($field, $newprc); |
|
| 1353 | + } |
|
| 1354 | + $PRC->save(); |
|
| 1355 | + } |
|
| 1356 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Add in our autosave ajax handlers |
|
| 1364 | + * |
|
| 1365 | + * @return void |
|
| 1366 | + */ |
|
| 1367 | + protected function _ee_autosave_create_new() |
|
| 1368 | + { |
|
| 1369 | + // $this->_ee_autosave_edit(); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + protected function _ee_autosave_edit() |
|
| 1375 | + { |
|
| 1376 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + |
|
| 1381 | + /** |
|
| 1382 | + * _generate_publish_box_extra_content |
|
| 1383 | + * |
|
| 1384 | + * @access private |
|
| 1385 | + * @return void |
|
| 1386 | + */ |
|
| 1387 | + private function _generate_publish_box_extra_content() |
|
| 1388 | + { |
|
| 1389 | + //load formatter helper |
|
| 1390 | + //args for getting related registrations |
|
| 1391 | + $approved_query_args = array( |
|
| 1392 | + array( |
|
| 1393 | + 'REG_deleted' => 0, |
|
| 1394 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1395 | + ), |
|
| 1396 | + ); |
|
| 1397 | + $not_approved_query_args = array( |
|
| 1398 | + array( |
|
| 1399 | + 'REG_deleted' => 0, |
|
| 1400 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1401 | + ), |
|
| 1402 | + ); |
|
| 1403 | + $pending_payment_query_args = array( |
|
| 1404 | + array( |
|
| 1405 | + 'REG_deleted' => 0, |
|
| 1406 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1407 | + ), |
|
| 1408 | + ); |
|
| 1409 | + // publish box |
|
| 1410 | + $publish_box_extra_args = array( |
|
| 1411 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1412 | + array( |
|
| 1413 | + 'action' => 'default', |
|
| 1414 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1415 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1416 | + ), |
|
| 1417 | + REG_ADMIN_URL |
|
| 1418 | + ), |
|
| 1419 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1420 | + array( |
|
| 1421 | + 'action' => 'default', |
|
| 1422 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1423 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1424 | + ), |
|
| 1425 | + REG_ADMIN_URL |
|
| 1426 | + ), |
|
| 1427 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1428 | + array( |
|
| 1429 | + 'action' => 'default', |
|
| 1430 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1431 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1432 | + ), |
|
| 1433 | + REG_ADMIN_URL |
|
| 1434 | + ), |
|
| 1435 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | + 'Registration', |
|
| 1437 | + $approved_query_args |
|
| 1438 | + ), |
|
| 1439 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | + 'Registration', |
|
| 1441 | + $not_approved_query_args |
|
| 1442 | + ), |
|
| 1443 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1444 | + 'Registration', |
|
| 1445 | + $pending_payment_query_args |
|
| 1446 | + ), |
|
| 1447 | + 'misc_pub_section_class' => apply_filters( |
|
| 1448 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1449 | + 'misc-pub-section' |
|
| 1450 | + ), |
|
| 1451 | + //'email_attendees_url' => add_query_arg( |
|
| 1452 | + // array( |
|
| 1453 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1454 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1455 | + // ), |
|
| 1456 | + // 'admin.php?page=espresso_registrations' |
|
| 1457 | + //), |
|
| 1458 | + ); |
|
| 1459 | + ob_start(); |
|
| 1460 | + do_action( |
|
| 1461 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1462 | + $this->_cpt_model_obj |
|
| 1463 | + ); |
|
| 1464 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1465 | + // load template |
|
| 1466 | + EEH_Template::display_template( |
|
| 1467 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1468 | + $publish_box_extra_args |
|
| 1469 | + ); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * This just returns whatever is set as the _event object property |
|
| 1476 | + * //todo this will become obsolete once the models are in place |
|
| 1477 | + * |
|
| 1478 | + * @return object |
|
| 1479 | + */ |
|
| 1480 | + public function get_event_object() |
|
| 1481 | + { |
|
| 1482 | + return $this->_cpt_model_obj; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + /** METABOXES * */ |
|
| 1489 | + /** |
|
| 1490 | + * _register_event_editor_meta_boxes |
|
| 1491 | + * add all metaboxes related to the event_editor |
|
| 1492 | + * |
|
| 1493 | + * @return void |
|
| 1494 | + */ |
|
| 1495 | + protected function _register_event_editor_meta_boxes() |
|
| 1496 | + { |
|
| 1497 | + $this->verify_cpt_object(); |
|
| 1498 | + add_meta_box( |
|
| 1499 | + 'espresso_event_editor_tickets', |
|
| 1500 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1501 | + array($this, 'ticket_metabox'), |
|
| 1502 | + $this->page_slug, |
|
| 1503 | + 'normal', |
|
| 1504 | + 'high' |
|
| 1505 | + ); |
|
| 1506 | + add_meta_box( |
|
| 1507 | + 'espresso_event_editor_event_options', |
|
| 1508 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1509 | + array($this, 'registration_options_meta_box'), |
|
| 1510 | + $this->page_slug, |
|
| 1511 | + 'side', |
|
| 1512 | + 'default' |
|
| 1513 | + ); |
|
| 1514 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1515 | + // where a metabox has a related management page in the admin |
|
| 1516 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1517 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + public function ticket_metabox() |
|
| 1523 | + { |
|
| 1524 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1525 | + //defaults for template args |
|
| 1526 | + $template_args = array( |
|
| 1527 | + 'existing_datetime_ids' => '', |
|
| 1528 | + 'event_datetime_help_link' => '', |
|
| 1529 | + 'ticket_options_help_link' => '', |
|
| 1530 | + 'time' => null, |
|
| 1531 | + 'ticket_rows' => '', |
|
| 1532 | + 'existing_ticket_ids' => '', |
|
| 1533 | + 'total_ticket_rows' => 1, |
|
| 1534 | + 'ticket_js_structure' => '', |
|
| 1535 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1536 | + 'disabled' => '', |
|
| 1537 | + ); |
|
| 1538 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1539 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1540 | + /** |
|
| 1541 | + * 1. Start with retrieving Datetimes |
|
| 1542 | + * 2. Fore each datetime get related tickets |
|
| 1543 | + * 3. For each ticket get related prices |
|
| 1544 | + */ |
|
| 1545 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1546 | + /** @type EE_Datetime $first_datetime */ |
|
| 1547 | + $first_datetime = reset($times); |
|
| 1548 | + //do we get related tickets? |
|
| 1549 | + if ($first_datetime instanceof EE_Datetime |
|
| 1550 | + && $first_datetime->ID() !== 0 |
|
| 1551 | + ) { |
|
| 1552 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1553 | + $template_args['time'] = $first_datetime; |
|
| 1554 | + $related_tickets = $first_datetime->tickets( |
|
| 1555 | + array( |
|
| 1556 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1557 | + 'default_where_conditions' => 'none', |
|
| 1558 | + ) |
|
| 1559 | + ); |
|
| 1560 | + if ( ! empty($related_tickets)) { |
|
| 1561 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1562 | + $row = 0; |
|
| 1563 | + foreach ($related_tickets as $ticket) { |
|
| 1564 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1565 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1566 | + $row++; |
|
| 1567 | + } |
|
| 1568 | + } else { |
|
| 1569 | + $template_args['total_ticket_rows'] = 1; |
|
| 1570 | + /** @type EE_Ticket $ticket */ |
|
| 1571 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1572 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1573 | + } |
|
| 1574 | + } else { |
|
| 1575 | + $template_args['time'] = $times[0]; |
|
| 1576 | + /** @type EE_Ticket $ticket */ |
|
| 1577 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1578 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1579 | + // NOTE: we're just sending the first default row |
|
| 1580 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1581 | + } |
|
| 1582 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1583 | + 'event_editor_event_datetimes_help_tab' |
|
| 1584 | + ); |
|
| 1585 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1586 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1587 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1588 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1589 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1590 | + true |
|
| 1591 | + ); |
|
| 1592 | + $template = apply_filters( |
|
| 1593 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1594 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1595 | + ); |
|
| 1596 | + EEH_Template::display_template($template, $template_args); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + /** |
|
| 1602 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1603 | + * |
|
| 1604 | + * @access private |
|
| 1605 | + * @param EE_Ticket $ticket the ticket object |
|
| 1606 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1607 | + * @param int $row |
|
| 1608 | + * @return string generated html for the ticket row. |
|
| 1609 | + */ |
|
| 1610 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1611 | + { |
|
| 1612 | + $template_args = array( |
|
| 1613 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1614 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1615 | + : '', |
|
| 1616 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1617 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1618 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1619 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1620 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1621 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1622 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1623 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1624 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1625 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1626 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1627 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1628 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1629 | + : ' disabled=disabled', |
|
| 1630 | + ); |
|
| 1631 | + $price = $ticket->ID() !== 0 |
|
| 1632 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1633 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1634 | + $price_args = array( |
|
| 1635 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1636 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1637 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1638 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1639 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1640 | + ); |
|
| 1641 | + //make sure we have default start and end dates if skeleton |
|
| 1642 | + //handle rows that should NOT be empty |
|
| 1643 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1644 | + //if empty then the start date will be now. |
|
| 1645 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1646 | + } |
|
| 1647 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1648 | + //get the earliest datetime (if present); |
|
| 1649 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1650 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1651 | + 'Datetime', |
|
| 1652 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1653 | + ) |
|
| 1654 | + : null; |
|
| 1655 | + if ( ! empty($earliest_dtt)) { |
|
| 1656 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1657 | + } else { |
|
| 1658 | + $template_args['TKT_end_date'] = date( |
|
| 1659 | + 'Y-m-d h:i a', |
|
| 1660 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1661 | + ); |
|
| 1662 | + } |
|
| 1663 | + } |
|
| 1664 | + $template_args = array_merge($template_args, $price_args); |
|
| 1665 | + $template = apply_filters( |
|
| 1666 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1667 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | + $ticket |
|
| 1669 | + ); |
|
| 1670 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + public function registration_options_meta_box() |
|
| 1676 | + { |
|
| 1677 | + $yes_no_values = array( |
|
| 1678 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1679 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1680 | + ); |
|
| 1681 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1682 | + array( |
|
| 1683 | + EEM_Registration::status_id_cancelled, |
|
| 1684 | + EEM_Registration::status_id_declined, |
|
| 1685 | + EEM_Registration::status_id_incomplete, |
|
| 1686 | + ), |
|
| 1687 | + true |
|
| 1688 | + ); |
|
| 1689 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1690 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1691 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1692 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1693 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1694 | + 'default_reg_status', |
|
| 1695 | + $default_reg_status_values, |
|
| 1696 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1697 | + ); |
|
| 1698 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1699 | + 'display_desc', |
|
| 1700 | + $yes_no_values, |
|
| 1701 | + $this->_cpt_model_obj->display_description() |
|
| 1702 | + ); |
|
| 1703 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1704 | + 'display_ticket_selector', |
|
| 1705 | + $yes_no_values, |
|
| 1706 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1707 | + '', |
|
| 1708 | + '', |
|
| 1709 | + false |
|
| 1710 | + ); |
|
| 1711 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1712 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1713 | + '', |
|
| 1714 | + $template_args, |
|
| 1715 | + $yes_no_values, |
|
| 1716 | + $default_reg_status_values |
|
| 1717 | + ); |
|
| 1718 | + EEH_Template::display_template( |
|
| 1719 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1720 | + $template_args |
|
| 1721 | + ); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * _get_events() |
|
| 1728 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1729 | + * |
|
| 1730 | + * @access public |
|
| 1731 | + * @param int $per_page count of items per page (20 default); |
|
| 1732 | + * @param int $current_page what is the current page being viewed. |
|
| 1733 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1734 | + * If FALSE then we return an array of event objects |
|
| 1735 | + * that match the given _view and paging parameters. |
|
| 1736 | + * @return array an array of event objects. |
|
| 1737 | + */ |
|
| 1738 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1739 | + { |
|
| 1740 | + $EEME = $this->_event_model(); |
|
| 1741 | + $offset = ($current_page - 1) * $per_page; |
|
| 1742 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1743 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1744 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1745 | + if (isset($this->_req_data['month_range'])) { |
|
| 1746 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1747 | + //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1748 | + //where PHP doesn't know what to assume for date. |
|
| 1749 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1750 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1751 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1752 | + } |
|
| 1753 | + $where = array(); |
|
| 1754 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1755 | + //determine what post_status our condition will have for the query. |
|
| 1756 | + switch ($status) { |
|
| 1757 | + case 'month' : |
|
| 1758 | + case 'today' : |
|
| 1759 | + case null : |
|
| 1760 | + case 'all' : |
|
| 1761 | + break; |
|
| 1762 | + case 'draft' : |
|
| 1763 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1764 | + break; |
|
| 1765 | + default : |
|
| 1766 | + $where['status'] = $status; |
|
| 1767 | + } |
|
| 1768 | + //categories? |
|
| 1769 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1770 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1771 | + if ( ! empty ($category)) { |
|
| 1772 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1773 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1774 | + } |
|
| 1775 | + //date where conditions |
|
| 1776 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1777 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1778 | + $DateTime = new DateTime( |
|
| 1779 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1780 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1781 | + ); |
|
| 1782 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1783 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1784 | + ->format('t'))->setTime(23, 59, 59) |
|
| 1785 | + ->format(implode(' ', $start_formats)); |
|
| 1786 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1787 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1788 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1789 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1790 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1791 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1793 | + $now = date('Y-m-01'); |
|
| 1794 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1795 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1796 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1797 | + ->setTime(23, 59, 59) |
|
| 1798 | + ->format(implode(' ', $start_formats)); |
|
| 1799 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1800 | + } |
|
| 1801 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1802 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1803 | + } else { |
|
| 1804 | + if ( ! isset($where['status'])) { |
|
| 1805 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1806 | + $where['OR'] = array( |
|
| 1807 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1808 | + 'AND' => array( |
|
| 1809 | + 'status*inclusive' => array('=', 'private'), |
|
| 1810 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1811 | + ), |
|
| 1812 | + ); |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1815 | + } |
|
| 1816 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1817 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1818 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1819 | + ) { |
|
| 1820 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1821 | + } |
|
| 1822 | + } |
|
| 1823 | + //search query handling |
|
| 1824 | + if (isset($this->_req_data['s'])) { |
|
| 1825 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1826 | + $where['OR'] = array( |
|
| 1827 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1828 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1829 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1830 | + ); |
|
| 1831 | + } |
|
| 1832 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1833 | + $query_params = apply_filters( |
|
| 1834 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1835 | + array( |
|
| 1836 | + $where, |
|
| 1837 | + 'limit' => $limit, |
|
| 1838 | + 'order_by' => $orderby, |
|
| 1839 | + 'order' => $order, |
|
| 1840 | + 'group_by' => 'EVT_ID', |
|
| 1841 | + ), |
|
| 1842 | + $this->_req_data |
|
| 1843 | + ); |
|
| 1844 | + //let's first check if we have special requests coming in. |
|
| 1845 | + if (isset($this->_req_data['active_status'])) { |
|
| 1846 | + switch ($this->_req_data['active_status']) { |
|
| 1847 | + case 'upcoming' : |
|
| 1848 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1849 | + break; |
|
| 1850 | + case 'expired' : |
|
| 1851 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1852 | + break; |
|
| 1853 | + case 'active' : |
|
| 1854 | + return $EEME->get_active_events($query_params, $count); |
|
| 1855 | + break; |
|
| 1856 | + case 'inactive' : |
|
| 1857 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1858 | + break; |
|
| 1859 | + } |
|
| 1860 | + } |
|
| 1861 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1862 | + return $events; |
|
| 1863 | + } |
|
| 1864 | + |
|
| 1865 | + |
|
| 1866 | + |
|
| 1867 | + /** |
|
| 1868 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1869 | + * |
|
| 1870 | + * @param string $post_id |
|
| 1871 | + */ |
|
| 1872 | + public function trash_cpt_item($post_id) |
|
| 1873 | + { |
|
| 1874 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1875 | + $this->_trash_or_restore_event('trash', false); |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * @param string $post_id |
|
| 1882 | + */ |
|
| 1883 | + public function restore_cpt_item($post_id) |
|
| 1884 | + { |
|
| 1885 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1886 | + $this->_trash_or_restore_event('draft', false); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + |
|
| 1890 | + |
|
| 1891 | + /** |
|
| 1892 | + * @param string $post_id |
|
| 1893 | + */ |
|
| 1894 | + public function delete_cpt_item($post_id) |
|
| 1895 | + { |
|
| 1896 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1897 | + $this->_delete_event(false); |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * _trash_or_restore_event |
|
| 1904 | + * |
|
| 1905 | + * @access protected |
|
| 1906 | + * @param string $event_status |
|
| 1907 | + * @param bool $redirect_after |
|
| 1908 | + */ |
|
| 1909 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1910 | + { |
|
| 1911 | + //determine the event id and set to array. |
|
| 1912 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1913 | + // loop thru events |
|
| 1914 | + if ($EVT_ID) { |
|
| 1915 | + // clean status |
|
| 1916 | + $event_status = sanitize_key($event_status); |
|
| 1917 | + // grab status |
|
| 1918 | + if ( ! empty($event_status)) { |
|
| 1919 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1920 | + } else { |
|
| 1921 | + $success = false; |
|
| 1922 | + $msg = esc_html__( |
|
| 1923 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1924 | + 'event_espresso' |
|
| 1925 | + ); |
|
| 1926 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | + } |
|
| 1928 | + } else { |
|
| 1929 | + $success = false; |
|
| 1930 | + $msg = esc_html__( |
|
| 1931 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1932 | + 'event_espresso' |
|
| 1933 | + ); |
|
| 1934 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1935 | + } |
|
| 1936 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1937 | + if ($redirect_after) { |
|
| 1938 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1939 | + } |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * _trash_or_restore_events |
|
| 1946 | + * |
|
| 1947 | + * @access protected |
|
| 1948 | + * @param string $event_status |
|
| 1949 | + * @return void |
|
| 1950 | + */ |
|
| 1951 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1952 | + { |
|
| 1953 | + // clean status |
|
| 1954 | + $event_status = sanitize_key($event_status); |
|
| 1955 | + // grab status |
|
| 1956 | + if ( ! empty($event_status)) { |
|
| 1957 | + $success = true; |
|
| 1958 | + //determine the event id and set to array. |
|
| 1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | + // loop thru events |
|
| 1961 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1962 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1963 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1964 | + $success = $results !== false ? $success : false; |
|
| 1965 | + } else { |
|
| 1966 | + $msg = sprintf( |
|
| 1967 | + esc_html__( |
|
| 1968 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1969 | + 'event_espresso' |
|
| 1970 | + ), |
|
| 1971 | + $EVT_ID |
|
| 1972 | + ); |
|
| 1973 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1974 | + $success = false; |
|
| 1975 | + } |
|
| 1976 | + } |
|
| 1977 | + } else { |
|
| 1978 | + $success = false; |
|
| 1979 | + $msg = esc_html__( |
|
| 1980 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1981 | + 'event_espresso' |
|
| 1982 | + ); |
|
| 1983 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1984 | + } |
|
| 1985 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1986 | + $success = $success ? 2 : false; |
|
| 1987 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1988 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * _trash_or_restore_events |
|
| 1995 | + * |
|
| 1996 | + * @access private |
|
| 1997 | + * @param int $EVT_ID |
|
| 1998 | + * @param string $event_status |
|
| 1999 | + * @return bool |
|
| 2000 | + */ |
|
| 2001 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2002 | + { |
|
| 2003 | + // grab event id |
|
| 2004 | + if ( ! $EVT_ID) { |
|
| 2005 | + $msg = esc_html__( |
|
| 2006 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2007 | + 'event_espresso' |
|
| 2008 | + ); |
|
| 2009 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2010 | + return false; |
|
| 2011 | + } |
|
| 2012 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2013 | + // clean status |
|
| 2014 | + $event_status = sanitize_key($event_status); |
|
| 2015 | + // grab status |
|
| 2016 | + if (empty($event_status)) { |
|
| 2017 | + $msg = esc_html__( |
|
| 2018 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2019 | + 'event_espresso' |
|
| 2020 | + ); |
|
| 2021 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2022 | + return false; |
|
| 2023 | + } |
|
| 2024 | + // was event trashed or restored ? |
|
| 2025 | + switch ($event_status) { |
|
| 2026 | + case 'draft' : |
|
| 2027 | + $action = 'restored from the trash'; |
|
| 2028 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2029 | + break; |
|
| 2030 | + case 'trash' : |
|
| 2031 | + $action = 'moved to the trash'; |
|
| 2032 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2033 | + break; |
|
| 2034 | + default : |
|
| 2035 | + $action = 'updated'; |
|
| 2036 | + $hook = false; |
|
| 2037 | + } |
|
| 2038 | + //use class to change status |
|
| 2039 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2040 | + $success = $this->_cpt_model_obj->save(); |
|
| 2041 | + if ($success === false) { |
|
| 2042 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2043 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2044 | + return false; |
|
| 2045 | + } |
|
| 2046 | + if ($hook) { |
|
| 2047 | + do_action($hook); |
|
| 2048 | + } |
|
| 2049 | + return true; |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * _delete_event |
|
| 2056 | + * |
|
| 2057 | + * @access protected |
|
| 2058 | + * @param bool $redirect_after |
|
| 2059 | + */ |
|
| 2060 | + protected function _delete_event($redirect_after = true) |
|
| 2061 | + { |
|
| 2062 | + //determine the event id and set to array. |
|
| 2063 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2064 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2065 | + // loop thru events |
|
| 2066 | + if ($EVT_ID) { |
|
| 2067 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2068 | + // get list of events with no prices |
|
| 2069 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2070 | + // remove this event from the list of events with no prices |
|
| 2071 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2072 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2073 | + } |
|
| 2074 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2075 | + } else { |
|
| 2076 | + $success = false; |
|
| 2077 | + $msg = esc_html__( |
|
| 2078 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2079 | + 'event_espresso' |
|
| 2080 | + ); |
|
| 2081 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2082 | + } |
|
| 2083 | + if ($redirect_after) { |
|
| 2084 | + $this->_redirect_after_action( |
|
| 2085 | + $success, |
|
| 2086 | + 'Event', |
|
| 2087 | + 'deleted', |
|
| 2088 | + array('action' => 'default', 'status' => 'trash') |
|
| 2089 | + ); |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + |
|
| 2094 | + |
|
| 2095 | + /** |
|
| 2096 | + * _delete_events |
|
| 2097 | + * |
|
| 2098 | + * @access protected |
|
| 2099 | + * @return void |
|
| 2100 | + */ |
|
| 2101 | + protected function _delete_events() |
|
| 2102 | + { |
|
| 2103 | + $success = true; |
|
| 2104 | + // get list of events with no prices |
|
| 2105 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2106 | + //determine the event id and set to array. |
|
| 2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | + // loop thru events |
|
| 2109 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2110 | + $EVT_ID = absint($EVT_ID); |
|
| 2111 | + if ($EVT_ID) { |
|
| 2112 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2113 | + $success = $results !== false ? $success : false; |
|
| 2114 | + // remove this event from the list of events with no prices |
|
| 2115 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2116 | + } else { |
|
| 2117 | + $success = false; |
|
| 2118 | + $msg = esc_html__( |
|
| 2119 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2120 | + 'event_espresso' |
|
| 2121 | + ); |
|
| 2122 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | + } |
|
| 2124 | + } |
|
| 2125 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2126 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2127 | + $success = $success ? 2 : false; |
|
| 2128 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + |
|
| 2132 | + |
|
| 2133 | + /** |
|
| 2134 | + * _permanently_delete_event |
|
| 2135 | + * |
|
| 2136 | + * @access private |
|
| 2137 | + * @param int $EVT_ID |
|
| 2138 | + * @return bool |
|
| 2139 | + */ |
|
| 2140 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2141 | + { |
|
| 2142 | + // grab event id |
|
| 2143 | + if ( ! $EVT_ID) { |
|
| 2144 | + $msg = esc_html__( |
|
| 2145 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2146 | + 'event_espresso' |
|
| 2147 | + ); |
|
| 2148 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2149 | + return false; |
|
| 2150 | + } |
|
| 2151 | + if ( |
|
| 2152 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2153 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2154 | + ) { |
|
| 2155 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2156 | + } |
|
| 2157 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2158 | + return false; |
|
| 2159 | + } |
|
| 2160 | + //need to delete related tickets and prices first. |
|
| 2161 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2162 | + foreach ($datetimes as $datetime) { |
|
| 2163 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2164 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2165 | + foreach ($tickets as $ticket) { |
|
| 2166 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2167 | + $ticket->delete_related_permanently('Price'); |
|
| 2168 | + $ticket->delete_permanently(); |
|
| 2169 | + } |
|
| 2170 | + $datetime->delete(); |
|
| 2171 | + } |
|
| 2172 | + //what about related venues or terms? |
|
| 2173 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2174 | + foreach ($venues as $venue) { |
|
| 2175 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2176 | + } |
|
| 2177 | + //any attached question groups? |
|
| 2178 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2179 | + if ( ! empty($question_groups)) { |
|
| 2180 | + foreach ($question_groups as $question_group) { |
|
| 2181 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + //Message Template Groups |
|
| 2185 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2186 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2187 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2188 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2189 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2190 | + } |
|
| 2191 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2192 | + // did it all go as planned ? |
|
| 2193 | + if ($success) { |
|
| 2194 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2195 | + EE_Error::add_success($msg); |
|
| 2196 | + } else { |
|
| 2197 | + $msg = sprintf( |
|
| 2198 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2199 | + $EVT_ID |
|
| 2200 | + ); |
|
| 2201 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2202 | + return false; |
|
| 2203 | + } |
|
| 2204 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2205 | + return true; |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + |
|
| 2209 | + |
|
| 2210 | + /** |
|
| 2211 | + * get total number of events |
|
| 2212 | + * |
|
| 2213 | + * @access public |
|
| 2214 | + * @return int |
|
| 2215 | + */ |
|
| 2216 | + public function total_events() |
|
| 2217 | + { |
|
| 2218 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2219 | + return $count; |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + |
|
| 2223 | + |
|
| 2224 | + /** |
|
| 2225 | + * get total number of draft events |
|
| 2226 | + * |
|
| 2227 | + * @access public |
|
| 2228 | + * @return int |
|
| 2229 | + */ |
|
| 2230 | + public function total_events_draft() |
|
| 2231 | + { |
|
| 2232 | + $where = array( |
|
| 2233 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2234 | + ); |
|
| 2235 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2236 | + return $count; |
|
| 2237 | + } |
|
| 2238 | + |
|
| 2239 | + |
|
| 2240 | + |
|
| 2241 | + /** |
|
| 2242 | + * get total number of trashed events |
|
| 2243 | + * |
|
| 2244 | + * @access public |
|
| 2245 | + * @return int |
|
| 2246 | + */ |
|
| 2247 | + public function total_trashed_events() |
|
| 2248 | + { |
|
| 2249 | + $where = array( |
|
| 2250 | + 'status' => 'trash', |
|
| 2251 | + ); |
|
| 2252 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2253 | + return $count; |
|
| 2254 | + } |
|
| 2255 | + |
|
| 2256 | + |
|
| 2257 | + /** |
|
| 2258 | + * _default_event_settings |
|
| 2259 | + * This generates the Default Settings Tab |
|
| 2260 | + * |
|
| 2261 | + * @return void |
|
| 2262 | + * @throws \EE_Error |
|
| 2263 | + */ |
|
| 2264 | + protected function _default_event_settings() |
|
| 2265 | + { |
|
| 2266 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2267 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2268 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2269 | + $this->display_admin_page_with_sidebar(); |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + |
|
| 2273 | + /** |
|
| 2274 | + * Return the form for event settings. |
|
| 2275 | + * @return \EE_Form_Section_Proper |
|
| 2276 | + */ |
|
| 2277 | + protected function _default_event_settings_form() |
|
| 2278 | + { |
|
| 2279 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2280 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2281 | + //exclude |
|
| 2282 | + array( |
|
| 2283 | + EEM_Registration::status_id_cancelled, |
|
| 2284 | + EEM_Registration::status_id_declined, |
|
| 2285 | + EEM_Registration::status_id_incomplete, |
|
| 2286 | + EEM_Registration::status_id_wait_list, |
|
| 2287 | + ), |
|
| 2288 | + true |
|
| 2289 | + ); |
|
| 2290 | + return new EE_Form_Section_Proper( |
|
| 2291 | + array( |
|
| 2292 | + 'name' => 'update_default_event_settings', |
|
| 2293 | + 'html_id' => 'update_default_event_settings', |
|
| 2294 | + 'html_class' => 'form-table', |
|
| 2295 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2296 | + 'subsections' => apply_filters( |
|
| 2297 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2298 | + array( |
|
| 2299 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2300 | + $registration_stati_for_selection, |
|
| 2301 | + array( |
|
| 2302 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2303 | + && array_key_exists( |
|
| 2304 | + $registration_config->default_STS_ID, |
|
| 2305 | + $registration_stati_for_selection |
|
| 2306 | + ) |
|
| 2307 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2308 | + : EEM_Registration::status_id_pending_payment, |
|
| 2309 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2310 | + . EEH_Template::get_help_tab_link( |
|
| 2311 | + 'default_settings_status_help_tab' |
|
| 2312 | + ), |
|
| 2313 | + 'html_help_text' => esc_html__( |
|
| 2314 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2315 | + 'event_espresso' |
|
| 2316 | + ) |
|
| 2317 | + ) |
|
| 2318 | + ), |
|
| 2319 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2320 | + array( |
|
| 2321 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2322 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2323 | + : EEM_Event::get_default_additional_limit(), |
|
| 2324 | + 'html_label_text' => esc_html__( |
|
| 2325 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2326 | + 'event_espresso' |
|
| 2327 | + ) . EEH_Template::get_help_tab_link( |
|
| 2328 | + 'default_maximum_tickets_help_tab"' |
|
| 2329 | + ), |
|
| 2330 | + 'html_help_text' => esc_html__( |
|
| 2331 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2332 | + 'event_espresso' |
|
| 2333 | + ) |
|
| 2334 | + ) |
|
| 2335 | + ) |
|
| 2336 | + ) |
|
| 2337 | + ) |
|
| 2338 | + ) |
|
| 2339 | + ); |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + |
|
| 2343 | + /** |
|
| 2344 | + * _update_default_event_settings |
|
| 2345 | + * |
|
| 2346 | + * @access protected |
|
| 2347 | + * @return void |
|
| 2348 | + * @throws \EE_Error |
|
| 2349 | + */ |
|
| 2350 | + protected function _update_default_event_settings() |
|
| 2351 | + { |
|
| 2352 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2353 | + $form = $this->_default_event_settings_form(); |
|
| 2354 | + if ($form->was_submitted()) { |
|
| 2355 | + $form->receive_form_submission(); |
|
| 2356 | + if ($form->is_valid()) { |
|
| 2357 | + $valid_data = $form->valid_data(); |
|
| 2358 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2359 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2360 | + } |
|
| 2361 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2362 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2363 | + } |
|
| 2364 | + //update because data was valid! |
|
| 2365 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2366 | + EE_Error::overwrite_success(); |
|
| 2367 | + EE_Error::add_success( |
|
| 2368 | + __('Default Event Settings were updated', 'event_espresso') |
|
| 2369 | + ); |
|
| 2370 | + } |
|
| 2371 | + } |
|
| 2372 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + |
|
| 2377 | + /************* Templates *************/ |
|
| 2378 | + protected function _template_settings() |
|
| 2379 | + { |
|
| 2380 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2381 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2382 | + . EVENTS_ASSETS_URL |
|
| 2383 | + . DS |
|
| 2384 | + . 'images' |
|
| 2385 | + . DS |
|
| 2386 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2387 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2388 | + . '" />'; |
|
| 2389 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2390 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2391 | + 'event_espresso' |
|
| 2392 | + ) . '</strong>'; |
|
| 2393 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2394 | + } |
|
| 2395 | + |
|
| 2396 | + |
|
| 2397 | + /** Event Category Stuff **/ |
|
| 2398 | + /** |
|
| 2399 | + * set the _category property with the category object for the loaded page. |
|
| 2400 | + * |
|
| 2401 | + * @access private |
|
| 2402 | + * @return void |
|
| 2403 | + */ |
|
| 2404 | + private function _set_category_object() |
|
| 2405 | + { |
|
| 2406 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2407 | + return; |
|
| 2408 | + } //already have the category object so get out. |
|
| 2409 | + //set default category object |
|
| 2410 | + $this->_set_empty_category_object(); |
|
| 2411 | + //only set if we've got an id |
|
| 2412 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2413 | + return; |
|
| 2414 | + } |
|
| 2415 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2416 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2417 | + if ( ! empty($term)) { |
|
| 2418 | + $this->_category->category_name = $term->name; |
|
| 2419 | + $this->_category->category_identifier = $term->slug; |
|
| 2420 | + $this->_category->category_desc = $term->description; |
|
| 2421 | + $this->_category->id = $term->term_id; |
|
| 2422 | + $this->_category->parent = $term->parent; |
|
| 2423 | + } |
|
| 2424 | + } |
|
| 2425 | + |
|
| 2426 | + |
|
| 2427 | + |
|
| 2428 | + private function _set_empty_category_object() |
|
| 2429 | + { |
|
| 2430 | + $this->_category = new stdClass(); |
|
| 2431 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2432 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2433 | + } |
|
| 2434 | + |
|
| 2435 | + |
|
| 2436 | + |
|
| 2437 | + protected function _category_list_table() |
|
| 2438 | + { |
|
| 2439 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2440 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2441 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2442 | + 'add_category', |
|
| 2443 | + 'add_category', |
|
| 2444 | + array(), |
|
| 2445 | + 'add-new-h2' |
|
| 2446 | + ); |
|
| 2447 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * @param $view |
|
| 2454 | + */ |
|
| 2455 | + protected function _category_details($view) |
|
| 2456 | + { |
|
| 2457 | + //load formatter helper |
|
| 2458 | + //load field generator helper |
|
| 2459 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2460 | + $this->_set_add_edit_form_tags($route); |
|
| 2461 | + $this->_set_category_object(); |
|
| 2462 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2463 | + $delete_action = 'delete_category'; |
|
| 2464 | + //custom redirect |
|
| 2465 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2466 | + array('action' => 'category_list'), |
|
| 2467 | + $this->_admin_base_url |
|
| 2468 | + ); |
|
| 2469 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2470 | + //take care of contents |
|
| 2471 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2472 | + $this->display_admin_page_with_sidebar(); |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + /** |
|
| 2478 | + * @return mixed |
|
| 2479 | + */ |
|
| 2480 | + protected function _category_details_content() |
|
| 2481 | + { |
|
| 2482 | + $editor_args['category_desc'] = array( |
|
| 2483 | + 'type' => 'wp_editor', |
|
| 2484 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2485 | + 'class' => 'my_editor_custom', |
|
| 2486 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2487 | + ); |
|
| 2488 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2489 | + $all_terms = get_terms( |
|
| 2490 | + array('espresso_event_categories'), |
|
| 2491 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2492 | + ); |
|
| 2493 | + //setup category select for term parents. |
|
| 2494 | + $category_select_values[] = array( |
|
| 2495 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2496 | + 'id' => 0, |
|
| 2497 | + ); |
|
| 2498 | + foreach ($all_terms as $term) { |
|
| 2499 | + $category_select_values[] = array( |
|
| 2500 | + 'text' => $term->name, |
|
| 2501 | + 'id' => $term->term_id, |
|
| 2502 | + ); |
|
| 2503 | + } |
|
| 2504 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2505 | + 'category_parent', |
|
| 2506 | + $category_select_values, |
|
| 2507 | + $this->_category->parent |
|
| 2508 | + ); |
|
| 2509 | + $template_args = array( |
|
| 2510 | + 'category' => $this->_category, |
|
| 2511 | + 'category_select' => $category_select, |
|
| 2512 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2513 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2514 | + 'disable' => '', |
|
| 2515 | + 'disabled_message' => false, |
|
| 2516 | + ); |
|
| 2517 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2518 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + |
|
| 2522 | + |
|
| 2523 | + protected function _delete_categories() |
|
| 2524 | + { |
|
| 2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | + : (array)$this->_req_data['category_id']; |
|
| 2527 | + foreach ($cat_ids as $cat_id) { |
|
| 2528 | + $this->_delete_category($cat_id); |
|
| 2529 | + } |
|
| 2530 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2531 | + $query_args = array( |
|
| 2532 | + 'action' => 'category_list', |
|
| 2533 | + ); |
|
| 2534 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + /** |
|
| 2540 | + * @param $cat_id |
|
| 2541 | + */ |
|
| 2542 | + protected function _delete_category($cat_id) |
|
| 2543 | + { |
|
| 2544 | + $cat_id = absint($cat_id); |
|
| 2545 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2546 | + } |
|
| 2547 | + |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + /** |
|
| 2551 | + * @param $new_category |
|
| 2552 | + */ |
|
| 2553 | + protected function _insert_or_update_category($new_category) |
|
| 2554 | + { |
|
| 2555 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2556 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2557 | + if ($cat_id) { |
|
| 2558 | + $query_args = array( |
|
| 2559 | + 'action' => 'edit_category', |
|
| 2560 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2561 | + ); |
|
| 2562 | + } else { |
|
| 2563 | + $query_args = array('action' => 'add_category'); |
|
| 2564 | + } |
|
| 2565 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * @param bool $update |
|
| 2572 | + * @return bool|mixed|string |
|
| 2573 | + */ |
|
| 2574 | + private function _insert_category($update = false) |
|
| 2575 | + { |
|
| 2576 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2577 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2578 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2579 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2580 | + if (empty($category_name)) { |
|
| 2581 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2582 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2583 | + return false; |
|
| 2584 | + } |
|
| 2585 | + $term_args = array( |
|
| 2586 | + 'name' => $category_name, |
|
| 2587 | + 'description' => $category_desc, |
|
| 2588 | + 'parent' => $category_parent, |
|
| 2589 | + ); |
|
| 2590 | + //was the category_identifier input disabled? |
|
| 2591 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2592 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2593 | + } |
|
| 2594 | + $insert_ids = $update |
|
| 2595 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2596 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2597 | + if ( ! is_array($insert_ids)) { |
|
| 2598 | + $msg = esc_html__( |
|
| 2599 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2600 | + 'event_espresso' |
|
| 2601 | + ); |
|
| 2602 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2603 | + } else { |
|
| 2604 | + $cat_id = $insert_ids['term_id']; |
|
| 2605 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2606 | + EE_Error::add_success($msg); |
|
| 2607 | + } |
|
| 2608 | + return $cat_id; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * @param int $per_page |
|
| 2615 | + * @param int $current_page |
|
| 2616 | + * @param bool $count |
|
| 2617 | + * @return \EE_Base_Class[]|int |
|
| 2618 | + */ |
|
| 2619 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2620 | + { |
|
| 2621 | + //testing term stuff |
|
| 2622 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2623 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2624 | + $limit = ($current_page - 1) * $per_page; |
|
| 2625 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2626 | + if (isset($this->_req_data['s'])) { |
|
| 2627 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2628 | + $where['OR'] = array( |
|
| 2629 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2630 | + 'description' => array('LIKE', $sstr), |
|
| 2631 | + ); |
|
| 2632 | + } |
|
| 2633 | + $query_params = array( |
|
| 2634 | + $where, |
|
| 2635 | + 'order_by' => array($orderby => $order), |
|
| 2636 | + 'limit' => $limit . ',' . $per_page, |
|
| 2637 | + 'force_join' => array('Term'), |
|
| 2638 | + ); |
|
| 2639 | + $categories = $count |
|
| 2640 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2641 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2642 | + return $categories; |
|
| 2643 | + } |
|
| 2644 | + |
|
| 2645 | + |
|
| 2646 | + |
|
| 2647 | + /* end category stuff */ |
|
| 2648 | + /**************/ |
|
| 2649 | 2649 | } |
| 2650 | 2650 | //end class Events_Admin_Page |
@@ -536,11 +536,11 @@ discard block |
||
| 536 | 536 | { |
| 537 | 537 | wp_register_style( |
| 538 | 538 | 'events-admin-css', |
| 539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 539 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 540 | 540 | array(), |
| 541 | 541 | EVENT_ESPRESSO_VERSION |
| 542 | 542 | ); |
| 543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | 544 | wp_enqueue_style('events-admin-css'); |
| 545 | 545 | wp_enqueue_style('ee-cat-admin'); |
| 546 | 546 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | //scripts |
| 549 | 549 | wp_register_script( |
| 550 | 550 | 'event_editor_js', |
| 551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 551 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 552 | 552 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
| 553 | 553 | EVENT_ESPRESSO_VERSION, |
| 554 | 554 | true |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | wp_enqueue_style('espresso-ui-theme'); |
| 581 | 581 | wp_register_style( |
| 582 | 582 | 'event-editor-css', |
| 583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 583 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 584 | 584 | array('ee-admin-css'), |
| 585 | 585 | EVENT_ESPRESSO_VERSION |
| 586 | 586 | ); |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | //scripts |
| 589 | 589 | wp_register_script( |
| 590 | 590 | 'event-datetime-metabox', |
| 591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 591 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 592 | 592 | array('event_editor_js', 'ee-datepicker'), |
| 593 | 593 | EVENT_ESPRESSO_VERSION |
| 594 | 594 | ); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
| 755 | 755 | 'event_espresso' |
| 756 | 756 | ), |
| 757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 757 | + '<a href="'.admin_url('options-general.php').'">', |
|
| 758 | 758 | '</a>' |
| 759 | 759 | ), |
| 760 | 760 | __FILE__, |
@@ -824,31 +824,31 @@ discard block |
||
| 824 | 824 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 825 | 825 | $statuses = array( |
| 826 | 826 | 'sold_out_status' => array( |
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 828 | 828 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 829 | 829 | ), |
| 830 | 830 | 'active_status' => array( |
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 832 | 832 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 833 | 833 | ), |
| 834 | 834 | 'upcoming_status' => array( |
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 836 | 836 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 837 | 837 | ), |
| 838 | 838 | 'postponed_status' => array( |
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 840 | 840 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 841 | 841 | ), |
| 842 | 842 | 'cancelled_status' => array( |
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 844 | 844 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 845 | 845 | ), |
| 846 | 846 | 'expired_status' => array( |
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 848 | 848 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 849 | 849 | ), |
| 850 | 850 | 'inactive_status' => array( |
| 851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 851 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 852 | 852 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 853 | 853 | ), |
| 854 | 854 | ); |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | { |
| 913 | 913 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 914 | 914 | $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
| 915 | - ? (array)$this->_template_args['after_list_table'] |
|
| 915 | + ? (array) $this->_template_args['after_list_table'] |
|
| 916 | 916 | : array(); |
| 917 | 917 | $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
| 918 | 918 | . EEH_Template::get_button_or_link( |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | 'button' |
| 922 | 922 | ); |
| 923 | 923 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 924 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 925 | 925 | 'create_new', |
| 926 | 926 | 'add', |
| 927 | 927 | array(), |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | */ |
| 1052 | 1052 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
| 1053 | 1053 | { |
| 1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1054 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1055 | 1055 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1056 | 1056 | $rows_affected = null; |
| 1057 | 1057 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | if (empty($tkt['TKT_start_date'])) { |
| 1176 | 1176 | //let's use now in the set timezone. |
| 1177 | 1177 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | if (empty($tkt['TKT_end_date'])) { |
| 1181 | 1181 | //use the start date of the first datetime |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1465 | 1465 | // load template |
| 1466 | 1466 | EEH_Template::display_template( |
| 1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1467 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1468 | 1468 | $publish_box_extra_args |
| 1469 | 1469 | ); |
| 1470 | 1470 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | ); |
| 1592 | 1592 | $template = apply_filters( |
| 1593 | 1593 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1594 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1595 | 1595 | ); |
| 1596 | 1596 | EEH_Template::display_template($template, $template_args); |
| 1597 | 1597 | } |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1611 | 1611 | { |
| 1612 | 1612 | $template_args = array( |
| 1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1613 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1614 | 1614 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1615 | 1615 | : '', |
| 1616 | 1616 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1664,7 +1664,7 @@ discard block |
||
| 1664 | 1664 | $template_args = array_merge($template_args, $price_args); |
| 1665 | 1665 | $template = apply_filters( |
| 1666 | 1666 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1667 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | 1668 | $ticket |
| 1669 | 1669 | ); |
| 1670 | 1670 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1716,7 +1716,7 @@ discard block |
||
| 1716 | 1716 | $default_reg_status_values |
| 1717 | 1717 | ); |
| 1718 | 1718 | EEH_Template::display_template( |
| 1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1719 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1720 | 1720 | $template_args |
| 1721 | 1721 | ); |
| 1722 | 1722 | } |
@@ -1739,7 +1739,7 @@ discard block |
||
| 1739 | 1739 | { |
| 1740 | 1740 | $EEME = $this->_event_model(); |
| 1741 | 1741 | $offset = ($current_page - 1) * $per_page; |
| 1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1742 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1743 | 1743 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1744 | 1744 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
| 1745 | 1745 | if (isset($this->_req_data['month_range'])) { |
@@ -1776,7 +1776,7 @@ discard block |
||
| 1776 | 1776 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1777 | 1777 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
| 1778 | 1778 | $DateTime = new DateTime( |
| 1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1779 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1780 | 1780 | new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
| 1781 | 1781 | ); |
| 1782 | 1782 | $start = $DateTime->format(implode(' ', $start_formats)); |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | } |
| 1823 | 1823 | //search query handling |
| 1824 | 1824 | if (isset($this->_req_data['s'])) { |
| 1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1825 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1826 | 1826 | $where['OR'] = array( |
| 1827 | 1827 | 'EVT_name' => array('LIKE', $search_string), |
| 1828 | 1828 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1956,7 +1956,7 @@ discard block |
||
| 1956 | 1956 | if ( ! empty($event_status)) { |
| 1957 | 1957 | $success = true; |
| 1958 | 1958 | //determine the event id and set to array. |
| 1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | 1960 | // loop thru events |
| 1961 | 1961 | foreach ($EVT_IDs as $EVT_ID) { |
| 1962 | 1962 | if ($EVT_ID = absint($EVT_ID)) { |
@@ -2104,7 +2104,7 @@ discard block |
||
| 2104 | 2104 | // get list of events with no prices |
| 2105 | 2105 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
| 2106 | 2106 | //determine the event id and set to array. |
| 2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | 2108 | // loop thru events |
| 2109 | 2109 | foreach ($EVT_IDs as $EVT_ID) { |
| 2110 | 2110 | $EVT_ID = absint($EVT_ID); |
@@ -2324,7 +2324,7 @@ discard block |
||
| 2324 | 2324 | 'html_label_text' => esc_html__( |
| 2325 | 2325 | 'Default Maximum Tickets Allowed Per Order:', |
| 2326 | 2326 | 'event_espresso' |
| 2327 | - ) . EEH_Template::get_help_tab_link( |
|
| 2327 | + ).EEH_Template::get_help_tab_link( |
|
| 2328 | 2328 | 'default_maximum_tickets_help_tab"' |
| 2329 | 2329 | ), |
| 2330 | 2330 | 'html_help_text' => esc_html__( |
@@ -2386,10 +2386,10 @@ discard block |
||
| 2386 | 2386 | . 'caffeinated_template_features.jpg" alt="' |
| 2387 | 2387 | . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
| 2388 | 2388 | . '" />'; |
| 2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2389 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__( |
|
| 2390 | 2390 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2391 | 2391 | 'event_espresso' |
| 2392 | - ) . '</strong>'; |
|
| 2392 | + ).'</strong>'; |
|
| 2393 | 2393 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2394 | 2394 | } |
| 2395 | 2395 | |
@@ -2438,7 +2438,7 @@ discard block |
||
| 2438 | 2438 | { |
| 2439 | 2439 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2440 | 2440 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2441 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2442 | 2442 | 'add_category', |
| 2443 | 2443 | 'add_category', |
| 2444 | 2444 | array(), |
@@ -2514,7 +2514,7 @@ discard block |
||
| 2514 | 2514 | 'disable' => '', |
| 2515 | 2515 | 'disabled_message' => false, |
| 2516 | 2516 | ); |
| 2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2517 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2518 | 2518 | return EEH_Template::display_template($template, $template_args, true); |
| 2519 | 2519 | } |
| 2520 | 2520 | |
@@ -2522,8 +2522,8 @@ discard block |
||
| 2522 | 2522 | |
| 2523 | 2523 | protected function _delete_categories() |
| 2524 | 2524 | { |
| 2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | - : (array)$this->_req_data['category_id']; |
|
| 2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2526 | + : (array) $this->_req_data['category_id']; |
|
| 2527 | 2527 | foreach ($cat_ids as $cat_id) { |
| 2528 | 2528 | $this->_delete_category($cat_id); |
| 2529 | 2529 | } |
@@ -2624,7 +2624,7 @@ discard block |
||
| 2624 | 2624 | $limit = ($current_page - 1) * $per_page; |
| 2625 | 2625 | $where = array('taxonomy' => 'espresso_event_categories'); |
| 2626 | 2626 | if (isset($this->_req_data['s'])) { |
| 2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2627 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2628 | 2628 | $where['OR'] = array( |
| 2629 | 2629 | 'Term.name' => array('LIKE', $sstr), |
| 2630 | 2630 | 'description' => array('LIKE', $sstr), |
@@ -2633,7 +2633,7 @@ discard block |
||
| 2633 | 2633 | $query_params = array( |
| 2634 | 2634 | $where, |
| 2635 | 2635 | 'order_by' => array($orderby => $order), |
| 2636 | - 'limit' => $limit . ',' . $per_page, |
|
| 2636 | + 'limit' => $limit.','.$per_page, |
|
| 2637 | 2637 | 'force_join' => array('Term'), |
| 2638 | 2638 | ); |
| 2639 | 2639 | $categories = $count |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <p> |
| 2 | 2 | <?php esc_html_e( |
| 3 | - 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
| 4 | - 'event_espresso' |
|
| 5 | - ); ?> |
|
| 3 | + 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
| 4 | + 'event_espresso' |
|
| 5 | + ); ?> |
|
| 6 | 6 | </p> |
| 7 | 7 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | 6 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function __construct() |
| 50 | 50 | { |
| 51 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
| 51 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | $this->_load_class_tools(); |
| 99 | 99 | // load interfaces |
| 100 | 100 | espresso_load_required('EEI_Payment_Method_Interfaces', |
| 101 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
| 101 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
| 102 | 102 | // deprecated functions |
| 103 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 103 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
| 104 | 104 | // WP cron jobs |
| 105 | 105 | $this->registry->load_core('Cron_Tasks'); |
| 106 | 106 | $this->registry->load_core('EE_Request_Handler'); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public function dependency_map() |
| 138 | 138 | { |
| 139 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
| 139 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
| 140 | 140 | throw new EE_Error( |
| 141 | 141 | sprintf( |
| 142 | 142 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function registry() |
| 157 | 157 | { |
| 158 | - if (! $this->registry instanceof EE_Registry) { |
|
| 158 | + if ( ! $this->registry instanceof EE_Registry) { |
|
| 159 | 159 | throw new EE_Error( |
| 160 | 160 | sprintf( |
| 161 | 161 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | private function _load_dependency_map() |
| 175 | 175 | { |
| 176 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
| 176 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
| 177 | 177 | EE_Error::add_error( |
| 178 | 178 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
| 179 | 179 | __FILE__, __FUNCTION__, __LINE__ |
| 180 | 180 | ); |
| 181 | 181 | wp_die(EE_Error::get_notices()); |
| 182 | 182 | } |
| 183 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
| 183 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
| 184 | 184 | return EE_Dependency_Map::instance($this->request, $this->response); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | private function _load_registry() |
| 193 | 193 | { |
| 194 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
| 194 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
| 195 | 195 | EE_Error::add_error( |
| 196 | 196 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
| 197 | 197 | __FILE__, __FUNCTION__, __LINE__ |
| 198 | 198 | ); |
| 199 | 199 | wp_die(EE_Error::get_notices()); |
| 200 | 200 | } |
| 201 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
| 201 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
| 202 | 202 | return EE_Registry::instance($this->dependency_map); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | private function _load_class_tools() |
| 211 | 211 | { |
| 212 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
| 212 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
| 213 | 213 | EE_Error::add_error( |
| 214 | 214 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
| 215 | 215 | __FILE__, __FUNCTION__, __LINE__ |
| 216 | 216 | ); |
| 217 | 217 | } |
| 218 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 218 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -21,212 +21,212 @@ discard block |
||
| 21 | 21 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var EE_Request $request |
|
| 26 | - */ |
|
| 27 | - protected $request; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var EE_Response $response |
|
| 31 | - */ |
|
| 32 | - protected $response; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EE_Dependency_Map $dependency_map |
|
| 36 | - */ |
|
| 37 | - protected $dependency_map; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var EE_Registry $registry |
|
| 41 | - */ |
|
| 42 | - protected $registry; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * EE_Load_Espresso_Core constructor |
|
| 48 | - */ |
|
| 49 | - public function __construct() |
|
| 50 | - { |
|
| 51 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * handle |
|
| 58 | - * sets hooks for running rest of system |
|
| 59 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 60 | - * starting EE Addons from any other point may lead to problems |
|
| 61 | - * |
|
| 62 | - * @param EE_Request $request |
|
| 63 | - * @param EE_Response $response |
|
| 64 | - * @return EE_Response |
|
| 65 | - * @throws EE_Error |
|
| 66 | - */ |
|
| 67 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
| 68 | - { |
|
| 69 | - $this->request = $request; |
|
| 70 | - $this->response = $response; |
|
| 71 | - // info about how to load classes required by other classes |
|
| 72 | - $this->dependency_map = $this->_load_dependency_map(); |
|
| 73 | - // central repository for classes |
|
| 74 | - $this->registry = $this->_load_registry(); |
|
| 75 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
| 76 | - // PSR4 Autoloaders |
|
| 77 | - $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
| 78 | - // build DI container |
|
| 79 | - $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
| 80 | - $OpenCoffeeShop->addRecipes(); |
|
| 81 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
| 82 | - // create and cache the CommandBus, and also add the CapChecker middleware |
|
| 83 | - $this->registry->create( |
|
| 84 | - 'CommandBusInterface', |
|
| 85 | - array( |
|
| 86 | - null, |
|
| 87 | - $this->registry->create('CapChecker'), |
|
| 88 | - ), |
|
| 89 | - true |
|
| 90 | - ); |
|
| 91 | - // workarounds for PHP < 5.3 |
|
| 92 | - $this->_load_class_tools(); |
|
| 93 | - // load interfaces |
|
| 94 | - espresso_load_required('EEI_Payment_Method_Interfaces', |
|
| 95 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
| 96 | - // deprecated functions |
|
| 97 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 98 | - // WP cron jobs |
|
| 99 | - $this->registry->load_core('Cron_Tasks'); |
|
| 100 | - $this->registry->load_core('EE_Request_Handler'); |
|
| 101 | - $this->registry->load_core('EE_System'); |
|
| 102 | - return $this->response; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return EE_Request |
|
| 109 | - */ |
|
| 110 | - public function request() |
|
| 111 | - { |
|
| 112 | - return $this->request; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return EE_Response |
|
| 119 | - */ |
|
| 120 | - public function response() |
|
| 121 | - { |
|
| 122 | - return $this->response; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public function dependency_map() |
|
| 132 | - { |
|
| 133 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
| 134 | - throw new EE_Error( |
|
| 135 | - sprintf( |
|
| 136 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
| 137 | - print_r($this->dependency_map, true) |
|
| 138 | - ) |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - return $this->dependency_map; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return EE_Registry |
|
| 148 | - * @throws EE_Error |
|
| 149 | - */ |
|
| 150 | - public function registry() |
|
| 151 | - { |
|
| 152 | - if (! $this->registry instanceof EE_Registry) { |
|
| 153 | - throw new EE_Error( |
|
| 154 | - sprintf( |
|
| 155 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
| 156 | - print_r($this->registry, true) |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - return $this->registry; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @return EE_Dependency_Map |
|
| 167 | - */ |
|
| 168 | - private function _load_dependency_map() |
|
| 169 | - { |
|
| 170 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
| 171 | - EE_Error::add_error( |
|
| 172 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
| 173 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 174 | - ); |
|
| 175 | - wp_die(EE_Error::get_notices()); |
|
| 176 | - } |
|
| 177 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
| 178 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return EE_Registry |
|
| 185 | - */ |
|
| 186 | - private function _load_registry() |
|
| 187 | - { |
|
| 188 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
| 189 | - EE_Error::add_error( |
|
| 190 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
| 191 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 192 | - ); |
|
| 193 | - wp_die(EE_Error::get_notices()); |
|
| 194 | - } |
|
| 195 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
| 196 | - return EE_Registry::instance($this->dependency_map); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - private function _load_class_tools() |
|
| 205 | - { |
|
| 206 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
| 207 | - EE_Error::add_error( |
|
| 208 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
| 209 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * called after the request stack has been fully processed |
|
| 219 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 220 | - * |
|
| 221 | - * @param EE_Request $request |
|
| 222 | - * @param EE_Response $response |
|
| 223 | - */ |
|
| 224 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
| 225 | - { |
|
| 226 | - if ($response->plugin_deactivated()) { |
|
| 227 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 228 | - } |
|
| 229 | - } |
|
| 24 | + /** |
|
| 25 | + * @var EE_Request $request |
|
| 26 | + */ |
|
| 27 | + protected $request; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var EE_Response $response |
|
| 31 | + */ |
|
| 32 | + protected $response; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EE_Dependency_Map $dependency_map |
|
| 36 | + */ |
|
| 37 | + protected $dependency_map; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var EE_Registry $registry |
|
| 41 | + */ |
|
| 42 | + protected $registry; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * EE_Load_Espresso_Core constructor |
|
| 48 | + */ |
|
| 49 | + public function __construct() |
|
| 50 | + { |
|
| 51 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * handle |
|
| 58 | + * sets hooks for running rest of system |
|
| 59 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 60 | + * starting EE Addons from any other point may lead to problems |
|
| 61 | + * |
|
| 62 | + * @param EE_Request $request |
|
| 63 | + * @param EE_Response $response |
|
| 64 | + * @return EE_Response |
|
| 65 | + * @throws EE_Error |
|
| 66 | + */ |
|
| 67 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
| 68 | + { |
|
| 69 | + $this->request = $request; |
|
| 70 | + $this->response = $response; |
|
| 71 | + // info about how to load classes required by other classes |
|
| 72 | + $this->dependency_map = $this->_load_dependency_map(); |
|
| 73 | + // central repository for classes |
|
| 74 | + $this->registry = $this->_load_registry(); |
|
| 75 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
| 76 | + // PSR4 Autoloaders |
|
| 77 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
| 78 | + // build DI container |
|
| 79 | + $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
| 80 | + $OpenCoffeeShop->addRecipes(); |
|
| 81 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
| 82 | + // create and cache the CommandBus, and also add the CapChecker middleware |
|
| 83 | + $this->registry->create( |
|
| 84 | + 'CommandBusInterface', |
|
| 85 | + array( |
|
| 86 | + null, |
|
| 87 | + $this->registry->create('CapChecker'), |
|
| 88 | + ), |
|
| 89 | + true |
|
| 90 | + ); |
|
| 91 | + // workarounds for PHP < 5.3 |
|
| 92 | + $this->_load_class_tools(); |
|
| 93 | + // load interfaces |
|
| 94 | + espresso_load_required('EEI_Payment_Method_Interfaces', |
|
| 95 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
| 96 | + // deprecated functions |
|
| 97 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 98 | + // WP cron jobs |
|
| 99 | + $this->registry->load_core('Cron_Tasks'); |
|
| 100 | + $this->registry->load_core('EE_Request_Handler'); |
|
| 101 | + $this->registry->load_core('EE_System'); |
|
| 102 | + return $this->response; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return EE_Request |
|
| 109 | + */ |
|
| 110 | + public function request() |
|
| 111 | + { |
|
| 112 | + return $this->request; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return EE_Response |
|
| 119 | + */ |
|
| 120 | + public function response() |
|
| 121 | + { |
|
| 122 | + return $this->response; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public function dependency_map() |
|
| 132 | + { |
|
| 133 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
| 134 | + throw new EE_Error( |
|
| 135 | + sprintf( |
|
| 136 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
| 137 | + print_r($this->dependency_map, true) |
|
| 138 | + ) |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + return $this->dependency_map; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return EE_Registry |
|
| 148 | + * @throws EE_Error |
|
| 149 | + */ |
|
| 150 | + public function registry() |
|
| 151 | + { |
|
| 152 | + if (! $this->registry instanceof EE_Registry) { |
|
| 153 | + throw new EE_Error( |
|
| 154 | + sprintf( |
|
| 155 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
| 156 | + print_r($this->registry, true) |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + return $this->registry; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @return EE_Dependency_Map |
|
| 167 | + */ |
|
| 168 | + private function _load_dependency_map() |
|
| 169 | + { |
|
| 170 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
| 171 | + EE_Error::add_error( |
|
| 172 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
| 173 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 174 | + ); |
|
| 175 | + wp_die(EE_Error::get_notices()); |
|
| 176 | + } |
|
| 177 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
| 178 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return EE_Registry |
|
| 185 | + */ |
|
| 186 | + private function _load_registry() |
|
| 187 | + { |
|
| 188 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
| 189 | + EE_Error::add_error( |
|
| 190 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
| 191 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 192 | + ); |
|
| 193 | + wp_die(EE_Error::get_notices()); |
|
| 194 | + } |
|
| 195 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
| 196 | + return EE_Registry::instance($this->dependency_map); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + private function _load_class_tools() |
|
| 205 | + { |
|
| 206 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
| 207 | + EE_Error::add_error( |
|
| 208 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
| 209 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * called after the request stack has been fully processed |
|
| 219 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 220 | + * |
|
| 221 | + * @param EE_Request $request |
|
| 222 | + * @param EE_Response $response |
|
| 223 | + */ |
|
| 224 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
| 225 | + { |
|
| 226 | + if ($response->plugin_deactivated()) { |
|
| 227 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | |
| 232 | 232 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 106 | 106 | { |
| 107 | 107 | // check if class object is instantiated, and instantiated properly |
| 108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 108 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | 109 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 110 | 110 | } |
| 111 | 111 | return self::$_instance; |
@@ -120,15 +120,15 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public static function register_dependencies($class, $dependencies) |
| 122 | 122 | { |
| 123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 123 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | 124 | // we need to make sure that any aliases used when registering a dependency |
| 125 | 125 | // get resolved to the correct class name |
| 126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 126 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 127 | 127 | $alias = self::$_instance->get_alias($dependency); |
| 128 | 128 | unset($dependencies[$dependency]); |
| 129 | 129 | $dependencies[$alias] = $load_source; |
| 130 | 130 | } |
| 131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 131 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
| 132 | 132 | return true; |
| 133 | 133 | } |
| 134 | 134 | return false; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | ); |
| 155 | 155 | } |
| 156 | 156 | $class_name = self::$_instance->get_alias($class_name); |
| 157 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 157 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 158 | 158 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 159 | 159 | return true; |
| 160 | 160 | } |
@@ -476,10 +476,10 @@ discard block |
||
| 476 | 476 | 'EE_Front_Controller' => 'load_core', |
| 477 | 477 | 'EE_Module_Request_Router' => 'load_core', |
| 478 | 478 | 'EE_Registry' => 'load_core', |
| 479 | - 'EE_Request' => function () use (&$request) { |
|
| 479 | + 'EE_Request' => function() use (&$request) { |
|
| 480 | 480 | return $request; |
| 481 | 481 | }, |
| 482 | - 'EE_Response' => function () use (&$response) { |
|
| 482 | + 'EE_Response' => function() use (&$response) { |
|
| 483 | 483 | return $response; |
| 484 | 484 | }, |
| 485 | 485 | 'EE_Request_Handler' => 'load_core', |
@@ -496,17 +496,17 @@ discard block |
||
| 496 | 496 | 'EE_Messages_Queue' => 'load_lib', |
| 497 | 497 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 498 | 498 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 499 | - 'EE_Messages_Generator' => function () { |
|
| 499 | + 'EE_Messages_Generator' => function() { |
|
| 500 | 500 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
| 501 | 501 | }, |
| 502 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 502 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 503 | 503 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
| 504 | 504 | }, |
| 505 | 505 | //load_model |
| 506 | 506 | 'EEM_Message_Template_Group' => 'load_model', |
| 507 | 507 | 'EEM_Message_Template' => 'load_model', |
| 508 | 508 | //load_helper |
| 509 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 509 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 510 | 510 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 511 | 511 | return new EEH_Parse_Shortcodes(); |
| 512 | 512 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('No direct script access allowed'); |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -18,543 +18,543 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * This means that the requested class dependency is not present in the dependency map |
|
| 23 | - */ |
|
| 24 | - const not_registered = 0; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 29 | - */ |
|
| 30 | - const load_new_object = 1; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 34 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 35 | - */ |
|
| 36 | - const load_from_cache = 2; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @type EE_Dependency_Map $_instance |
|
| 40 | - */ |
|
| 41 | - protected static $_instance; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @type EE_Request $request |
|
| 45 | - */ |
|
| 46 | - protected $_request; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @type EE_Response $response |
|
| 50 | - */ |
|
| 51 | - protected $_response; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @type array $_dependency_map |
|
| 56 | - */ |
|
| 57 | - protected $_dependency_map = array(); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type array $_class_loaders |
|
| 61 | - */ |
|
| 62 | - protected $_class_loaders = array(); |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type array $_aliases |
|
| 66 | - */ |
|
| 67 | - protected $_aliases = array(); |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * EE_Dependency_Map constructor. |
|
| 73 | - * |
|
| 74 | - * @param EE_Request $request |
|
| 75 | - * @param EE_Response $response |
|
| 76 | - */ |
|
| 77 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 78 | - { |
|
| 79 | - $this->_request = $request; |
|
| 80 | - $this->_response = $response; |
|
| 81 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 82 | - do_action('EE_Dependency_Map____construct'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - */ |
|
| 89 | - public function initialize() |
|
| 90 | - { |
|
| 91 | - $this->_register_core_dependencies(); |
|
| 92 | - $this->_register_core_class_loaders(); |
|
| 93 | - $this->_register_core_aliases(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @singleton method used to instantiate class object |
|
| 100 | - * @access public |
|
| 101 | - * @param EE_Request $request |
|
| 102 | - * @param EE_Response $response |
|
| 103 | - * @return EE_Dependency_Map instance |
|
| 104 | - */ |
|
| 105 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 106 | - { |
|
| 107 | - // check if class object is instantiated, and instantiated properly |
|
| 108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 110 | - } |
|
| 111 | - return self::$_instance; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $class |
|
| 118 | - * @param array $dependencies |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - public static function register_dependencies($class, $dependencies) |
|
| 122 | - { |
|
| 123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | - // we need to make sure that any aliases used when registering a dependency |
|
| 125 | - // get resolved to the correct class name |
|
| 126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 127 | - $alias = self::$_instance->get_alias($dependency); |
|
| 128 | - unset($dependencies[$dependency]); |
|
| 129 | - $dependencies[$alias] = $load_source; |
|
| 130 | - } |
|
| 131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $class_name |
|
| 141 | - * @param string $loader |
|
| 142 | - * @return bool |
|
| 143 | - * @throws EE_Error |
|
| 144 | - */ |
|
| 145 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 146 | - { |
|
| 147 | - // check that loader method starts with "load_" and exists in EE_Registry |
|
| 148 | - if (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) { |
|
| 149 | - throw new EE_Error( |
|
| 150 | - sprintf( |
|
| 151 | - __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 152 | - $loader |
|
| 153 | - ) |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 157 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 158 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function dependency_map() |
|
| 170 | - { |
|
| 171 | - return $this->_dependency_map; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 178 | - * |
|
| 179 | - * @param string $class_name |
|
| 180 | - * @return boolean |
|
| 181 | - */ |
|
| 182 | - public function has($class_name = '') |
|
| 183 | - { |
|
| 184 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 191 | - * |
|
| 192 | - * @param string $class_name |
|
| 193 | - * @param string $dependency |
|
| 194 | - * @return bool |
|
| 195 | - */ |
|
| 196 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 197 | - { |
|
| 198 | - $dependency = $this->get_alias($dependency); |
|
| 199 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 200 | - ? true |
|
| 201 | - : false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 208 | - * |
|
| 209 | - * @param string $class_name |
|
| 210 | - * @param string $dependency |
|
| 211 | - * @return int |
|
| 212 | - */ |
|
| 213 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 214 | - { |
|
| 215 | - $dependency = $this->get_alias($dependency); |
|
| 216 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 217 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 218 | - : EE_Dependency_Map::not_registered; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @param string $class_name |
|
| 225 | - * @return string | Closure |
|
| 226 | - */ |
|
| 227 | - public function class_loader($class_name) |
|
| 228 | - { |
|
| 229 | - $class_name = $this->get_alias($class_name); |
|
| 230 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @return array |
|
| 237 | - */ |
|
| 238 | - public function class_loaders() |
|
| 239 | - { |
|
| 240 | - return $this->_class_loaders; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * adds an alias for a classname |
|
| 247 | - * |
|
| 248 | - * @param string $class_name |
|
| 249 | - * @param string $alias |
|
| 250 | - */ |
|
| 251 | - public function add_alias($class_name, $alias) |
|
| 252 | - { |
|
| 253 | - $this->_aliases[$class_name] = $alias; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * returns TRUE if the provided class name has an alias |
|
| 260 | - * |
|
| 261 | - * @param string $class_name |
|
| 262 | - * @return boolean |
|
| 263 | - */ |
|
| 264 | - public function has_alias($class_name = '') |
|
| 265 | - { |
|
| 266 | - return isset($this->_aliases[$class_name]) ? true : false; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 273 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 274 | - * for example: |
|
| 275 | - * if the following two entries were added to the _aliases array: |
|
| 276 | - * array( |
|
| 277 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 278 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 279 | - * ) |
|
| 280 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 281 | - * to load an instance of 'some\namespace\classname' |
|
| 282 | - * |
|
| 283 | - * @param string $class_name |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function get_alias($class_name = '') |
|
| 287 | - { |
|
| 288 | - return $this->has_alias($class_name) |
|
| 289 | - ? $this->get_alias($this->_aliases[$class_name]) |
|
| 290 | - : $class_name; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 297 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 298 | - * This is done by using the following class constants: |
|
| 299 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 300 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 301 | - */ |
|
| 302 | - protected function _register_core_dependencies() |
|
| 303 | - { |
|
| 304 | - $this->_dependency_map = array( |
|
| 305 | - 'EE_Request_Handler' => array( |
|
| 306 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 307 | - ), |
|
| 308 | - 'EE_System' => array( |
|
| 309 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 310 | - ), |
|
| 311 | - 'EE_Session' => array( |
|
| 312 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 313 | - ), |
|
| 314 | - 'EE_Cart' => array( |
|
| 315 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 316 | - ), |
|
| 317 | - 'EE_Front_Controller' => array( |
|
| 318 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 319 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 320 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 321 | - ), |
|
| 322 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 323 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 324 | - ), |
|
| 325 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 326 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 327 | - ), |
|
| 328 | - 'EE_Message_Resource_Manager' => array( |
|
| 329 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 330 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 331 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 332 | - ), |
|
| 333 | - 'EE_Message_Factory' => array( |
|
| 334 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 335 | - ), |
|
| 336 | - 'EE_messages' => array( |
|
| 337 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 338 | - ), |
|
| 339 | - 'EE_Messages_Generator' => array( |
|
| 340 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 341 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 342 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 343 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 344 | - ), |
|
| 345 | - 'EE_Messages_Processor' => array( |
|
| 346 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 347 | - ), |
|
| 348 | - 'EE_Messages_Queue' => array( |
|
| 349 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 350 | - ), |
|
| 351 | - 'EE_Messages_Template_Defaults' => array( |
|
| 352 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 353 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 354 | - ), |
|
| 355 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 356 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 357 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 358 | - ), |
|
| 359 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 360 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 361 | - ), |
|
| 362 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 363 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 365 | - ), |
|
| 366 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 367 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 368 | - ), |
|
| 369 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 370 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 371 | - ), |
|
| 372 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 373 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 374 | - ), |
|
| 375 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 376 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 377 | - ), |
|
| 378 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 379 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 380 | - ), |
|
| 381 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 382 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 383 | - ), |
|
| 384 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 385 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 386 | - ), |
|
| 387 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 388 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 389 | - ), |
|
| 390 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 391 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 392 | - ), |
|
| 393 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 394 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 395 | - ), |
|
| 396 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 397 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 398 | - ), |
|
| 399 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 400 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 401 | - ), |
|
| 402 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 403 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 404 | - ), |
|
| 405 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 406 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 407 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 408 | - ), |
|
| 409 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 410 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 411 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 412 | - ), |
|
| 413 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 414 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 415 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 416 | - ), |
|
| 417 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 418 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 419 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 420 | - ), |
|
| 421 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 422 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 423 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 424 | - ), |
|
| 425 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 426 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 427 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 428 | - ), |
|
| 429 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 430 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 431 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 432 | - ), |
|
| 433 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 434 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 435 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 436 | - ), |
|
| 437 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 438 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 439 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 440 | - ), |
|
| 441 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 442 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 443 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - ), |
|
| 445 | - ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Registers how core classes are loaded. |
|
| 452 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 453 | - * 'EE_Request_Handler' => 'load_core' |
|
| 454 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 455 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 456 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 457 | - * 'Some_Class' => function () { |
|
| 458 | - * return new Some_Class(); |
|
| 459 | - * }, |
|
| 460 | - * This is required for instantiating dependencies |
|
| 461 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 462 | - * 'Required_Interface' => function () { |
|
| 463 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 464 | - * }, |
|
| 465 | - */ |
|
| 466 | - protected function _register_core_class_loaders() |
|
| 467 | - { |
|
| 468 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 469 | - //be used in a closure. |
|
| 470 | - $request = &$this->_request; |
|
| 471 | - $response = &$this->_response; |
|
| 472 | - $this->_class_loaders = array( |
|
| 473 | - //load_core |
|
| 474 | - 'EE_Capabilities' => 'load_core', |
|
| 475 | - 'EE_Encryption' => 'load_core', |
|
| 476 | - 'EE_Front_Controller' => 'load_core', |
|
| 477 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 478 | - 'EE_Registry' => 'load_core', |
|
| 479 | - 'EE_Request' => function () use (&$request) { |
|
| 480 | - return $request; |
|
| 481 | - }, |
|
| 482 | - 'EE_Response' => function () use (&$response) { |
|
| 483 | - return $response; |
|
| 484 | - }, |
|
| 485 | - 'EE_Request_Handler' => 'load_core', |
|
| 486 | - 'EE_Session' => 'load_core', |
|
| 487 | - 'EE_System' => 'load_core', |
|
| 488 | - //load_lib |
|
| 489 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 490 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 491 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 492 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 493 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 494 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 495 | - 'EE_Message_Repository' => 'load_lib', |
|
| 496 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 497 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 498 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 499 | - 'EE_Messages_Generator' => function () { |
|
| 500 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
| 501 | - }, |
|
| 502 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 503 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
| 504 | - }, |
|
| 505 | - //load_model |
|
| 506 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 507 | - 'EEM_Message_Template' => 'load_model', |
|
| 508 | - //load_helper |
|
| 509 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 510 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 511 | - return new EEH_Parse_Shortcodes(); |
|
| 512 | - } |
|
| 513 | - return null; |
|
| 514 | - }, |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * can be used for supplying alternate names for classes, |
|
| 522 | - * or for connecting interface names to instantiable classes |
|
| 523 | - */ |
|
| 524 | - protected function _register_core_aliases() |
|
| 525 | - { |
|
| 526 | - $this->_aliases = array( |
|
| 527 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 528 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 529 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 530 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 531 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 532 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 533 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 534 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 535 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 536 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 537 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 538 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 539 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 540 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 541 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 542 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 543 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 551 | - * request Primarily used by unit tests. |
|
| 552 | - */ |
|
| 553 | - public function reset() |
|
| 554 | - { |
|
| 555 | - $this->_register_core_class_loaders(); |
|
| 556 | - $this->_register_core_dependencies(); |
|
| 557 | - } |
|
| 21 | + /** |
|
| 22 | + * This means that the requested class dependency is not present in the dependency map |
|
| 23 | + */ |
|
| 24 | + const not_registered = 0; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 29 | + */ |
|
| 30 | + const load_new_object = 1; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 34 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 35 | + */ |
|
| 36 | + const load_from_cache = 2; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @type EE_Dependency_Map $_instance |
|
| 40 | + */ |
|
| 41 | + protected static $_instance; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @type EE_Request $request |
|
| 45 | + */ |
|
| 46 | + protected $_request; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @type EE_Response $response |
|
| 50 | + */ |
|
| 51 | + protected $_response; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @type array $_dependency_map |
|
| 56 | + */ |
|
| 57 | + protected $_dependency_map = array(); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type array $_class_loaders |
|
| 61 | + */ |
|
| 62 | + protected $_class_loaders = array(); |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type array $_aliases |
|
| 66 | + */ |
|
| 67 | + protected $_aliases = array(); |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * EE_Dependency_Map constructor. |
|
| 73 | + * |
|
| 74 | + * @param EE_Request $request |
|
| 75 | + * @param EE_Response $response |
|
| 76 | + */ |
|
| 77 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 78 | + { |
|
| 79 | + $this->_request = $request; |
|
| 80 | + $this->_response = $response; |
|
| 81 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 82 | + do_action('EE_Dependency_Map____construct'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + */ |
|
| 89 | + public function initialize() |
|
| 90 | + { |
|
| 91 | + $this->_register_core_dependencies(); |
|
| 92 | + $this->_register_core_class_loaders(); |
|
| 93 | + $this->_register_core_aliases(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @singleton method used to instantiate class object |
|
| 100 | + * @access public |
|
| 101 | + * @param EE_Request $request |
|
| 102 | + * @param EE_Response $response |
|
| 103 | + * @return EE_Dependency_Map instance |
|
| 104 | + */ |
|
| 105 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 106 | + { |
|
| 107 | + // check if class object is instantiated, and instantiated properly |
|
| 108 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 109 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 110 | + } |
|
| 111 | + return self::$_instance; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $class |
|
| 118 | + * @param array $dependencies |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + public static function register_dependencies($class, $dependencies) |
|
| 122 | + { |
|
| 123 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 124 | + // we need to make sure that any aliases used when registering a dependency |
|
| 125 | + // get resolved to the correct class name |
|
| 126 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 127 | + $alias = self::$_instance->get_alias($dependency); |
|
| 128 | + unset($dependencies[$dependency]); |
|
| 129 | + $dependencies[$alias] = $load_source; |
|
| 130 | + } |
|
| 131 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $class_name |
|
| 141 | + * @param string $loader |
|
| 142 | + * @return bool |
|
| 143 | + * @throws EE_Error |
|
| 144 | + */ |
|
| 145 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 146 | + { |
|
| 147 | + // check that loader method starts with "load_" and exists in EE_Registry |
|
| 148 | + if (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) { |
|
| 149 | + throw new EE_Error( |
|
| 150 | + sprintf( |
|
| 151 | + __('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 152 | + $loader |
|
| 153 | + ) |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 157 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 158 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function dependency_map() |
|
| 170 | + { |
|
| 171 | + return $this->_dependency_map; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 178 | + * |
|
| 179 | + * @param string $class_name |
|
| 180 | + * @return boolean |
|
| 181 | + */ |
|
| 182 | + public function has($class_name = '') |
|
| 183 | + { |
|
| 184 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 191 | + * |
|
| 192 | + * @param string $class_name |
|
| 193 | + * @param string $dependency |
|
| 194 | + * @return bool |
|
| 195 | + */ |
|
| 196 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 197 | + { |
|
| 198 | + $dependency = $this->get_alias($dependency); |
|
| 199 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 200 | + ? true |
|
| 201 | + : false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 208 | + * |
|
| 209 | + * @param string $class_name |
|
| 210 | + * @param string $dependency |
|
| 211 | + * @return int |
|
| 212 | + */ |
|
| 213 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 214 | + { |
|
| 215 | + $dependency = $this->get_alias($dependency); |
|
| 216 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 217 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 218 | + : EE_Dependency_Map::not_registered; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param string $class_name |
|
| 225 | + * @return string | Closure |
|
| 226 | + */ |
|
| 227 | + public function class_loader($class_name) |
|
| 228 | + { |
|
| 229 | + $class_name = $this->get_alias($class_name); |
|
| 230 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @return array |
|
| 237 | + */ |
|
| 238 | + public function class_loaders() |
|
| 239 | + { |
|
| 240 | + return $this->_class_loaders; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * adds an alias for a classname |
|
| 247 | + * |
|
| 248 | + * @param string $class_name |
|
| 249 | + * @param string $alias |
|
| 250 | + */ |
|
| 251 | + public function add_alias($class_name, $alias) |
|
| 252 | + { |
|
| 253 | + $this->_aliases[$class_name] = $alias; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * returns TRUE if the provided class name has an alias |
|
| 260 | + * |
|
| 261 | + * @param string $class_name |
|
| 262 | + * @return boolean |
|
| 263 | + */ |
|
| 264 | + public function has_alias($class_name = '') |
|
| 265 | + { |
|
| 266 | + return isset($this->_aliases[$class_name]) ? true : false; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 273 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 274 | + * for example: |
|
| 275 | + * if the following two entries were added to the _aliases array: |
|
| 276 | + * array( |
|
| 277 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 278 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 279 | + * ) |
|
| 280 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 281 | + * to load an instance of 'some\namespace\classname' |
|
| 282 | + * |
|
| 283 | + * @param string $class_name |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function get_alias($class_name = '') |
|
| 287 | + { |
|
| 288 | + return $this->has_alias($class_name) |
|
| 289 | + ? $this->get_alias($this->_aliases[$class_name]) |
|
| 290 | + : $class_name; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 297 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 298 | + * This is done by using the following class constants: |
|
| 299 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 300 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 301 | + */ |
|
| 302 | + protected function _register_core_dependencies() |
|
| 303 | + { |
|
| 304 | + $this->_dependency_map = array( |
|
| 305 | + 'EE_Request_Handler' => array( |
|
| 306 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 307 | + ), |
|
| 308 | + 'EE_System' => array( |
|
| 309 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 310 | + ), |
|
| 311 | + 'EE_Session' => array( |
|
| 312 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 313 | + ), |
|
| 314 | + 'EE_Cart' => array( |
|
| 315 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 316 | + ), |
|
| 317 | + 'EE_Front_Controller' => array( |
|
| 318 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 319 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 320 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 321 | + ), |
|
| 322 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 323 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 324 | + ), |
|
| 325 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 326 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 327 | + ), |
|
| 328 | + 'EE_Message_Resource_Manager' => array( |
|
| 329 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 330 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 331 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 332 | + ), |
|
| 333 | + 'EE_Message_Factory' => array( |
|
| 334 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 335 | + ), |
|
| 336 | + 'EE_messages' => array( |
|
| 337 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 338 | + ), |
|
| 339 | + 'EE_Messages_Generator' => array( |
|
| 340 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 341 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 342 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 343 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 344 | + ), |
|
| 345 | + 'EE_Messages_Processor' => array( |
|
| 346 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 347 | + ), |
|
| 348 | + 'EE_Messages_Queue' => array( |
|
| 349 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 350 | + ), |
|
| 351 | + 'EE_Messages_Template_Defaults' => array( |
|
| 352 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 353 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 354 | + ), |
|
| 355 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 356 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 357 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 358 | + ), |
|
| 359 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 360 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 361 | + ), |
|
| 362 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 363 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 365 | + ), |
|
| 366 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 367 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 368 | + ), |
|
| 369 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 370 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 371 | + ), |
|
| 372 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 373 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 374 | + ), |
|
| 375 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 376 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 377 | + ), |
|
| 378 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 379 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 380 | + ), |
|
| 381 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 382 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 383 | + ), |
|
| 384 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 385 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 386 | + ), |
|
| 387 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 388 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 389 | + ), |
|
| 390 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 391 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 392 | + ), |
|
| 393 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 394 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 395 | + ), |
|
| 396 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 397 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 398 | + ), |
|
| 399 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 400 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 401 | + ), |
|
| 402 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 403 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 404 | + ), |
|
| 405 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 406 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 407 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 408 | + ), |
|
| 409 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 410 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 411 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 412 | + ), |
|
| 413 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 414 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 415 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 416 | + ), |
|
| 417 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 418 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 419 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 420 | + ), |
|
| 421 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 422 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 423 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 424 | + ), |
|
| 425 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 426 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 427 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 428 | + ), |
|
| 429 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 430 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 431 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 432 | + ), |
|
| 433 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 434 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 435 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 436 | + ), |
|
| 437 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 438 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 439 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 440 | + ), |
|
| 441 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 442 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 443 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + ), |
|
| 445 | + ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Registers how core classes are loaded. |
|
| 452 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 453 | + * 'EE_Request_Handler' => 'load_core' |
|
| 454 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 455 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 456 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 457 | + * 'Some_Class' => function () { |
|
| 458 | + * return new Some_Class(); |
|
| 459 | + * }, |
|
| 460 | + * This is required for instantiating dependencies |
|
| 461 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 462 | + * 'Required_Interface' => function () { |
|
| 463 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 464 | + * }, |
|
| 465 | + */ |
|
| 466 | + protected function _register_core_class_loaders() |
|
| 467 | + { |
|
| 468 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 469 | + //be used in a closure. |
|
| 470 | + $request = &$this->_request; |
|
| 471 | + $response = &$this->_response; |
|
| 472 | + $this->_class_loaders = array( |
|
| 473 | + //load_core |
|
| 474 | + 'EE_Capabilities' => 'load_core', |
|
| 475 | + 'EE_Encryption' => 'load_core', |
|
| 476 | + 'EE_Front_Controller' => 'load_core', |
|
| 477 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 478 | + 'EE_Registry' => 'load_core', |
|
| 479 | + 'EE_Request' => function () use (&$request) { |
|
| 480 | + return $request; |
|
| 481 | + }, |
|
| 482 | + 'EE_Response' => function () use (&$response) { |
|
| 483 | + return $response; |
|
| 484 | + }, |
|
| 485 | + 'EE_Request_Handler' => 'load_core', |
|
| 486 | + 'EE_Session' => 'load_core', |
|
| 487 | + 'EE_System' => 'load_core', |
|
| 488 | + //load_lib |
|
| 489 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 490 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 491 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 492 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 493 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 494 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 495 | + 'EE_Message_Repository' => 'load_lib', |
|
| 496 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 497 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 498 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 499 | + 'EE_Messages_Generator' => function () { |
|
| 500 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
| 501 | + }, |
|
| 502 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 503 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
| 504 | + }, |
|
| 505 | + //load_model |
|
| 506 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 507 | + 'EEM_Message_Template' => 'load_model', |
|
| 508 | + //load_helper |
|
| 509 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 510 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 511 | + return new EEH_Parse_Shortcodes(); |
|
| 512 | + } |
|
| 513 | + return null; |
|
| 514 | + }, |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * can be used for supplying alternate names for classes, |
|
| 522 | + * or for connecting interface names to instantiable classes |
|
| 523 | + */ |
|
| 524 | + protected function _register_core_aliases() |
|
| 525 | + { |
|
| 526 | + $this->_aliases = array( |
|
| 527 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 528 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 529 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 530 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 531 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 532 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 533 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 534 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 535 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 536 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 537 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 538 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 539 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 540 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 541 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 542 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 543 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 551 | + * request Primarily used by unit tests. |
|
| 552 | + */ |
|
| 553 | + public function reset() |
|
| 554 | + { |
|
| 555 | + $this->_register_core_class_loaders(); |
|
| 556 | + $this->_register_core_dependencies(); |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | 559 | |
| 560 | 560 | } |
@@ -14,72 +14,72 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class ConstantsAbstract |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - private static $plugin_file =''; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * String indicating version for plugin |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - private static $version = ''; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Initializes internal static properties. |
|
| 33 | - * @param $plugin_file |
|
| 34 | - * @param $version |
|
| 35 | - */ |
|
| 36 | - public static function init($plugin_file, $version) |
|
| 37 | - { |
|
| 38 | - self::$plugin_file = $plugin_file; |
|
| 39 | - self::$version = $version; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public static function pluginFile() |
|
| 47 | - { |
|
| 48 | - return self::$plugin_file; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public static function pluginBasename() |
|
| 55 | - { |
|
| 56 | - return plugin_basename(self::$plugin_file); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public static function pluginPath() |
|
| 63 | - { |
|
| 64 | - return plugin_dir_path(self::$plugin_file); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public static function pluginUrl() |
|
| 72 | - { |
|
| 73 | - return plugin_dir_url(self::$plugin_file); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public static function version() |
|
| 81 | - { |
|
| 82 | - return self::$version; |
|
| 83 | - } |
|
| 17 | + /** |
|
| 18 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + private static $plugin_file =''; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * String indicating version for plugin |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + private static $version = ''; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Initializes internal static properties. |
|
| 33 | + * @param $plugin_file |
|
| 34 | + * @param $version |
|
| 35 | + */ |
|
| 36 | + public static function init($plugin_file, $version) |
|
| 37 | + { |
|
| 38 | + self::$plugin_file = $plugin_file; |
|
| 39 | + self::$version = $version; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public static function pluginFile() |
|
| 47 | + { |
|
| 48 | + return self::$plugin_file; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public static function pluginBasename() |
|
| 55 | + { |
|
| 56 | + return plugin_basename(self::$plugin_file); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public static function pluginPath() |
|
| 63 | + { |
|
| 64 | + return plugin_dir_path(self::$plugin_file); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public static function pluginUrl() |
|
| 72 | + { |
|
| 73 | + return plugin_dir_url(self::$plugin_file); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public static function version() |
|
| 81 | + { |
|
| 82 | + return self::$version; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | * Equivalent to `__FILE__` for main plugin file. |
| 19 | 19 | * @var string |
| 20 | 20 | */ |
| 21 | - private static $plugin_file =''; |
|
| 21 | + private static $plugin_file = ''; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -577,7 +577,7 @@ |
||
| 577 | 577 | |
| 578 | 578 | /** |
| 579 | 579 | * @param EE_State[] $state_options |
| 580 | - * @return array |
|
| 580 | + * @return EE_State[] |
|
| 581 | 581 | * @throws EE_Error |
| 582 | 582 | */ |
| 583 | 583 | public static function state_options($state_options = array()) |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,620 +16,620 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return EED_Module|EED_Add_New_State |
|
| 21 | - */ |
|
| 22 | - public static function instance() |
|
| 23 | - { |
|
| 24 | - return parent::get_instance(__CLASS__); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 40 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 41 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 42 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 43 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 44 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 46 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 48 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 49 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 50 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 52 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public static function set_hooks_admin() |
|
| 63 | - { |
|
| 64 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 65 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 66 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 67 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 68 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 69 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 70 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 71 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 72 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 73 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 74 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 75 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 76 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 77 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 78 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 79 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 80 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 81 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 82 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 83 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 84 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 85 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 86 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public static function set_definitions() |
|
| 95 | - { |
|
| 96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | - define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param WP $WP |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - public function run($WP) |
|
| 107 | - { |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return void |
|
| 114 | - */ |
|
| 115 | - public static function translate_js_strings() |
|
| 116 | - { |
|
| 117 | - EE_Registry::$i18n_js_strings['ans_no_country'] = __('In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 118 | - 'event_espresso'); |
|
| 119 | - EE_Registry::$i18n_js_strings['ans_no_name'] = __('In order to proceed, you need to enter the name of your State/Province.', |
|
| 120 | - 'event_espresso'); |
|
| 121 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = __('In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 122 | - 'event_espresso'); |
|
| 123 | - EE_Registry::$i18n_js_strings['ans_save_success'] = __('The new state was successfully saved to the database.', |
|
| 124 | - 'event_espresso'); |
|
| 125 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = __('An unknown error has occurred on the server while saving the new state to the database.', |
|
| 126 | - 'event_espresso'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return void |
|
| 133 | - */ |
|
| 134 | - public static function wp_enqueue_scripts() |
|
| 135 | - { |
|
| 136 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 137 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 138 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 139 | - wp_enqueue_script('add_new_state'); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * display_add_new_state_micro_form |
|
| 147 | - * |
|
| 148 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 149 | - * @return string |
|
| 150 | - * @throws EE_Error |
|
| 151 | - */ |
|
| 152 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 153 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 154 | - { |
|
| 155 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 156 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 157 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 158 | - // is the "state" question in this form section? |
|
| 159 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 160 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 161 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 162 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 163 | - if ($input instanceof EE_State_Select_Input) { |
|
| 164 | - $input->html_name(); |
|
| 165 | - } |
|
| 166 | - return $question_group_reg_form; |
|
| 167 | - } |
|
| 168 | - // we're only doing this for state select inputs |
|
| 169 | - if ($input instanceof EE_State_Select_Input) { |
|
| 170 | - // grab any set values from the request |
|
| 171 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 172 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 173 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 174 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 175 | - $country_options = array(); |
|
| 176 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 177 | - if (! empty($countries)) { |
|
| 178 | - foreach ($countries as $country) { |
|
| 179 | - if ($country instanceof EE_Country) { |
|
| 180 | - $country_options[$country->ID()] = $country->name(); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 185 | - array( |
|
| 186 | - 'name' => 'new_state_micro_form', |
|
| 187 | - 'html_id' => 'new_state_micro_form', |
|
| 188 | - 'layout_strategy' => new EE_No_Layout(), |
|
| 189 | - 'subsections' => array( |
|
| 190 | - // add hidden input to indicate that a new state is being added |
|
| 191 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 192 | - array( |
|
| 193 | - 'html_name' => str_replace('state', 'nsmf_add_new_state', $input->html_name()), |
|
| 194 | - 'html_id' => str_replace('state', 'nsmf_add_new_state', $input->html_id()), |
|
| 195 | - 'default' => 0, |
|
| 196 | - ) |
|
| 197 | - ), |
|
| 198 | - // add link for displaying hidden container |
|
| 199 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 200 | - apply_filters( |
|
| 201 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 202 | - EEH_HTML::link( |
|
| 203 | - '', |
|
| 204 | - __('click here to add a new state/province', 'event_espresso'), |
|
| 205 | - '', |
|
| 206 | - 'display-' . $input->html_id(), |
|
| 207 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 208 | - '', |
|
| 209 | - 'data-target="' . $input->html_id() . '"' |
|
| 210 | - ) |
|
| 211 | - ) |
|
| 212 | - ), |
|
| 213 | - // add initial html for hidden container |
|
| 214 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 215 | - apply_filters( |
|
| 216 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 217 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | - 'display: none;') . |
|
| 219 | - EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
| 220 | - 'event_espresso')) . |
|
| 221 | - EEH_HTML::ul() . |
|
| 222 | - EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
|
| 223 | - 'event_espresso')) . |
|
| 224 | - EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 225 | - EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
|
| 226 | - 'event_espresso')) . |
|
| 227 | - EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 228 | - EEH_HTML::ulx() |
|
| 229 | - ) |
|
| 230 | - ), |
|
| 231 | - // NEW STATE COUNTRY |
|
| 232 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 233 | - $country_options, |
|
| 234 | - array( |
|
| 235 | - 'html_name' => $country_name, |
|
| 236 | - 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
|
| 237 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 238 | - 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
|
| 239 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 240 | - 'required' => false, |
|
| 241 | - ) |
|
| 242 | - ), |
|
| 243 | - // NEW STATE NAME |
|
| 244 | - 'new_state_name' => new EE_Text_Input( |
|
| 245 | - array( |
|
| 246 | - 'html_name' => $state_name, |
|
| 247 | - 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
|
| 248 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 249 | - 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
|
| 250 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 251 | - 'required' => false, |
|
| 252 | - ) |
|
| 253 | - ), |
|
| 254 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 255 | - // NEW STATE NAME |
|
| 256 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 257 | - array( |
|
| 258 | - 'html_name' => $abbrv_name, |
|
| 259 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 260 | - $input->html_id()), |
|
| 261 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 262 | - 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
|
| 263 | - 'html_other_attributes' => 'size="24"', |
|
| 264 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 265 | - 'required' => false, |
|
| 266 | - ) |
|
| 267 | - ), |
|
| 268 | - // "submit" button |
|
| 269 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 270 | - apply_filters( |
|
| 271 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 272 | - EEH_HTML::nbsp(3) . |
|
| 273 | - EEH_HTML::link( |
|
| 274 | - '', |
|
| 275 | - __('ADD', 'event_espresso'), |
|
| 276 | - '', |
|
| 277 | - 'submit-' . $new_state_submit_id, |
|
| 278 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 279 | - '', |
|
| 280 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 281 | - ) |
|
| 282 | - ) |
|
| 283 | - ), |
|
| 284 | - // extra info |
|
| 285 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 286 | - apply_filters( |
|
| 287 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 288 | - EEH_HTML::br(2) |
|
| 289 | - . |
|
| 290 | - EEH_HTML::div('', '', 'small-text') |
|
| 291 | - . |
|
| 292 | - EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')) |
|
| 293 | - . |
|
| 294 | - EEH_HTML::br() |
|
| 295 | - . |
|
| 296 | - sprintf( |
|
| 297 | - __('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 298 | - 'event_espresso'), |
|
| 299 | - EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 300 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', |
|
| 301 | - 'ee-form-add-new-state-wiki-lnk') |
|
| 302 | - ) |
|
| 303 | - . |
|
| 304 | - EEH_HTML::divx() |
|
| 305 | - . |
|
| 306 | - EEH_HTML::br() |
|
| 307 | - . |
|
| 308 | - EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
|
| 309 | - 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | - 'data-target="' . $input->html_id() . '"') |
|
| 311 | - . |
|
| 312 | - EEH_HTML::divx() |
|
| 313 | - . |
|
| 314 | - EEH_HTML::br() |
|
| 315 | - ) |
|
| 316 | - ), |
|
| 317 | - ), |
|
| 318 | - ) |
|
| 319 | - ); |
|
| 320 | - $question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', |
|
| 321 | - false); |
|
| 322 | - } |
|
| 323 | - return $question_group_reg_form; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * set_new_state_input_width |
|
| 330 | - * |
|
| 331 | - * @return int|string |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public static function add_new_state() |
|
| 335 | - { |
|
| 336 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 337 | - if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 338 | - EE_Registry::instance()->load_model('State'); |
|
| 339 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 340 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 341 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 342 | - : false; |
|
| 343 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 344 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 345 | - : false; |
|
| 346 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 347 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 348 | - : false; |
|
| 349 | - if ($state_country && $state_name && $state_abbr) { |
|
| 350 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 351 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 352 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 353 | - 'STA_name' => ucwords($state_name), |
|
| 354 | - 'STA_active' => false, |
|
| 355 | - )); |
|
| 356 | - if ($new_state instanceof EE_State) { |
|
| 357 | - // clean house |
|
| 358 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 359 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 360 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 361 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 362 | - // get any existing new states |
|
| 363 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 364 | - 'nsmf_new_states' |
|
| 365 | - ); |
|
| 366 | - $new_states[$new_state->ID()] = $new_state; |
|
| 367 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 368 | - array('nsmf_new_states' => $new_states) |
|
| 369 | - ); |
|
| 370 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 371 | - echo wp_json_encode(array( |
|
| 372 | - 'success' => true, |
|
| 373 | - 'id' => $new_state->ID(), |
|
| 374 | - 'name' => $new_state->name(), |
|
| 375 | - 'abbrev' => $new_state->abbrev(), |
|
| 376 | - 'country_iso' => $new_state->country_iso(), |
|
| 377 | - 'country_name' => $new_state->country()->name(), |
|
| 378 | - )); |
|
| 379 | - exit(); |
|
| 380 | - } |
|
| 381 | - return $new_state->ID(); |
|
| 382 | - } |
|
| 383 | - } else { |
|
| 384 | - $error = __('A new State/Province could not be added because invalid or missing data was received.', |
|
| 385 | - 'event_espresso'); |
|
| 386 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 387 | - echo wp_json_encode(array('error' => $error)); |
|
| 388 | - exit(); |
|
| 389 | - } |
|
| 390 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * recursively drills down through request params to remove any that were added by this module |
|
| 400 | - * |
|
| 401 | - * @param array $request_params |
|
| 402 | - * @return array |
|
| 403 | - */ |
|
| 404 | - public static function filter_checkout_request_params($request_params) |
|
| 405 | - { |
|
| 406 | - foreach ($request_params as $form_section) { |
|
| 407 | - if (is_array($form_section)) { |
|
| 408 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 409 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $request_params; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @param array $request_params |
|
| 419 | - * @return array |
|
| 420 | - */ |
|
| 421 | - public static function unset_new_state_request_params($request_params) |
|
| 422 | - { |
|
| 423 | - unset( |
|
| 424 | - $request_params['new_state_micro_form'], |
|
| 425 | - $request_params['new_state_micro_add_new_state'], |
|
| 426 | - $request_params['new_state_micro_new_state_country'], |
|
| 427 | - $request_params['new_state_micro_new_state_name'], |
|
| 428 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 429 | - ); |
|
| 430 | - return $request_params; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * @param array $props_n_values |
|
| 437 | - * @return bool |
|
| 438 | - * @throws EE_Error |
|
| 439 | - */ |
|
| 440 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 441 | - { |
|
| 442 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 443 | - if (! empty($existing_state)) { |
|
| 444 | - return array_pop($existing_state); |
|
| 445 | - } |
|
| 446 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 447 | - if ($new_state instanceof EE_State) { |
|
| 448 | - // if not non-ajax admin |
|
| 449 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 450 | - $new_state_notice = sprintf( |
|
| 451 | - __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 452 | - 'event_espresso'), |
|
| 453 | - '<b>' . $new_state->name() . '</b>', |
|
| 454 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | - '<a href="' . add_query_arg(array( |
|
| 457 | - 'page' => 'espresso_general_settings', |
|
| 458 | - 'action' => 'country_settings', |
|
| 459 | - 'country' => $new_state->country_iso(), |
|
| 460 | - ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | - 'event_espresso') . '</a>', |
|
| 462 | - '<br />' |
|
| 463 | - ); |
|
| 464 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 465 | - $new_state->save(); |
|
| 466 | - EEM_State::instance()->reset_cached_states(); |
|
| 467 | - return $new_state; |
|
| 468 | - } |
|
| 469 | - return false; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * @param string $CNT_ISO |
|
| 476 | - * @param string $STA_ID |
|
| 477 | - * @param array $cols_n_values |
|
| 478 | - * @return void |
|
| 479 | - */ |
|
| 480 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 481 | - { |
|
| 482 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
| 483 | - if (! $CNT_ISO) { |
|
| 484 | - EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
|
| 485 | - __FUNCTION__, __LINE__); |
|
| 486 | - } |
|
| 487 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 488 | - : false; |
|
| 489 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 491 | - if ($state instanceof EE_State) { |
|
| 492 | - $STA_abbrev = $state->abbrev(); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - if (! $STA_abbrev) { |
|
| 496 | - EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 497 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | - } |
|
| 499 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * @param EE_State[] $state_options |
|
| 506 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 507 | - * @param EE_Registration $registration |
|
| 508 | - * @param EE_Question $question |
|
| 509 | - * @param $answer |
|
| 510 | - * @return array |
|
| 511 | - */ |
|
| 512 | - public static function inject_new_reg_state_into_options( |
|
| 513 | - $state_options = array(), |
|
| 514 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 515 | - EE_Registration $registration, |
|
| 516 | - EE_Question $question, |
|
| 517 | - $answer |
|
| 518 | - ) { |
|
| 519 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 520 | - && $question->type() |
|
| 521 | - === EEM_Question::QST_type_state |
|
| 522 | - ) { |
|
| 523 | - $STA_ID = $answer->value(); |
|
| 524 | - if (! empty($STA_ID)) { |
|
| 525 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 526 | - if ($state instanceof EE_State) { |
|
| 527 | - $country = $state->country(); |
|
| 528 | - if ($country instanceof EE_Country) { |
|
| 529 | - if (! isset($state_options[$country->name()])) { |
|
| 530 | - $state_options[$country->name()] = array(); |
|
| 531 | - } |
|
| 532 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - return $state_options; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * @param EE_Country[] $country_options |
|
| 546 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 547 | - * @param EE_Registration $registration |
|
| 548 | - * @param EE_Question $question |
|
| 549 | - * @param $answer |
|
| 550 | - * @return array |
|
| 551 | - */ |
|
| 552 | - public static function inject_new_reg_country_into_options( |
|
| 553 | - $country_options = array(), |
|
| 554 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 555 | - EE_Registration $registration, |
|
| 556 | - EE_Question $question, |
|
| 557 | - $answer |
|
| 558 | - ) { |
|
| 559 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 560 | - && $question->type() |
|
| 561 | - === EEM_Question::QST_type_country |
|
| 562 | - ) { |
|
| 563 | - $CNT_ISO = $answer->value(); |
|
| 564 | - if (! empty($CNT_ISO)) { |
|
| 565 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 566 | - if ($country instanceof EE_Country) { |
|
| 567 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 568 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - return $country_options; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @param EE_State[] $state_options |
|
| 580 | - * @return array |
|
| 581 | - * @throws EE_Error |
|
| 582 | - */ |
|
| 583 | - public static function state_options($state_options = array()) |
|
| 584 | - { |
|
| 585 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 586 | - foreach ($new_states as $new_state) { |
|
| 587 | - if ( |
|
| 588 | - $new_state instanceof EE_State |
|
| 589 | - && $new_state->country() instanceof EE_Country |
|
| 590 | - ) { |
|
| 591 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - return $state_options; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @return array |
|
| 601 | - */ |
|
| 602 | - protected static function _get_new_states() |
|
| 603 | - { |
|
| 604 | - $new_states = array(); |
|
| 605 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 606 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 607 | - 'nsmf_new_states' |
|
| 608 | - ); |
|
| 609 | - } |
|
| 610 | - return is_array($new_states) ? $new_states : array(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * @param EE_Country[] $country_options |
|
| 617 | - * @return array |
|
| 618 | - * @throws EE_Error |
|
| 619 | - */ |
|
| 620 | - public static function country_options($country_options = array()) |
|
| 621 | - { |
|
| 622 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 623 | - foreach ($new_states as $new_state) { |
|
| 624 | - if ( |
|
| 625 | - $new_state instanceof EE_State |
|
| 626 | - && $new_state->country() instanceof EE_Country |
|
| 627 | - ) { |
|
| 628 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - return $country_options; |
|
| 632 | - } |
|
| 19 | + /** |
|
| 20 | + * @return EED_Module|EED_Add_New_State |
|
| 21 | + */ |
|
| 22 | + public static function instance() |
|
| 23 | + { |
|
| 24 | + return parent::get_instance(__CLASS__); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 40 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 41 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 42 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 43 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 44 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 46 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 48 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 49 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 50 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 52 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public static function set_hooks_admin() |
|
| 63 | + { |
|
| 64 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 65 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 66 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 67 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 68 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 69 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 70 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 71 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 72 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 73 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 74 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 75 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 76 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 77 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 78 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 79 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 80 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 81 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 82 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 83 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 84 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 85 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 86 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public static function set_definitions() |
|
| 95 | + { |
|
| 96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | + define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param WP $WP |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + public function run($WP) |
|
| 107 | + { |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return void |
|
| 114 | + */ |
|
| 115 | + public static function translate_js_strings() |
|
| 116 | + { |
|
| 117 | + EE_Registry::$i18n_js_strings['ans_no_country'] = __('In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 118 | + 'event_espresso'); |
|
| 119 | + EE_Registry::$i18n_js_strings['ans_no_name'] = __('In order to proceed, you need to enter the name of your State/Province.', |
|
| 120 | + 'event_espresso'); |
|
| 121 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = __('In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 122 | + 'event_espresso'); |
|
| 123 | + EE_Registry::$i18n_js_strings['ans_save_success'] = __('The new state was successfully saved to the database.', |
|
| 124 | + 'event_espresso'); |
|
| 125 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = __('An unknown error has occurred on the server while saving the new state to the database.', |
|
| 126 | + 'event_espresso'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return void |
|
| 133 | + */ |
|
| 134 | + public static function wp_enqueue_scripts() |
|
| 135 | + { |
|
| 136 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 137 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 138 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 139 | + wp_enqueue_script('add_new_state'); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * display_add_new_state_micro_form |
|
| 147 | + * |
|
| 148 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 149 | + * @return string |
|
| 150 | + * @throws EE_Error |
|
| 151 | + */ |
|
| 152 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 153 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 154 | + { |
|
| 155 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 156 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 157 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 158 | + // is the "state" question in this form section? |
|
| 159 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 160 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 161 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 162 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 163 | + if ($input instanceof EE_State_Select_Input) { |
|
| 164 | + $input->html_name(); |
|
| 165 | + } |
|
| 166 | + return $question_group_reg_form; |
|
| 167 | + } |
|
| 168 | + // we're only doing this for state select inputs |
|
| 169 | + if ($input instanceof EE_State_Select_Input) { |
|
| 170 | + // grab any set values from the request |
|
| 171 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 172 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 173 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 174 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 175 | + $country_options = array(); |
|
| 176 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 177 | + if (! empty($countries)) { |
|
| 178 | + foreach ($countries as $country) { |
|
| 179 | + if ($country instanceof EE_Country) { |
|
| 180 | + $country_options[$country->ID()] = $country->name(); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 185 | + array( |
|
| 186 | + 'name' => 'new_state_micro_form', |
|
| 187 | + 'html_id' => 'new_state_micro_form', |
|
| 188 | + 'layout_strategy' => new EE_No_Layout(), |
|
| 189 | + 'subsections' => array( |
|
| 190 | + // add hidden input to indicate that a new state is being added |
|
| 191 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 192 | + array( |
|
| 193 | + 'html_name' => str_replace('state', 'nsmf_add_new_state', $input->html_name()), |
|
| 194 | + 'html_id' => str_replace('state', 'nsmf_add_new_state', $input->html_id()), |
|
| 195 | + 'default' => 0, |
|
| 196 | + ) |
|
| 197 | + ), |
|
| 198 | + // add link for displaying hidden container |
|
| 199 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 200 | + apply_filters( |
|
| 201 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 202 | + EEH_HTML::link( |
|
| 203 | + '', |
|
| 204 | + __('click here to add a new state/province', 'event_espresso'), |
|
| 205 | + '', |
|
| 206 | + 'display-' . $input->html_id(), |
|
| 207 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 208 | + '', |
|
| 209 | + 'data-target="' . $input->html_id() . '"' |
|
| 210 | + ) |
|
| 211 | + ) |
|
| 212 | + ), |
|
| 213 | + // add initial html for hidden container |
|
| 214 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 215 | + apply_filters( |
|
| 216 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 217 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | + 'display: none;') . |
|
| 219 | + EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
| 220 | + 'event_espresso')) . |
|
| 221 | + EEH_HTML::ul() . |
|
| 222 | + EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
|
| 223 | + 'event_espresso')) . |
|
| 224 | + EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 225 | + EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
|
| 226 | + 'event_espresso')) . |
|
| 227 | + EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 228 | + EEH_HTML::ulx() |
|
| 229 | + ) |
|
| 230 | + ), |
|
| 231 | + // NEW STATE COUNTRY |
|
| 232 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 233 | + $country_options, |
|
| 234 | + array( |
|
| 235 | + 'html_name' => $country_name, |
|
| 236 | + 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
|
| 237 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 238 | + 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
|
| 239 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 240 | + 'required' => false, |
|
| 241 | + ) |
|
| 242 | + ), |
|
| 243 | + // NEW STATE NAME |
|
| 244 | + 'new_state_name' => new EE_Text_Input( |
|
| 245 | + array( |
|
| 246 | + 'html_name' => $state_name, |
|
| 247 | + 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
|
| 248 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 249 | + 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
|
| 250 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 251 | + 'required' => false, |
|
| 252 | + ) |
|
| 253 | + ), |
|
| 254 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 255 | + // NEW STATE NAME |
|
| 256 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 257 | + array( |
|
| 258 | + 'html_name' => $abbrv_name, |
|
| 259 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 260 | + $input->html_id()), |
|
| 261 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 262 | + 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
|
| 263 | + 'html_other_attributes' => 'size="24"', |
|
| 264 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 265 | + 'required' => false, |
|
| 266 | + ) |
|
| 267 | + ), |
|
| 268 | + // "submit" button |
|
| 269 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 270 | + apply_filters( |
|
| 271 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 272 | + EEH_HTML::nbsp(3) . |
|
| 273 | + EEH_HTML::link( |
|
| 274 | + '', |
|
| 275 | + __('ADD', 'event_espresso'), |
|
| 276 | + '', |
|
| 277 | + 'submit-' . $new_state_submit_id, |
|
| 278 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 279 | + '', |
|
| 280 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 281 | + ) |
|
| 282 | + ) |
|
| 283 | + ), |
|
| 284 | + // extra info |
|
| 285 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 286 | + apply_filters( |
|
| 287 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 288 | + EEH_HTML::br(2) |
|
| 289 | + . |
|
| 290 | + EEH_HTML::div('', '', 'small-text') |
|
| 291 | + . |
|
| 292 | + EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')) |
|
| 293 | + . |
|
| 294 | + EEH_HTML::br() |
|
| 295 | + . |
|
| 296 | + sprintf( |
|
| 297 | + __('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 298 | + 'event_espresso'), |
|
| 299 | + EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 300 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', |
|
| 301 | + 'ee-form-add-new-state-wiki-lnk') |
|
| 302 | + ) |
|
| 303 | + . |
|
| 304 | + EEH_HTML::divx() |
|
| 305 | + . |
|
| 306 | + EEH_HTML::br() |
|
| 307 | + . |
|
| 308 | + EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
|
| 309 | + 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | + 'data-target="' . $input->html_id() . '"') |
|
| 311 | + . |
|
| 312 | + EEH_HTML::divx() |
|
| 313 | + . |
|
| 314 | + EEH_HTML::br() |
|
| 315 | + ) |
|
| 316 | + ), |
|
| 317 | + ), |
|
| 318 | + ) |
|
| 319 | + ); |
|
| 320 | + $question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', |
|
| 321 | + false); |
|
| 322 | + } |
|
| 323 | + return $question_group_reg_form; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * set_new_state_input_width |
|
| 330 | + * |
|
| 331 | + * @return int|string |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public static function add_new_state() |
|
| 335 | + { |
|
| 336 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 337 | + if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 338 | + EE_Registry::instance()->load_model('State'); |
|
| 339 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 340 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 341 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 342 | + : false; |
|
| 343 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 344 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 345 | + : false; |
|
| 346 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 347 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 348 | + : false; |
|
| 349 | + if ($state_country && $state_name && $state_abbr) { |
|
| 350 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 351 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 352 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 353 | + 'STA_name' => ucwords($state_name), |
|
| 354 | + 'STA_active' => false, |
|
| 355 | + )); |
|
| 356 | + if ($new_state instanceof EE_State) { |
|
| 357 | + // clean house |
|
| 358 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 359 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 360 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 361 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 362 | + // get any existing new states |
|
| 363 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 364 | + 'nsmf_new_states' |
|
| 365 | + ); |
|
| 366 | + $new_states[$new_state->ID()] = $new_state; |
|
| 367 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 368 | + array('nsmf_new_states' => $new_states) |
|
| 369 | + ); |
|
| 370 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 371 | + echo wp_json_encode(array( |
|
| 372 | + 'success' => true, |
|
| 373 | + 'id' => $new_state->ID(), |
|
| 374 | + 'name' => $new_state->name(), |
|
| 375 | + 'abbrev' => $new_state->abbrev(), |
|
| 376 | + 'country_iso' => $new_state->country_iso(), |
|
| 377 | + 'country_name' => $new_state->country()->name(), |
|
| 378 | + )); |
|
| 379 | + exit(); |
|
| 380 | + } |
|
| 381 | + return $new_state->ID(); |
|
| 382 | + } |
|
| 383 | + } else { |
|
| 384 | + $error = __('A new State/Province could not be added because invalid or missing data was received.', |
|
| 385 | + 'event_espresso'); |
|
| 386 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 387 | + echo wp_json_encode(array('error' => $error)); |
|
| 388 | + exit(); |
|
| 389 | + } |
|
| 390 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * recursively drills down through request params to remove any that were added by this module |
|
| 400 | + * |
|
| 401 | + * @param array $request_params |
|
| 402 | + * @return array |
|
| 403 | + */ |
|
| 404 | + public static function filter_checkout_request_params($request_params) |
|
| 405 | + { |
|
| 406 | + foreach ($request_params as $form_section) { |
|
| 407 | + if (is_array($form_section)) { |
|
| 408 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 409 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $request_params; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @param array $request_params |
|
| 419 | + * @return array |
|
| 420 | + */ |
|
| 421 | + public static function unset_new_state_request_params($request_params) |
|
| 422 | + { |
|
| 423 | + unset( |
|
| 424 | + $request_params['new_state_micro_form'], |
|
| 425 | + $request_params['new_state_micro_add_new_state'], |
|
| 426 | + $request_params['new_state_micro_new_state_country'], |
|
| 427 | + $request_params['new_state_micro_new_state_name'], |
|
| 428 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 429 | + ); |
|
| 430 | + return $request_params; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param array $props_n_values |
|
| 437 | + * @return bool |
|
| 438 | + * @throws EE_Error |
|
| 439 | + */ |
|
| 440 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 441 | + { |
|
| 442 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 443 | + if (! empty($existing_state)) { |
|
| 444 | + return array_pop($existing_state); |
|
| 445 | + } |
|
| 446 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 447 | + if ($new_state instanceof EE_State) { |
|
| 448 | + // if not non-ajax admin |
|
| 449 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 450 | + $new_state_notice = sprintf( |
|
| 451 | + __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 452 | + 'event_espresso'), |
|
| 453 | + '<b>' . $new_state->name() . '</b>', |
|
| 454 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | + '<a href="' . add_query_arg(array( |
|
| 457 | + 'page' => 'espresso_general_settings', |
|
| 458 | + 'action' => 'country_settings', |
|
| 459 | + 'country' => $new_state->country_iso(), |
|
| 460 | + ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | + 'event_espresso') . '</a>', |
|
| 462 | + '<br />' |
|
| 463 | + ); |
|
| 464 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
| 465 | + $new_state->save(); |
|
| 466 | + EEM_State::instance()->reset_cached_states(); |
|
| 467 | + return $new_state; |
|
| 468 | + } |
|
| 469 | + return false; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @param string $CNT_ISO |
|
| 476 | + * @param string $STA_ID |
|
| 477 | + * @param array $cols_n_values |
|
| 478 | + * @return void |
|
| 479 | + */ |
|
| 480 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 481 | + { |
|
| 482 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
| 483 | + if (! $CNT_ISO) { |
|
| 484 | + EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
|
| 485 | + __FUNCTION__, __LINE__); |
|
| 486 | + } |
|
| 487 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 488 | + : false; |
|
| 489 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 491 | + if ($state instanceof EE_State) { |
|
| 492 | + $STA_abbrev = $state->abbrev(); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + if (! $STA_abbrev) { |
|
| 496 | + EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 497 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | + } |
|
| 499 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * @param EE_State[] $state_options |
|
| 506 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 507 | + * @param EE_Registration $registration |
|
| 508 | + * @param EE_Question $question |
|
| 509 | + * @param $answer |
|
| 510 | + * @return array |
|
| 511 | + */ |
|
| 512 | + public static function inject_new_reg_state_into_options( |
|
| 513 | + $state_options = array(), |
|
| 514 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 515 | + EE_Registration $registration, |
|
| 516 | + EE_Question $question, |
|
| 517 | + $answer |
|
| 518 | + ) { |
|
| 519 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 520 | + && $question->type() |
|
| 521 | + === EEM_Question::QST_type_state |
|
| 522 | + ) { |
|
| 523 | + $STA_ID = $answer->value(); |
|
| 524 | + if (! empty($STA_ID)) { |
|
| 525 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 526 | + if ($state instanceof EE_State) { |
|
| 527 | + $country = $state->country(); |
|
| 528 | + if ($country instanceof EE_Country) { |
|
| 529 | + if (! isset($state_options[$country->name()])) { |
|
| 530 | + $state_options[$country->name()] = array(); |
|
| 531 | + } |
|
| 532 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + return $state_options; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * @param EE_Country[] $country_options |
|
| 546 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 547 | + * @param EE_Registration $registration |
|
| 548 | + * @param EE_Question $question |
|
| 549 | + * @param $answer |
|
| 550 | + * @return array |
|
| 551 | + */ |
|
| 552 | + public static function inject_new_reg_country_into_options( |
|
| 553 | + $country_options = array(), |
|
| 554 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 555 | + EE_Registration $registration, |
|
| 556 | + EE_Question $question, |
|
| 557 | + $answer |
|
| 558 | + ) { |
|
| 559 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 560 | + && $question->type() |
|
| 561 | + === EEM_Question::QST_type_country |
|
| 562 | + ) { |
|
| 563 | + $CNT_ISO = $answer->value(); |
|
| 564 | + if (! empty($CNT_ISO)) { |
|
| 565 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 566 | + if ($country instanceof EE_Country) { |
|
| 567 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 568 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + return $country_options; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @param EE_State[] $state_options |
|
| 580 | + * @return array |
|
| 581 | + * @throws EE_Error |
|
| 582 | + */ |
|
| 583 | + public static function state_options($state_options = array()) |
|
| 584 | + { |
|
| 585 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 586 | + foreach ($new_states as $new_state) { |
|
| 587 | + if ( |
|
| 588 | + $new_state instanceof EE_State |
|
| 589 | + && $new_state->country() instanceof EE_Country |
|
| 590 | + ) { |
|
| 591 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + return $state_options; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @return array |
|
| 601 | + */ |
|
| 602 | + protected static function _get_new_states() |
|
| 603 | + { |
|
| 604 | + $new_states = array(); |
|
| 605 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 606 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 607 | + 'nsmf_new_states' |
|
| 608 | + ); |
|
| 609 | + } |
|
| 610 | + return is_array($new_states) ? $new_states : array(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * @param EE_Country[] $country_options |
|
| 617 | + * @return array |
|
| 618 | + * @throws EE_Error |
|
| 619 | + */ |
|
| 620 | + public static function country_options($country_options = array()) |
|
| 621 | + { |
|
| 622 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 623 | + foreach ($new_states as $new_state) { |
|
| 624 | + if ( |
|
| 625 | + $new_state instanceof EE_State |
|
| 626 | + && $new_state->country() instanceof EE_Country |
|
| 627 | + ) { |
|
| 628 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + return $country_options; |
|
| 632 | + } |
|
| 633 | 633 | |
| 634 | 634 | |
| 635 | 635 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public static function set_definitions() |
| 95 | 95 | { |
| 96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 97 | - define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 97 | + define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public static function wp_enqueue_scripts() |
| 135 | 135 | { |
| 136 | 136 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 137 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 137 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
| 138 | 138 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
| 139 | 139 | wp_enqueue_script('add_new_state'); |
| 140 | 140 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 175 | 175 | $country_options = array(); |
| 176 | 176 | $countries = EEM_Country::instance()->get_all_countries(); |
| 177 | - if (! empty($countries)) { |
|
| 177 | + if ( ! empty($countries)) { |
|
| 178 | 178 | foreach ($countries as $country) { |
| 179 | 179 | if ($country instanceof EE_Country) { |
| 180 | 180 | $country_options[$country->ID()] = $country->name(); |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | '', |
| 204 | 204 | __('click here to add a new state/province', 'event_espresso'), |
| 205 | 205 | '', |
| 206 | - 'display-' . $input->html_id(), |
|
| 206 | + 'display-'.$input->html_id(), |
|
| 207 | 207 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 208 | 208 | '', |
| 209 | - 'data-target="' . $input->html_id() . '"' |
|
| 209 | + 'data-target="'.$input->html_id().'"' |
|
| 210 | 210 | ) |
| 211 | 211 | ) |
| 212 | 212 | ), |
@@ -214,17 +214,17 @@ discard block |
||
| 214 | 214 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
| 215 | 215 | apply_filters( |
| 216 | 216 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 217 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 218 | - 'display: none;') . |
|
| 217 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
| 218 | + 'display: none;'). |
|
| 219 | 219 | EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
| 220 | - 'event_espresso')) . |
|
| 221 | - EEH_HTML::ul() . |
|
| 220 | + 'event_espresso')). |
|
| 221 | + EEH_HTML::ul(). |
|
| 222 | 222 | EEH_HTML::li(__('first select the Country that your State/Province belongs to', |
| 223 | - 'event_espresso')) . |
|
| 224 | - EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')) . |
|
| 223 | + 'event_espresso')). |
|
| 224 | + EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')). |
|
| 225 | 225 | EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', |
| 226 | - 'event_espresso')) . |
|
| 227 | - EEH_HTML::li(__('click the ADD button', 'event_espresso')) . |
|
| 226 | + 'event_espresso')). |
|
| 227 | + EEH_HTML::li(__('click the ADD button', 'event_espresso')). |
|
| 228 | 228 | EEH_HTML::ulx() |
| 229 | 229 | ) |
| 230 | 230 | ), |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | array( |
| 235 | 235 | 'html_name' => $country_name, |
| 236 | 236 | 'html_id' => str_replace('state', 'nsmf_new_state_country', $input->html_id()), |
| 237 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 237 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 238 | 238 | 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
| 239 | 239 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
| 240 | 240 | 'required' => false, |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | array( |
| 246 | 246 | 'html_name' => $state_name, |
| 247 | 247 | 'html_id' => str_replace('state', 'nsmf_new_state_name', $input->html_id()), |
| 248 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 248 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 249 | 249 | 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
| 250 | 250 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
| 251 | 251 | 'required' => false, |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | 'html_name' => $abbrv_name, |
| 259 | 259 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
| 260 | 260 | $input->html_id()), |
| 261 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 261 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 262 | 262 | 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
| 263 | 263 | 'html_other_attributes' => 'size="24"', |
| 264 | 264 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
@@ -269,15 +269,15 @@ discard block |
||
| 269 | 269 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
| 270 | 270 | apply_filters( |
| 271 | 271 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
| 272 | - EEH_HTML::nbsp(3) . |
|
| 272 | + EEH_HTML::nbsp(3). |
|
| 273 | 273 | EEH_HTML::link( |
| 274 | 274 | '', |
| 275 | 275 | __('ADD', 'event_espresso'), |
| 276 | 276 | '', |
| 277 | - 'submit-' . $new_state_submit_id, |
|
| 277 | + 'submit-'.$new_state_submit_id, |
|
| 278 | 278 | 'ee-form-add-new-state-submit button button-secondary', |
| 279 | 279 | '', |
| 280 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 280 | + 'data-target="'.$new_state_submit_id.'"' |
|
| 281 | 281 | ) |
| 282 | 282 | ) |
| 283 | 283 | ), |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | EEH_HTML::br() |
| 307 | 307 | . |
| 308 | 308 | EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', |
| 309 | - 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | - 'data-target="' . $input->html_id() . '"') |
|
| 309 | + 'hide-'.$input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', |
|
| 310 | + 'data-target="'.$input->html_id().'"') |
|
| 311 | 311 | . |
| 312 | 312 | EEH_HTML::divx() |
| 313 | 313 | . |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | public static function add_new_state() |
| 335 | 335 | { |
| 336 | 336 | $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
| 337 | - if ( absint($REQ->get('nsmf_add_new_state')) === 1 ) { |
|
| 337 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 338 | 338 | EE_Registry::instance()->load_model('State'); |
| 339 | 339 | // grab country ISO code, new state name, and new state abbreviation |
| 340 | 340 | $state_country = $REQ->is_set('nsmf_new_state_country') |
@@ -440,25 +440,25 @@ discard block |
||
| 440 | 440 | public static function save_new_state_to_db($props_n_values = array()) |
| 441 | 441 | { |
| 442 | 442 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
| 443 | - if (! empty($existing_state)) { |
|
| 443 | + if ( ! empty($existing_state)) { |
|
| 444 | 444 | return array_pop($existing_state); |
| 445 | 445 | } |
| 446 | 446 | $new_state = EE_State::new_instance($props_n_values); |
| 447 | 447 | if ($new_state instanceof EE_State) { |
| 448 | 448 | // if not non-ajax admin |
| 449 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
| 449 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
| 450 | 450 | $new_state_notice = sprintf( |
| 451 | 451 | __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 452 | 452 | 'event_espresso'), |
| 453 | - '<b>' . $new_state->name() . '</b>', |
|
| 454 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 455 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 456 | - '<a href="' . add_query_arg(array( |
|
| 453 | + '<b>'.$new_state->name().'</b>', |
|
| 454 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 455 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 456 | + '<a href="'.add_query_arg(array( |
|
| 457 | 457 | 'page' => 'espresso_general_settings', |
| 458 | 458 | 'action' => 'country_settings', |
| 459 | 459 | 'country' => $new_state->country_iso(), |
| 460 | - ), admin_url('admin.php')) . '">' . __('Event Espresso - General Settings > Countries Tab', |
|
| 461 | - 'event_espresso') . '</a>', |
|
| 460 | + ), admin_url('admin.php')).'">'.__('Event Espresso - General Settings > Countries Tab', |
|
| 461 | + 'event_espresso').'</a>', |
|
| 462 | 462 | '<br />' |
| 463 | 463 | ); |
| 464 | 464 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -480,23 +480,23 @@ discard block |
||
| 480 | 480 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
| 481 | 481 | { |
| 482 | 482 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
| 483 | - if (! $CNT_ISO) { |
|
| 483 | + if ( ! $CNT_ISO) { |
|
| 484 | 484 | EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, |
| 485 | 485 | __FUNCTION__, __LINE__); |
| 486 | 486 | } |
| 487 | 487 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 488 | 488 | : false; |
| 489 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 489 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 490 | 490 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 491 | 491 | if ($state instanceof EE_State) { |
| 492 | 492 | $STA_abbrev = $state->abbrev(); |
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | - if (! $STA_abbrev) { |
|
| 495 | + if ( ! $STA_abbrev) { |
|
| 496 | 496 | EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 497 | 497 | __FILE__, __FUNCTION__, __LINE__); |
| 498 | 498 | } |
| 499 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 499 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -521,15 +521,15 @@ discard block |
||
| 521 | 521 | === EEM_Question::QST_type_state |
| 522 | 522 | ) { |
| 523 | 523 | $STA_ID = $answer->value(); |
| 524 | - if (! empty($STA_ID)) { |
|
| 524 | + if ( ! empty($STA_ID)) { |
|
| 525 | 525 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 526 | 526 | if ($state instanceof EE_State) { |
| 527 | 527 | $country = $state->country(); |
| 528 | 528 | if ($country instanceof EE_Country) { |
| 529 | - if (! isset($state_options[$country->name()])) { |
|
| 529 | + if ( ! isset($state_options[$country->name()])) { |
|
| 530 | 530 | $state_options[$country->name()] = array(); |
| 531 | 531 | } |
| 532 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 532 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 533 | 533 | $state_options[$country->name()][$STA_ID] = $state->name(); |
| 534 | 534 | } |
| 535 | 535 | } |
@@ -561,10 +561,10 @@ discard block |
||
| 561 | 561 | === EEM_Question::QST_type_country |
| 562 | 562 | ) { |
| 563 | 563 | $CNT_ISO = $answer->value(); |
| 564 | - if (! empty($CNT_ISO)) { |
|
| 564 | + if ( ! empty($CNT_ISO)) { |
|
| 565 | 565 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 566 | 566 | if ($country instanceof EE_Country) { |
| 567 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 567 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 568 | 568 | $country_options[$CNT_ISO] = $country->name(); |
| 569 | 569 | } |
| 570 | 570 | } |