@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.5.0 |
8 | 8 | */ |
9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -21,166 +21,166 @@ discard block |
||
21 | 21 | class EE_Register_Capabilities implements EEI_Plugin_API |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Holds the settings for a specific registration. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected static $_registry = array(); |
|
24 | + /** |
|
25 | + * Holds the settings for a specific registration. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected static $_registry = array(); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Used to register capability items with EE core. |
|
34 | - * |
|
35 | - * @since 4.5.0 |
|
36 | - * @param string $cap_reference usually will be a class name |
|
37 | - * that references capability |
|
38 | - * related items setup for |
|
39 | - * something. |
|
40 | - * @param array $setup_args { |
|
41 | - * An array of items related to |
|
42 | - * registering capabilities. |
|
43 | - * @type array $capabilities An array mapping capability |
|
44 | - * strings to core WP Role. Something like: array( |
|
45 | - * 'administrator' => array( |
|
46 | - * 'read_cap', 'edit_cap', |
|
47 | - * 'delete_cap'), |
|
48 | - * 'author' => |
|
49 | - * array( 'read_cap' ) |
|
50 | - * ). |
|
51 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
52 | - * @see EE_Capabilities.php for php docs on these objects. |
|
53 | - * Should be indexed by the |
|
54 | - * classname for the capability |
|
55 | - * map and values representing |
|
56 | - * the arguments for the map. |
|
57 | - * } |
|
58 | - * @throws EE_Error |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public static function register($cap_reference = null, $setup_args = array()) |
|
62 | - { |
|
63 | - //required fields MUST be present, so let's make sure they are. |
|
64 | - if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | - throw new EE_Error( |
|
66 | - __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
67 | - 'event_espresso') |
|
68 | - ); |
|
69 | - } |
|
70 | - //make sure we don't register twice |
|
71 | - if (isset(self::$_registry[$cap_reference])) { |
|
72 | - return; |
|
73 | - } |
|
74 | - //make sure this is not registered too late or too early. |
|
75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | - EE_Error::doing_it_wrong(__METHOD__, |
|
77 | - sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
78 | - 'event_espresso'), $cap_reference), '4.5.0'); |
|
79 | - } |
|
80 | - //some preliminary sanitization and setting to the $_registry property |
|
81 | - self::$_registry[$cap_reference] = array( |
|
82 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(), |
|
83 | - 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(), |
|
84 | - ); |
|
85 | - //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
86 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', |
|
87 | - array('EE_Register_Capabilities', 'register_capabilities'), 10); |
|
88 | - //add filter for cap maps |
|
89 | - add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
90 | - array('EE_Register_Capabilities', 'register_cap_maps'), 10); |
|
91 | - //init_role_caps to register new capabilities |
|
92 | - if (is_admin()) { |
|
93 | - EE_Registry::instance()->load_core('Capabilities'); |
|
94 | - EE_Capabilities::instance()->init_caps(); |
|
95 | - } |
|
96 | - } |
|
32 | + /** |
|
33 | + * Used to register capability items with EE core. |
|
34 | + * |
|
35 | + * @since 4.5.0 |
|
36 | + * @param string $cap_reference usually will be a class name |
|
37 | + * that references capability |
|
38 | + * related items setup for |
|
39 | + * something. |
|
40 | + * @param array $setup_args { |
|
41 | + * An array of items related to |
|
42 | + * registering capabilities. |
|
43 | + * @type array $capabilities An array mapping capability |
|
44 | + * strings to core WP Role. Something like: array( |
|
45 | + * 'administrator' => array( |
|
46 | + * 'read_cap', 'edit_cap', |
|
47 | + * 'delete_cap'), |
|
48 | + * 'author' => |
|
49 | + * array( 'read_cap' ) |
|
50 | + * ). |
|
51 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
52 | + * @see EE_Capabilities.php for php docs on these objects. |
|
53 | + * Should be indexed by the |
|
54 | + * classname for the capability |
|
55 | + * map and values representing |
|
56 | + * the arguments for the map. |
|
57 | + * } |
|
58 | + * @throws EE_Error |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public static function register($cap_reference = null, $setup_args = array()) |
|
62 | + { |
|
63 | + //required fields MUST be present, so let's make sure they are. |
|
64 | + if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | + throw new EE_Error( |
|
66 | + __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
67 | + 'event_espresso') |
|
68 | + ); |
|
69 | + } |
|
70 | + //make sure we don't register twice |
|
71 | + if (isset(self::$_registry[$cap_reference])) { |
|
72 | + return; |
|
73 | + } |
|
74 | + //make sure this is not registered too late or too early. |
|
75 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | + EE_Error::doing_it_wrong(__METHOD__, |
|
77 | + sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
78 | + 'event_espresso'), $cap_reference), '4.5.0'); |
|
79 | + } |
|
80 | + //some preliminary sanitization and setting to the $_registry property |
|
81 | + self::$_registry[$cap_reference] = array( |
|
82 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(), |
|
83 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array(), |
|
84 | + ); |
|
85 | + //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
86 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', |
|
87 | + array('EE_Register_Capabilities', 'register_capabilities'), 10); |
|
88 | + //add filter for cap maps |
|
89 | + add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
90 | + array('EE_Register_Capabilities', 'register_cap_maps'), 10); |
|
91 | + //init_role_caps to register new capabilities |
|
92 | + if (is_admin()) { |
|
93 | + EE_Registry::instance()->load_core('Capabilities'); |
|
94 | + EE_Capabilities::instance()->init_caps(); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
101 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
102 | - * registration ensures that new capabilities are added to existing roles. |
|
103 | - * |
|
104 | - * @param array $incoming_caps The original caps map. |
|
105 | - * @return array merged in new caps. |
|
106 | - */ |
|
107 | - public static function register_capabilities($incoming_caps) |
|
108 | - { |
|
109 | - foreach (self::$_registry as $ref => $caps_and_cap_map) { |
|
110 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
111 | - } |
|
112 | - return $incoming_caps; |
|
113 | - } |
|
99 | + /** |
|
100 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
101 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
102 | + * registration ensures that new capabilities are added to existing roles. |
|
103 | + * |
|
104 | + * @param array $incoming_caps The original caps map. |
|
105 | + * @return array merged in new caps. |
|
106 | + */ |
|
107 | + public static function register_capabilities($incoming_caps) |
|
108 | + { |
|
109 | + foreach (self::$_registry as $ref => $caps_and_cap_map) { |
|
110 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
111 | + } |
|
112 | + return $incoming_caps; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
118 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
119 | - * |
|
120 | - * @since 4.5.0 |
|
121 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
122 | - * @return EE_Meta_Capability_Map[] |
|
123 | - * @throws EE_Error |
|
124 | - */ |
|
125 | - public static function register_cap_maps($cap_maps) |
|
126 | - { |
|
127 | - //loop through and instantiate cap maps. |
|
128 | - foreach (self::$_registry as $cap_reference => $setup) { |
|
129 | - if (! isset($setup['cap_maps'])) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
116 | + /** |
|
117 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
118 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
119 | + * |
|
120 | + * @since 4.5.0 |
|
121 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
122 | + * @return EE_Meta_Capability_Map[] |
|
123 | + * @throws EE_Error |
|
124 | + */ |
|
125 | + public static function register_cap_maps($cap_maps) |
|
126 | + { |
|
127 | + //loop through and instantiate cap maps. |
|
128 | + foreach (self::$_registry as $cap_reference => $setup) { |
|
129 | + if (! isset($setup['cap_maps'])) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
133 | 133 | |
134 | - /** |
|
135 | - * account for cases where capability maps may be indexed |
|
136 | - * numerically to allow for the same map class to be utilized |
|
137 | - * In those cases, maps will be setup in an array like: |
|
138 | - * array( |
|
139 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
140 | - * 'ee_edit_cap', array( 'Object_Name', |
|
141 | - * 'ee_edit_published_cap', |
|
142 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
143 | - * ) ) |
|
144 | - * 1 => ... |
|
145 | - * ) |
|
146 | - * instead of: |
|
147 | - * array( |
|
148 | - * 'EE_Meta_Capability' => array( |
|
149 | - * 'ee_edit_cap', array( 'Object_Name', |
|
150 | - * 'ee_edit_published_cap', |
|
151 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | - * ), |
|
153 | - * ... |
|
154 | - * ) |
|
155 | - */ |
|
156 | - if (is_numeric($cap_class)) { |
|
157 | - $cap_class = key($args); |
|
158 | - $args = $args[$cap_class]; |
|
159 | - } |
|
134 | + /** |
|
135 | + * account for cases where capability maps may be indexed |
|
136 | + * numerically to allow for the same map class to be utilized |
|
137 | + * In those cases, maps will be setup in an array like: |
|
138 | + * array( |
|
139 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
140 | + * 'ee_edit_cap', array( 'Object_Name', |
|
141 | + * 'ee_edit_published_cap', |
|
142 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
143 | + * ) ) |
|
144 | + * 1 => ... |
|
145 | + * ) |
|
146 | + * instead of: |
|
147 | + * array( |
|
148 | + * 'EE_Meta_Capability' => array( |
|
149 | + * 'ee_edit_cap', array( 'Object_Name', |
|
150 | + * 'ee_edit_published_cap', |
|
151 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
152 | + * ), |
|
153 | + * ... |
|
154 | + * ) |
|
155 | + */ |
|
156 | + if (is_numeric($cap_class)) { |
|
157 | + $cap_class = key($args); |
|
158 | + $args = $args[$cap_class]; |
|
159 | + } |
|
160 | 160 | |
161 | - if (! class_exists($cap_class)) { |
|
162 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
163 | - 'event_espresso'), $cap_reference)); |
|
164 | - } |
|
161 | + if (! class_exists($cap_class)) { |
|
162 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
163 | + 'event_espresso'), $cap_reference)); |
|
164 | + } |
|
165 | 165 | |
166 | - if (count($args) !== 2) { |
|
167 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
168 | - 'event_espresso'), $cap_reference)); |
|
169 | - } |
|
170 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
171 | - } |
|
172 | - } |
|
173 | - return $cap_maps; |
|
174 | - } |
|
166 | + if (count($args) !== 2) { |
|
167 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
168 | + 'event_espresso'), $cap_reference)); |
|
169 | + } |
|
170 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
171 | + } |
|
172 | + } |
|
173 | + return $cap_maps; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - public static function deregister($cap_reference = null) |
|
178 | - { |
|
179 | - if (! empty(self::$_registry[$cap_reference])) { |
|
180 | - unset(self::$_registry[$cap_reference]); |
|
181 | - } |
|
177 | + public static function deregister($cap_reference = null) |
|
178 | + { |
|
179 | + if (! empty(self::$_registry[$cap_reference])) { |
|
180 | + unset(self::$_registry[$cap_reference]); |
|
181 | + } |
|
182 | 182 | |
183 | - //re init caps to grab the changes due to removed caps. |
|
184 | - EE_Capabilities::instance()->init_caps(); |
|
185 | - } |
|
183 | + //re init caps to grab the changes due to removed caps. |
|
184 | + EE_Capabilities::instance()->init_caps(); |
|
185 | + } |
|
186 | 186 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @subpackage plugin api, capabilities |
7 | 7 | * @since 4.5.0 |
8 | 8 | */ |
9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | 10 | exit('No direct script access allowed'); |
11 | 11 | } |
12 | 12 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public static function register($cap_reference = null, $setup_args = array()) |
62 | 62 | { |
63 | 63 | //required fields MUST be present, so let's make sure they are. |
64 | - if (! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
64 | + if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
65 | 65 | throw new EE_Error( |
66 | 66 | __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
67 | 67 | 'event_espresso') |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return; |
73 | 73 | } |
74 | 74 | //make sure this is not registered too late or too early. |
75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
75 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
76 | 76 | EE_Error::doing_it_wrong(__METHOD__, |
77 | 77 | sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
78 | 78 | 'event_espresso'), $cap_reference), '4.5.0'); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | //loop through and instantiate cap maps. |
128 | 128 | foreach (self::$_registry as $cap_reference => $setup) { |
129 | - if (! isset($setup['cap_maps'])) { |
|
129 | + if ( ! isset($setup['cap_maps'])) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $args = $args[$cap_class]; |
159 | 159 | } |
160 | 160 | |
161 | - if (! class_exists($cap_class)) { |
|
161 | + if ( ! class_exists($cap_class)) { |
|
162 | 162 | throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
163 | 163 | 'event_espresso'), $cap_reference)); |
164 | 164 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | public static function deregister($cap_reference = null) |
178 | 178 | { |
179 | - if (! empty(self::$_registry[$cap_reference])) { |
|
179 | + if ( ! empty(self::$_registry[$cap_reference])) { |
|
180 | 180 | unset(self::$_registry[$cap_reference]); |
181 | 181 | } |
182 | 182 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use WP_Post; |
17 | 17 | |
18 | 18 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
19 | - exit( 'No direct script access allowed' ); |
|
19 | + exit( 'No direct script access allowed' ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | |
@@ -33,679 +33,679 @@ discard block |
||
33 | 33 | class DisplayTicketSelector |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * event that ticket selector is being generated for |
|
38 | - * |
|
39 | - * @access protected |
|
40 | - * @var EE_Event $event |
|
41 | - */ |
|
42 | - protected $event; |
|
43 | - |
|
44 | - /** |
|
45 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
46 | - * |
|
47 | - * @var bool $iframe |
|
48 | - */ |
|
49 | - protected $iframe = false; |
|
50 | - |
|
51 | - /** |
|
52 | - * max attendees that can register for event at one time |
|
53 | - * |
|
54 | - * @var int $max_attendees |
|
55 | - */ |
|
56 | - private $max_attendees = EE_INF; |
|
57 | - |
|
58 | - /** |
|
59 | - *@var string $date_format |
|
60 | - */ |
|
61 | - private $date_format; |
|
62 | - |
|
63 | - /** |
|
64 | - *@var string $time_format |
|
65 | - */ |
|
66 | - private $time_format; |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * DisplayTicketSelector constructor. |
|
72 | - */ |
|
73 | - public function __construct() |
|
74 | - { |
|
75 | - $this->date_format = apply_filters( |
|
76 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
77 | - get_option('date_format') |
|
78 | - ); |
|
79 | - $this->time_format = apply_filters( |
|
80 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
81 | - get_option('time_format') |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param boolean $iframe |
|
89 | - */ |
|
90 | - public function setIframe( $iframe = true ) |
|
91 | - { |
|
92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * finds and sets the \EE_Event object for use throughout class |
|
98 | - * |
|
99 | - * @param mixed $event |
|
100 | - * @return bool |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - protected function setEvent( $event = null ) |
|
104 | - { |
|
105 | - if ( $event === null ) { |
|
106 | - global $post; |
|
107 | - $event = $post; |
|
108 | - } |
|
109 | - if ( $event instanceof EE_Event ) { |
|
110 | - $this->event = $event; |
|
111 | - } else if ( $event instanceof WP_Post ) { |
|
112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
113 | - $this->event = $event->EE_Event; |
|
114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
116 | - $this->event = $event->EE_Event; |
|
117 | - } |
|
118 | - } else { |
|
119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
120 | - $dev_msg = $user_msg . __( |
|
121 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
122 | - 'event_espresso' |
|
123 | - ); |
|
124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
125 | - return false; |
|
126 | - } |
|
127 | - return true; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function getMaxAttendees() |
|
136 | - { |
|
137 | - return $this->max_attendees; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param int $max_attendees |
|
144 | - */ |
|
145 | - public function setMaxAttendees($max_attendees) |
|
146 | - { |
|
147 | - $this->max_attendees = absint( |
|
148 | - apply_filters( |
|
149 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
150 | - $max_attendees |
|
151 | - ) |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * creates buttons for selecting number of attendees for an event |
|
159 | - * |
|
160 | - * @param WP_Post|int $event |
|
161 | - * @param bool $view_details |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - public function display( $event = null, $view_details = false ) |
|
166 | - { |
|
167 | - // reset filter for displaying submit button |
|
168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
169 | - // poke and prod incoming event till it tells us what it is |
|
170 | - if ( ! $this->setEvent( $event ) ) { |
|
171 | - return false; |
|
172 | - } |
|
173 | - // begin gathering template arguments by getting event status |
|
174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
176 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
177 | - } |
|
178 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
179 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
180 | - if ($this->getMaxAttendees() < 1) { |
|
181 | - return $this->ticketSalesClosedMessage(); |
|
182 | - } |
|
183 | - // is the event expired ? |
|
184 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
186 | - return $this->expiredEventMessage(); |
|
187 | - } |
|
188 | - // get all tickets for this event ordered by the datetime |
|
189 | - $tickets = $this->getTickets(); |
|
190 | - if (count($tickets) < 1) { |
|
191 | - return $this->noTicketAvailableMessage(); |
|
192 | - } |
|
193 | - if (EED_Events_Archive::is_iframe()){ |
|
194 | - $this->setIframe(); |
|
195 | - } |
|
196 | - // redirecting to another site for registration ?? |
|
197 | - $external_url = (string) $this->event->external_url(); |
|
198 | - // if redirecting to another site for registration, then we don't load the TS |
|
199 | - $ticket_selector = $external_url |
|
200 | - ? $this->externalEventRegistration() |
|
201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
202 | - // now set up the form (but not for the admin) |
|
203 | - $ticket_selector = ! is_admin() |
|
204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
205 | - : $ticket_selector; |
|
206 | - // submit button and form close tag |
|
207 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
208 | - return $ticket_selector; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * displayTicketSelector |
|
215 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
216 | - * |
|
217 | - * @param WP_Post|int $event |
|
218 | - * @param string $_event_active_status |
|
219 | - * @param bool $view_details |
|
220 | - * @return bool |
|
221 | - * @throws EE_Error |
|
222 | - */ |
|
223 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
224 | - { |
|
225 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
226 | - return ! is_admin() |
|
227 | - && ( |
|
228 | - ! $this->event->display_ticket_selector() |
|
229 | - || $view_details |
|
230 | - || post_password_required($event_post) |
|
231 | - || ( |
|
232 | - $_event_active_status !== EE_Datetime::active |
|
233 | - && $_event_active_status !== EE_Datetime::upcoming |
|
234 | - && $_event_active_status !== EE_Datetime::sold_out |
|
235 | - && ! ( |
|
236 | - $_event_active_status === EE_Datetime::inactive |
|
237 | - && is_user_logged_in() |
|
238 | - ) |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * noTicketAvailableMessage |
|
247 | - * notice displayed if event is expired |
|
248 | - * |
|
249 | - * @return string |
|
250 | - * @throws EE_Error |
|
251 | - */ |
|
252 | - protected function expiredEventMessage() |
|
253 | - { |
|
254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
255 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
256 | - 'event_espresso' |
|
257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * noTicketAvailableMessage |
|
264 | - * notice displayed if event has no more tickets available |
|
265 | - * |
|
266 | - * @return string |
|
267 | - * @throws EE_Error |
|
268 | - */ |
|
269 | - protected function noTicketAvailableMessage() |
|
270 | - { |
|
271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
272 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
273 | - $no_ticket_available_msg .= sprintf( |
|
274 | - esc_html__( |
|
275 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
276 | - 'event_espresso' |
|
277 | - ), |
|
278 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
279 | - '</b><br />', |
|
280 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
281 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
282 | - ); |
|
283 | - } |
|
284 | - return ' |
|
36 | + /** |
|
37 | + * event that ticket selector is being generated for |
|
38 | + * |
|
39 | + * @access protected |
|
40 | + * @var EE_Event $event |
|
41 | + */ |
|
42 | + protected $event; |
|
43 | + |
|
44 | + /** |
|
45 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
46 | + * |
|
47 | + * @var bool $iframe |
|
48 | + */ |
|
49 | + protected $iframe = false; |
|
50 | + |
|
51 | + /** |
|
52 | + * max attendees that can register for event at one time |
|
53 | + * |
|
54 | + * @var int $max_attendees |
|
55 | + */ |
|
56 | + private $max_attendees = EE_INF; |
|
57 | + |
|
58 | + /** |
|
59 | + *@var string $date_format |
|
60 | + */ |
|
61 | + private $date_format; |
|
62 | + |
|
63 | + /** |
|
64 | + *@var string $time_format |
|
65 | + */ |
|
66 | + private $time_format; |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * DisplayTicketSelector constructor. |
|
72 | + */ |
|
73 | + public function __construct() |
|
74 | + { |
|
75 | + $this->date_format = apply_filters( |
|
76 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
77 | + get_option('date_format') |
|
78 | + ); |
|
79 | + $this->time_format = apply_filters( |
|
80 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
81 | + get_option('time_format') |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param boolean $iframe |
|
89 | + */ |
|
90 | + public function setIframe( $iframe = true ) |
|
91 | + { |
|
92 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * finds and sets the \EE_Event object for use throughout class |
|
98 | + * |
|
99 | + * @param mixed $event |
|
100 | + * @return bool |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + protected function setEvent( $event = null ) |
|
104 | + { |
|
105 | + if ( $event === null ) { |
|
106 | + global $post; |
|
107 | + $event = $post; |
|
108 | + } |
|
109 | + if ( $event instanceof EE_Event ) { |
|
110 | + $this->event = $event; |
|
111 | + } else if ( $event instanceof WP_Post ) { |
|
112 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
113 | + $this->event = $event->EE_Event; |
|
114 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
116 | + $this->event = $event->EE_Event; |
|
117 | + } |
|
118 | + } else { |
|
119 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
120 | + $dev_msg = $user_msg . __( |
|
121 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
122 | + 'event_espresso' |
|
123 | + ); |
|
124 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
125 | + return false; |
|
126 | + } |
|
127 | + return true; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function getMaxAttendees() |
|
136 | + { |
|
137 | + return $this->max_attendees; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param int $max_attendees |
|
144 | + */ |
|
145 | + public function setMaxAttendees($max_attendees) |
|
146 | + { |
|
147 | + $this->max_attendees = absint( |
|
148 | + apply_filters( |
|
149 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
150 | + $max_attendees |
|
151 | + ) |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * creates buttons for selecting number of attendees for an event |
|
159 | + * |
|
160 | + * @param WP_Post|int $event |
|
161 | + * @param bool $view_details |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + public function display( $event = null, $view_details = false ) |
|
166 | + { |
|
167 | + // reset filter for displaying submit button |
|
168 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
169 | + // poke and prod incoming event till it tells us what it is |
|
170 | + if ( ! $this->setEvent( $event ) ) { |
|
171 | + return false; |
|
172 | + } |
|
173 | + // begin gathering template arguments by getting event status |
|
174 | + $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
175 | + if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
176 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
177 | + } |
|
178 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
179 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
180 | + if ($this->getMaxAttendees() < 1) { |
|
181 | + return $this->ticketSalesClosedMessage(); |
|
182 | + } |
|
183 | + // is the event expired ? |
|
184 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
185 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
186 | + return $this->expiredEventMessage(); |
|
187 | + } |
|
188 | + // get all tickets for this event ordered by the datetime |
|
189 | + $tickets = $this->getTickets(); |
|
190 | + if (count($tickets) < 1) { |
|
191 | + return $this->noTicketAvailableMessage(); |
|
192 | + } |
|
193 | + if (EED_Events_Archive::is_iframe()){ |
|
194 | + $this->setIframe(); |
|
195 | + } |
|
196 | + // redirecting to another site for registration ?? |
|
197 | + $external_url = (string) $this->event->external_url(); |
|
198 | + // if redirecting to another site for registration, then we don't load the TS |
|
199 | + $ticket_selector = $external_url |
|
200 | + ? $this->externalEventRegistration() |
|
201 | + : $this->loadTicketSelector($tickets,$template_args); |
|
202 | + // now set up the form (but not for the admin) |
|
203 | + $ticket_selector = ! is_admin() |
|
204 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
205 | + : $ticket_selector; |
|
206 | + // submit button and form close tag |
|
207 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
208 | + return $ticket_selector; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * displayTicketSelector |
|
215 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
216 | + * |
|
217 | + * @param WP_Post|int $event |
|
218 | + * @param string $_event_active_status |
|
219 | + * @param bool $view_details |
|
220 | + * @return bool |
|
221 | + * @throws EE_Error |
|
222 | + */ |
|
223 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
224 | + { |
|
225 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
226 | + return ! is_admin() |
|
227 | + && ( |
|
228 | + ! $this->event->display_ticket_selector() |
|
229 | + || $view_details |
|
230 | + || post_password_required($event_post) |
|
231 | + || ( |
|
232 | + $_event_active_status !== EE_Datetime::active |
|
233 | + && $_event_active_status !== EE_Datetime::upcoming |
|
234 | + && $_event_active_status !== EE_Datetime::sold_out |
|
235 | + && ! ( |
|
236 | + $_event_active_status === EE_Datetime::inactive |
|
237 | + && is_user_logged_in() |
|
238 | + ) |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * noTicketAvailableMessage |
|
247 | + * notice displayed if event is expired |
|
248 | + * |
|
249 | + * @return string |
|
250 | + * @throws EE_Error |
|
251 | + */ |
|
252 | + protected function expiredEventMessage() |
|
253 | + { |
|
254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
255 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
256 | + 'event_espresso' |
|
257 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * noTicketAvailableMessage |
|
264 | + * notice displayed if event has no more tickets available |
|
265 | + * |
|
266 | + * @return string |
|
267 | + * @throws EE_Error |
|
268 | + */ |
|
269 | + protected function noTicketAvailableMessage() |
|
270 | + { |
|
271 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
272 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
273 | + $no_ticket_available_msg .= sprintf( |
|
274 | + esc_html__( |
|
275 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
276 | + 'event_espresso' |
|
277 | + ), |
|
278 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
279 | + '</b><br />', |
|
280 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
281 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
282 | + ); |
|
283 | + } |
|
284 | + return ' |
|
285 | 285 | <div class="ee-event-expired-notice"> |
286 | 286 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * ticketSalesClosed |
|
294 | - * notice displayed if event ticket sales are turned off |
|
295 | - * |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - protected function ticketSalesClosedMessage() |
|
300 | - { |
|
301 | - $sales_closed_msg = esc_html__( |
|
302 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
303 | - 'event_espresso' |
|
304 | - ); |
|
305 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
306 | - $sales_closed_msg .= sprintf( |
|
307 | - esc_html__( |
|
308 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
309 | - 'event_espresso' |
|
310 | - ), |
|
311 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
312 | - '</b><br />', |
|
313 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
314 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
315 | - ); |
|
316 | - } |
|
317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * getTickets |
|
324 | - * |
|
325 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
326 | - * @throws EE_Error |
|
327 | - */ |
|
328 | - protected function getTickets() |
|
329 | - { |
|
330 | - $ticket_query_args = array( |
|
331 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
332 | - 'order_by' => array( |
|
333 | - 'TKT_order' => 'ASC', |
|
334 | - 'TKT_required' => 'DESC', |
|
335 | - 'TKT_start_date' => 'ASC', |
|
336 | - 'TKT_end_date' => 'ASC', |
|
337 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
338 | - ), |
|
339 | - ); |
|
340 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
341 | - //use the correct applicable time query depending on what version of core is being run. |
|
342 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
343 | - ? time() |
|
344 | - : current_time('timestamp'); |
|
345 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
346 | - } |
|
347 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * loadTicketSelector |
|
354 | - * begins to assemble template arguments |
|
355 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
356 | - * |
|
357 | - * @param \EE_Ticket[] $tickets |
|
358 | - * @param array $template_args |
|
359 | - * @return string |
|
360 | - * @throws EE_Error |
|
361 | - */ |
|
362 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
363 | - { |
|
364 | - $template_args['event'] = $this->event; |
|
365 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
366 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
367 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
368 | - $template_args['date_format'] = $this->date_format; |
|
369 | - $template_args['time_format'] = $this->time_format; |
|
370 | - /** |
|
371 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
372 | - * |
|
373 | - * @since 4.9.13 |
|
374 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
375 | - * @param int $EVT_ID The Event ID |
|
376 | - */ |
|
377 | - $template_args['anchor_id'] = apply_filters( |
|
378 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
380 | - $this->event->ID() |
|
381 | - ); |
|
382 | - $template_args['tickets'] = $tickets; |
|
383 | - $template_args['ticket_count'] = count($tickets); |
|
384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
385 | - return $ticket_selector instanceof TicketSelectorSimple |
|
386 | - ? $ticket_selector |
|
387 | - : new TicketSelectorStandard( |
|
388 | - $this->event, |
|
389 | - $tickets, |
|
390 | - $this->getMaxAttendees(), |
|
391 | - $template_args, |
|
392 | - $this->date_format, |
|
393 | - $this->time_format |
|
394 | - ); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * simpleTicketSelector |
|
401 | - * there's one ticket, and max attendees is set to one, |
|
402 | - * so if the event is free, then this is a "simple" ticket selector |
|
403 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
404 | - * |
|
405 | - * @param \EE_Ticket[] $tickets |
|
406 | - * @param array $template_args |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - */ |
|
410 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
411 | - { |
|
412 | - // if there is only ONE ticket with a max qty of ONE |
|
413 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
414 | - return ''; |
|
415 | - } |
|
416 | - /** @var \EE_Ticket $ticket */ |
|
417 | - $ticket = reset($tickets); |
|
418 | - // if the ticket is free... then not much need for the ticket selector |
|
419 | - if ( |
|
420 | - apply_filters( |
|
421 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
422 | - $ticket->is_free(), |
|
423 | - $this->event->ID() |
|
424 | - ) |
|
425 | - ) { |
|
426 | - return new TicketSelectorSimple( |
|
427 | - $this->event, |
|
428 | - $ticket, |
|
429 | - $this->getMaxAttendees(), |
|
430 | - $template_args |
|
431 | - ); |
|
432 | - } |
|
433 | - return ''; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * externalEventRegistration |
|
440 | - * |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - public function externalEventRegistration() |
|
444 | - { |
|
445 | - // if not we still need to trigger the display of the submit button |
|
446 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
447 | - //display notice to admin that registration is external |
|
448 | - return is_admin() |
|
449 | - ? esc_html__( |
|
450 | - 'Registration is at an external URL for this event.', |
|
451 | - 'event_espresso' |
|
452 | - ) |
|
453 | - : ''; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * formOpen |
|
460 | - * |
|
461 | - * @param int $ID |
|
462 | - * @param string $external_url |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
466 | - { |
|
467 | - // if redirecting, we don't need any anything else |
|
468 | - if ( $external_url ) { |
|
469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
470 | - // open link in new window ? |
|
471 | - $html .= apply_filters( |
|
472 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
473 | - EED_Events_Archive::is_iframe() |
|
474 | - ) |
|
475 | - ? ' target="_blank"' |
|
476 | - : ''; |
|
477 | - $html .= '>'; |
|
478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
481 | - } |
|
482 | - return $html; |
|
483 | - } |
|
484 | - // if there is no submit button, then don't start building a form |
|
485 | - // because the "View Details" button will build its own form |
|
486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
487 | - return ''; |
|
488 | - } |
|
489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
490 | - if ( ! $checkout_url ) { |
|
491 | - EE_Error::add_error( |
|
492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
493 | - __FILE__, |
|
494 | - __FUNCTION__, |
|
495 | - __LINE__ |
|
496 | - ); |
|
497 | - } |
|
498 | - // set no cache headers and constants |
|
499 | - EE_System::do_not_cache(); |
|
500 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
502 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
504 | - return $html; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * displaySubmitButton |
|
511 | - * |
|
512 | - * @param string $external_url |
|
513 | - * @return string |
|
514 | - * @throws EE_Error |
|
515 | - */ |
|
516 | - public function displaySubmitButton($external_url = '') |
|
517 | - { |
|
518 | - $html = ''; |
|
519 | - if ( ! is_admin()) { |
|
520 | - // standard TS displayed with submit button, ie: "Register Now" |
|
521 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
522 | - $html .= $this->displayRegisterNowButton(); |
|
523 | - $html .= empty($external_url) |
|
524 | - ? $this->ticketSelectorEndDiv() |
|
525 | - : $this->clearTicketSelector(); |
|
526 | - $html .= '<br/>' . $this->formClose(); |
|
527 | - } else if ($this->getMaxAttendees() === 1) { |
|
528 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
529 | - if ($this->event->is_sold_out()) { |
|
530 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
531 | - $html .= apply_filters( |
|
532 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
533 | - sprintf( |
|
534 | - __( |
|
535 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
536 | - 'event_espresso' |
|
537 | - ), |
|
538 | - '<p class="no-ticket-selector-msg clear-float">', |
|
539 | - $this->event->name(), |
|
540 | - '</p>', |
|
541 | - '<br />' |
|
542 | - ), |
|
543 | - $this->event |
|
544 | - ); |
|
545 | - if ( |
|
546 | - apply_filters( |
|
547 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
548 | - false, |
|
549 | - $this->event |
|
550 | - ) |
|
551 | - ) { |
|
552 | - $html .= $this->displayRegisterNowButton(); |
|
553 | - } |
|
554 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
555 | - $html .= $this->ticketSelectorEndDiv(); |
|
556 | - } else if ( |
|
557 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
558 | - && ! is_single() |
|
559 | - ) { |
|
560 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
561 | - // but no tickets are available, so display event's "View Details" button. |
|
562 | - // it is being viewed via somewhere other than a single post |
|
563 | - $html .= $this->displayViewDetailsButton(true); |
|
564 | - } else { |
|
565 | - $html .= $this->ticketSelectorEndDiv(); |
|
566 | - } |
|
567 | - } else if (is_archive()) { |
|
568 | - // event list, no tickets available so display event's "View Details" button |
|
569 | - $html .= $this->ticketSelectorEndDiv(); |
|
570 | - $html .= $this->displayViewDetailsButton(); |
|
571 | - } else { |
|
572 | - if ( |
|
573 | - apply_filters( |
|
574 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
575 | - false, |
|
576 | - $this->event |
|
577 | - ) |
|
578 | - ) { |
|
579 | - $html .= $this->displayRegisterNowButton(); |
|
580 | - } |
|
581 | - // no submit or view details button, and no additional content |
|
582 | - $html .= $this->ticketSelectorEndDiv(); |
|
583 | - } |
|
584 | - if ( ! $this->iframe && ! is_archive()) { |
|
585 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
586 | - } |
|
587 | - } |
|
588 | - return $html; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * @return string |
|
595 | - * @throws EE_Error |
|
596 | - */ |
|
597 | - public function displayRegisterNowButton() |
|
598 | - { |
|
599 | - $btn_text = apply_filters( |
|
600 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
601 | - __('Register Now', 'event_espresso'), |
|
602 | - $this->event |
|
603 | - ); |
|
604 | - $external_url = $this->event->external_url(); |
|
605 | - $html = EEH_HTML::div( |
|
606 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
607 | - ); |
|
608 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
609 | - $html .= ' class="ticket-selector-submit-btn '; |
|
610 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
611 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
612 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
613 | - $html .= apply_filters( |
|
614 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
615 | - '', |
|
616 | - $this->event |
|
617 | - ); |
|
618 | - return $html; |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * displayViewDetailsButton |
|
624 | - * |
|
625 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
626 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
627 | - * either because they are sold out, expired, or not yet on sale. |
|
628 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
629 | - * @return string |
|
630 | - * @throws EE_Error |
|
631 | - */ |
|
632 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
633 | - { |
|
634 | - if ( ! $this->event->get_permalink() ) { |
|
635 | - EE_Error::add_error( |
|
636 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
637 | - __FILE__, __FUNCTION__, __LINE__ |
|
638 | - ); |
|
639 | - } |
|
640 | - $view_details_btn = '<form method="POST" action="'; |
|
641 | - $view_details_btn .= apply_filters( |
|
642 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
643 | - $this->event->get_permalink(), |
|
644 | - $this->event |
|
645 | - ); |
|
646 | - $view_details_btn .= '"'; |
|
647 | - // open link in new window ? |
|
648 | - $view_details_btn .= apply_filters( |
|
649 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
650 | - EED_Events_Archive::is_iframe() |
|
651 | - ) |
|
652 | - ? ' target="_blank"' |
|
653 | - : ''; |
|
654 | - $view_details_btn .='>'; |
|
655 | - $btn_text = apply_filters( |
|
656 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
657 | - esc_html__('View Details', 'event_espresso'), |
|
658 | - $this->event |
|
659 | - ); |
|
660 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
661 | - . $this->event->ID() |
|
662 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
663 | - . $btn_text |
|
664 | - . '" />'; |
|
665 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
666 | - if ($DWMTS) { |
|
667 | - $view_details_btn .= $this->formClose(); |
|
668 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
669 | - $view_details_btn .= '<br/>'; |
|
670 | - } else { |
|
671 | - $view_details_btn .= $this->clearTicketSelector(); |
|
672 | - $view_details_btn .= '<br/>'; |
|
673 | - $view_details_btn .= $this->formClose(); |
|
674 | - } |
|
675 | - return $view_details_btn; |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * @return string |
|
682 | - */ |
|
683 | - public function ticketSelectorEndDiv() |
|
684 | - { |
|
685 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * @return string |
|
692 | - */ |
|
693 | - public function clearTicketSelector() |
|
694 | - { |
|
695 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
696 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * @access public |
|
703 | - * @return string |
|
704 | - */ |
|
705 | - public function formClose() |
|
706 | - { |
|
707 | - return '</form>'; |
|
708 | - } |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * ticketSalesClosed |
|
294 | + * notice displayed if event ticket sales are turned off |
|
295 | + * |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + protected function ticketSalesClosedMessage() |
|
300 | + { |
|
301 | + $sales_closed_msg = esc_html__( |
|
302 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
303 | + 'event_espresso' |
|
304 | + ); |
|
305 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
306 | + $sales_closed_msg .= sprintf( |
|
307 | + esc_html__( |
|
308 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
309 | + 'event_espresso' |
|
310 | + ), |
|
311 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
312 | + '</b><br />', |
|
313 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
314 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
315 | + ); |
|
316 | + } |
|
317 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * getTickets |
|
324 | + * |
|
325 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
326 | + * @throws EE_Error |
|
327 | + */ |
|
328 | + protected function getTickets() |
|
329 | + { |
|
330 | + $ticket_query_args = array( |
|
331 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
332 | + 'order_by' => array( |
|
333 | + 'TKT_order' => 'ASC', |
|
334 | + 'TKT_required' => 'DESC', |
|
335 | + 'TKT_start_date' => 'ASC', |
|
336 | + 'TKT_end_date' => 'ASC', |
|
337 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
338 | + ), |
|
339 | + ); |
|
340 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
341 | + //use the correct applicable time query depending on what version of core is being run. |
|
342 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
343 | + ? time() |
|
344 | + : current_time('timestamp'); |
|
345 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
346 | + } |
|
347 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * loadTicketSelector |
|
354 | + * begins to assemble template arguments |
|
355 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
356 | + * |
|
357 | + * @param \EE_Ticket[] $tickets |
|
358 | + * @param array $template_args |
|
359 | + * @return string |
|
360 | + * @throws EE_Error |
|
361 | + */ |
|
362 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
363 | + { |
|
364 | + $template_args['event'] = $this->event; |
|
365 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
366 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
367 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
368 | + $template_args['date_format'] = $this->date_format; |
|
369 | + $template_args['time_format'] = $this->time_format; |
|
370 | + /** |
|
371 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
372 | + * |
|
373 | + * @since 4.9.13 |
|
374 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
375 | + * @param int $EVT_ID The Event ID |
|
376 | + */ |
|
377 | + $template_args['anchor_id'] = apply_filters( |
|
378 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
379 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
380 | + $this->event->ID() |
|
381 | + ); |
|
382 | + $template_args['tickets'] = $tickets; |
|
383 | + $template_args['ticket_count'] = count($tickets); |
|
384 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
385 | + return $ticket_selector instanceof TicketSelectorSimple |
|
386 | + ? $ticket_selector |
|
387 | + : new TicketSelectorStandard( |
|
388 | + $this->event, |
|
389 | + $tickets, |
|
390 | + $this->getMaxAttendees(), |
|
391 | + $template_args, |
|
392 | + $this->date_format, |
|
393 | + $this->time_format |
|
394 | + ); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * simpleTicketSelector |
|
401 | + * there's one ticket, and max attendees is set to one, |
|
402 | + * so if the event is free, then this is a "simple" ticket selector |
|
403 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
404 | + * |
|
405 | + * @param \EE_Ticket[] $tickets |
|
406 | + * @param array $template_args |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + */ |
|
410 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
411 | + { |
|
412 | + // if there is only ONE ticket with a max qty of ONE |
|
413 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
414 | + return ''; |
|
415 | + } |
|
416 | + /** @var \EE_Ticket $ticket */ |
|
417 | + $ticket = reset($tickets); |
|
418 | + // if the ticket is free... then not much need for the ticket selector |
|
419 | + if ( |
|
420 | + apply_filters( |
|
421 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
422 | + $ticket->is_free(), |
|
423 | + $this->event->ID() |
|
424 | + ) |
|
425 | + ) { |
|
426 | + return new TicketSelectorSimple( |
|
427 | + $this->event, |
|
428 | + $ticket, |
|
429 | + $this->getMaxAttendees(), |
|
430 | + $template_args |
|
431 | + ); |
|
432 | + } |
|
433 | + return ''; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * externalEventRegistration |
|
440 | + * |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + public function externalEventRegistration() |
|
444 | + { |
|
445 | + // if not we still need to trigger the display of the submit button |
|
446 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
447 | + //display notice to admin that registration is external |
|
448 | + return is_admin() |
|
449 | + ? esc_html__( |
|
450 | + 'Registration is at an external URL for this event.', |
|
451 | + 'event_espresso' |
|
452 | + ) |
|
453 | + : ''; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * formOpen |
|
460 | + * |
|
461 | + * @param int $ID |
|
462 | + * @param string $external_url |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
466 | + { |
|
467 | + // if redirecting, we don't need any anything else |
|
468 | + if ( $external_url ) { |
|
469 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
470 | + // open link in new window ? |
|
471 | + $html .= apply_filters( |
|
472 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
473 | + EED_Events_Archive::is_iframe() |
|
474 | + ) |
|
475 | + ? ' target="_blank"' |
|
476 | + : ''; |
|
477 | + $html .= '>'; |
|
478 | + $query_args = EEH_URL::get_query_string( $external_url ); |
|
479 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
480 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
481 | + } |
|
482 | + return $html; |
|
483 | + } |
|
484 | + // if there is no submit button, then don't start building a form |
|
485 | + // because the "View Details" button will build its own form |
|
486 | + if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
487 | + return ''; |
|
488 | + } |
|
489 | + $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
490 | + if ( ! $checkout_url ) { |
|
491 | + EE_Error::add_error( |
|
492 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
493 | + __FILE__, |
|
494 | + __FUNCTION__, |
|
495 | + __LINE__ |
|
496 | + ); |
|
497 | + } |
|
498 | + // set no cache headers and constants |
|
499 | + EE_System::do_not_cache(); |
|
500 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
501 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
502 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
503 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
504 | + return $html; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * displaySubmitButton |
|
511 | + * |
|
512 | + * @param string $external_url |
|
513 | + * @return string |
|
514 | + * @throws EE_Error |
|
515 | + */ |
|
516 | + public function displaySubmitButton($external_url = '') |
|
517 | + { |
|
518 | + $html = ''; |
|
519 | + if ( ! is_admin()) { |
|
520 | + // standard TS displayed with submit button, ie: "Register Now" |
|
521 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
522 | + $html .= $this->displayRegisterNowButton(); |
|
523 | + $html .= empty($external_url) |
|
524 | + ? $this->ticketSelectorEndDiv() |
|
525 | + : $this->clearTicketSelector(); |
|
526 | + $html .= '<br/>' . $this->formClose(); |
|
527 | + } else if ($this->getMaxAttendees() === 1) { |
|
528 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
529 | + if ($this->event->is_sold_out()) { |
|
530 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
531 | + $html .= apply_filters( |
|
532 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
533 | + sprintf( |
|
534 | + __( |
|
535 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
536 | + 'event_espresso' |
|
537 | + ), |
|
538 | + '<p class="no-ticket-selector-msg clear-float">', |
|
539 | + $this->event->name(), |
|
540 | + '</p>', |
|
541 | + '<br />' |
|
542 | + ), |
|
543 | + $this->event |
|
544 | + ); |
|
545 | + if ( |
|
546 | + apply_filters( |
|
547 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
548 | + false, |
|
549 | + $this->event |
|
550 | + ) |
|
551 | + ) { |
|
552 | + $html .= $this->displayRegisterNowButton(); |
|
553 | + } |
|
554 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
555 | + $html .= $this->ticketSelectorEndDiv(); |
|
556 | + } else if ( |
|
557 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
558 | + && ! is_single() |
|
559 | + ) { |
|
560 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
561 | + // but no tickets are available, so display event's "View Details" button. |
|
562 | + // it is being viewed via somewhere other than a single post |
|
563 | + $html .= $this->displayViewDetailsButton(true); |
|
564 | + } else { |
|
565 | + $html .= $this->ticketSelectorEndDiv(); |
|
566 | + } |
|
567 | + } else if (is_archive()) { |
|
568 | + // event list, no tickets available so display event's "View Details" button |
|
569 | + $html .= $this->ticketSelectorEndDiv(); |
|
570 | + $html .= $this->displayViewDetailsButton(); |
|
571 | + } else { |
|
572 | + if ( |
|
573 | + apply_filters( |
|
574 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
575 | + false, |
|
576 | + $this->event |
|
577 | + ) |
|
578 | + ) { |
|
579 | + $html .= $this->displayRegisterNowButton(); |
|
580 | + } |
|
581 | + // no submit or view details button, and no additional content |
|
582 | + $html .= $this->ticketSelectorEndDiv(); |
|
583 | + } |
|
584 | + if ( ! $this->iframe && ! is_archive()) { |
|
585 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
586 | + } |
|
587 | + } |
|
588 | + return $html; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * @return string |
|
595 | + * @throws EE_Error |
|
596 | + */ |
|
597 | + public function displayRegisterNowButton() |
|
598 | + { |
|
599 | + $btn_text = apply_filters( |
|
600 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
601 | + __('Register Now', 'event_espresso'), |
|
602 | + $this->event |
|
603 | + ); |
|
604 | + $external_url = $this->event->external_url(); |
|
605 | + $html = EEH_HTML::div( |
|
606 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
607 | + ); |
|
608 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
609 | + $html .= ' class="ticket-selector-submit-btn '; |
|
610 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
611 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
612 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
613 | + $html .= apply_filters( |
|
614 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
615 | + '', |
|
616 | + $this->event |
|
617 | + ); |
|
618 | + return $html; |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * displayViewDetailsButton |
|
624 | + * |
|
625 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
626 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
627 | + * either because they are sold out, expired, or not yet on sale. |
|
628 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
629 | + * @return string |
|
630 | + * @throws EE_Error |
|
631 | + */ |
|
632 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
633 | + { |
|
634 | + if ( ! $this->event->get_permalink() ) { |
|
635 | + EE_Error::add_error( |
|
636 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
637 | + __FILE__, __FUNCTION__, __LINE__ |
|
638 | + ); |
|
639 | + } |
|
640 | + $view_details_btn = '<form method="POST" action="'; |
|
641 | + $view_details_btn .= apply_filters( |
|
642 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
643 | + $this->event->get_permalink(), |
|
644 | + $this->event |
|
645 | + ); |
|
646 | + $view_details_btn .= '"'; |
|
647 | + // open link in new window ? |
|
648 | + $view_details_btn .= apply_filters( |
|
649 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
650 | + EED_Events_Archive::is_iframe() |
|
651 | + ) |
|
652 | + ? ' target="_blank"' |
|
653 | + : ''; |
|
654 | + $view_details_btn .='>'; |
|
655 | + $btn_text = apply_filters( |
|
656 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
657 | + esc_html__('View Details', 'event_espresso'), |
|
658 | + $this->event |
|
659 | + ); |
|
660 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
661 | + . $this->event->ID() |
|
662 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
663 | + . $btn_text |
|
664 | + . '" />'; |
|
665 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
666 | + if ($DWMTS) { |
|
667 | + $view_details_btn .= $this->formClose(); |
|
668 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
669 | + $view_details_btn .= '<br/>'; |
|
670 | + } else { |
|
671 | + $view_details_btn .= $this->clearTicketSelector(); |
|
672 | + $view_details_btn .= '<br/>'; |
|
673 | + $view_details_btn .= $this->formClose(); |
|
674 | + } |
|
675 | + return $view_details_btn; |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * @return string |
|
682 | + */ |
|
683 | + public function ticketSelectorEndDiv() |
|
684 | + { |
|
685 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * @return string |
|
692 | + */ |
|
693 | + public function clearTicketSelector() |
|
694 | + { |
|
695 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
696 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * @access public |
|
703 | + * @return string |
|
704 | + */ |
|
705 | + public function formClose() |
|
706 | + { |
|
707 | + return '</form>'; |
|
708 | + } |
|
709 | 709 | |
710 | 710 | |
711 | 711 |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | use EEM_Ticket; |
16 | 16 | use WP_Post; |
17 | 17 | |
18 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
19 | - exit( 'No direct script access allowed' ); |
|
18 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
19 | + exit('No direct script access allowed'); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @param boolean $iframe |
89 | 89 | */ |
90 | - public function setIframe( $iframe = true ) |
|
90 | + public function setIframe($iframe = true) |
|
91 | 91 | { |
92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
92 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -100,28 +100,28 @@ discard block |
||
100 | 100 | * @return bool |
101 | 101 | * @throws EE_Error |
102 | 102 | */ |
103 | - protected function setEvent( $event = null ) |
|
103 | + protected function setEvent($event = null) |
|
104 | 104 | { |
105 | - if ( $event === null ) { |
|
105 | + if ($event === null) { |
|
106 | 106 | global $post; |
107 | 107 | $event = $post; |
108 | 108 | } |
109 | - if ( $event instanceof EE_Event ) { |
|
109 | + if ($event instanceof EE_Event) { |
|
110 | 110 | $this->event = $event; |
111 | - } else if ( $event instanceof WP_Post ) { |
|
112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
111 | + } else if ($event instanceof WP_Post) { |
|
112 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
113 | 113 | $this->event = $event->EE_Event; |
114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
114 | + } else if ($event->post_type === 'espresso_events') { |
|
115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
116 | 116 | $this->event = $event->EE_Event; |
117 | 117 | } |
118 | 118 | } else { |
119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
120 | - $dev_msg = $user_msg . __( |
|
119 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
120 | + $dev_msg = $user_msg.__( |
|
121 | 121 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
122 | 122 | 'event_espresso' |
123 | 123 | ); |
124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
124 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | return true; |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | * @return string |
163 | 163 | * @throws EE_Error |
164 | 164 | */ |
165 | - public function display( $event = null, $view_details = false ) |
|
165 | + public function display($event = null, $view_details = false) |
|
166 | 166 | { |
167 | 167 | // reset filter for displaying submit button |
168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
168 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
169 | 169 | // poke and prod incoming event till it tells us what it is |
170 | - if ( ! $this->setEvent( $event ) ) { |
|
170 | + if ( ! $this->setEvent($event)) { |
|
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | // begin gathering template arguments by getting event status |
174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
174 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
175 | + if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) { |
|
176 | 176 | return ! is_single() ? $this->displayViewDetailsButton() : ''; |
177 | 177 | } |
178 | 178 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | // is the event expired ? |
184 | 184 | $template_args['event_is_expired'] = $this->event->is_expired(); |
185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
185 | + if ($template_args['event_is_expired']) { |
|
186 | 186 | return $this->expiredEventMessage(); |
187 | 187 | } |
188 | 188 | // get all tickets for this event ordered by the datetime |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if (count($tickets) < 1) { |
191 | 191 | return $this->noTicketAvailableMessage(); |
192 | 192 | } |
193 | - if (EED_Events_Archive::is_iframe()){ |
|
193 | + if (EED_Events_Archive::is_iframe()) { |
|
194 | 194 | $this->setIframe(); |
195 | 195 | } |
196 | 196 | // redirecting to another site for registration ?? |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | // if redirecting to another site for registration, then we don't load the TS |
199 | 199 | $ticket_selector = $external_url |
200 | 200 | ? $this->externalEventRegistration() |
201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
201 | + : $this->loadTicketSelector($tickets, $template_args); |
|
202 | 202 | // now set up the form (but not for the admin) |
203 | 203 | $ticket_selector = ! is_admin() |
204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
204 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
205 | 205 | : $ticket_selector; |
206 | 206 | // submit button and form close tag |
207 | 207 | $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | */ |
252 | 252 | protected function expiredEventMessage() |
253 | 253 | { |
254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
255 | 255 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
256 | 256 | 'event_espresso' |
257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
257 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | protected function noTicketAvailableMessage() |
270 | 270 | { |
271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
271 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
272 | 272 | if (current_user_can('edit_post', $this->event->ID())) { |
273 | 273 | $no_ticket_available_msg .= sprintf( |
274 | 274 | esc_html__( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | return ' |
285 | 285 | <div class="ee-event-expired-notice"> |
286 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
286 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
288 | 288 | } |
289 | 289 | |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
315 | 315 | ); |
316 | 316 | } |
317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
317 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | |
@@ -376,12 +376,12 @@ discard block |
||
376 | 376 | */ |
377 | 377 | $template_args['anchor_id'] = apply_filters( |
378 | 378 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
379 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
380 | 380 | $this->event->ID() |
381 | 381 | ); |
382 | 382 | $template_args['tickets'] = $tickets; |
383 | 383 | $template_args['ticket_count'] = count($tickets); |
384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
384 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
385 | 385 | return $ticket_selector instanceof TicketSelectorSimple |
386 | 386 | ? $ticket_selector |
387 | 387 | : new TicketSelectorStandard( |
@@ -462,11 +462,11 @@ discard block |
||
462 | 462 | * @param string $external_url |
463 | 463 | * @return string |
464 | 464 | */ |
465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
465 | + public function formOpen($ID = 0, $external_url = '') |
|
466 | 466 | { |
467 | 467 | // if redirecting, we don't need any anything else |
468 | - if ( $external_url ) { |
|
469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
468 | + if ($external_url) { |
|
469 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
470 | 470 | // open link in new window ? |
471 | 471 | $html .= apply_filters( |
472 | 472 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -475,21 +475,21 @@ discard block |
||
475 | 475 | ? ' target="_blank"' |
476 | 476 | : ''; |
477 | 477 | $html .= '>'; |
478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
478 | + $query_args = EEH_URL::get_query_string($external_url); |
|
479 | + foreach ((array) $query_args as $query_arg => $value) { |
|
480 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
481 | 481 | } |
482 | 482 | return $html; |
483 | 483 | } |
484 | 484 | // if there is no submit button, then don't start building a form |
485 | 485 | // because the "View Details" button will build its own form |
486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
486 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
487 | 487 | return ''; |
488 | 488 | } |
489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
490 | - if ( ! $checkout_url ) { |
|
489 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
490 | + if ( ! $checkout_url) { |
|
491 | 491 | EE_Error::add_error( |
492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
492 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
493 | 493 | __FILE__, |
494 | 494 | __FUNCTION__, |
495 | 495 | __LINE__ |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | // set no cache headers and constants |
499 | 499 | EE_System::do_not_cache(); |
500 | 500 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
501 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
502 | 502 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
503 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
504 | 504 | return $html; |
505 | 505 | } |
506 | 506 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $html .= empty($external_url) |
524 | 524 | ? $this->ticketSelectorEndDiv() |
525 | 525 | : $this->clearTicketSelector(); |
526 | - $html .= '<br/>' . $this->formClose(); |
|
526 | + $html .= '<br/>'.$this->formClose(); |
|
527 | 527 | } else if ($this->getMaxAttendees() === 1) { |
528 | 528 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
529 | 529 | if ($this->event->is_sold_out()) { |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | $html .= $this->displayRegisterNowButton(); |
553 | 553 | } |
554 | 554 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
555 | - $html .= $this->ticketSelectorEndDiv(); |
|
555 | + $html .= $this->ticketSelectorEndDiv(); |
|
556 | 556 | } else if ( |
557 | 557 | apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
558 | 558 | && ! is_single() |
@@ -603,13 +603,13 @@ discard block |
||
603 | 603 | ); |
604 | 604 | $external_url = $this->event->external_url(); |
605 | 605 | $html = EEH_HTML::div( |
606 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
606 | + '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
607 | 607 | ); |
608 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
608 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
609 | 609 | $html .= ' class="ticket-selector-submit-btn '; |
610 | 610 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
611 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
612 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
611 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
612 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
613 | 613 | $html .= apply_filters( |
614 | 614 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
615 | 615 | '', |
@@ -629,11 +629,11 @@ discard block |
||
629 | 629 | * @return string |
630 | 630 | * @throws EE_Error |
631 | 631 | */ |
632 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
632 | + public function displayViewDetailsButton($DWMTS = false) |
|
633 | 633 | { |
634 | - if ( ! $this->event->get_permalink() ) { |
|
634 | + if ( ! $this->event->get_permalink()) { |
|
635 | 635 | EE_Error::add_error( |
636 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
636 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
637 | 637 | __FILE__, __FUNCTION__, __LINE__ |
638 | 638 | ); |
639 | 639 | } |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | ) |
652 | 652 | ? ' target="_blank"' |
653 | 653 | : ''; |
654 | - $view_details_btn .='>'; |
|
654 | + $view_details_btn .= '>'; |
|
655 | 655 | $btn_text = apply_filters( |
656 | 656 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
657 | 657 | esc_html__('View Details', 'event_espresso'), |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
663 | 663 | . $btn_text |
664 | 664 | . '" />'; |
665 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
665 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
666 | 666 | if ($DWMTS) { |
667 | 667 | $view_details_btn .= $this->formClose(); |
668 | 668 | $view_details_btn .= $this->ticketSelectorEndDiv(); |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | */ |
683 | 683 | public function ticketSelectorEndDiv() |
684 | 684 | { |
685 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
685 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
686 | 686 | } |
687 | 687 | |
688 | 688 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\modules\ticket_selector; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,570 +19,570 @@ discard block |
||
19 | 19 | class ProcessTicketSelector |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * array of datetimes and the spaces available for them |
|
24 | - * |
|
25 | - * @access private |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - private static $_available_spaces = array(); |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * cancelTicketSelections |
|
34 | - * |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function cancelTicketSelections() |
|
38 | - { |
|
39 | - // check nonce |
|
40 | - if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
41 | - return false; |
|
42 | - } |
|
43 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
44 | - if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
45 | - wp_safe_redirect( |
|
46 | - \EEH_Event_View::event_link_url( |
|
47 | - \EE_Registry::instance()->REQ->get('event_id') |
|
48 | - ) |
|
49 | - ); |
|
50 | - } else { |
|
51 | - wp_safe_redirect( |
|
52 | - site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
53 | - ); |
|
54 | - } |
|
55 | - exit(); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * processTicketSelectorNonce |
|
62 | - * |
|
63 | - * @param string $nonce_name |
|
64 | - * @param string $id |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
68 | - { |
|
69 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
70 | - if ( |
|
71 | - ! is_admin() |
|
72 | - && ( |
|
73 | - ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
74 | - || ! wp_verify_nonce( |
|
75 | - \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
76 | - $nonce_name |
|
77 | - ) |
|
78 | - ) |
|
79 | - ) { |
|
80 | - \EE_Error::add_error( |
|
81 | - sprintf( |
|
82 | - __( |
|
83 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
84 | - 'event_espresso' |
|
85 | - ), |
|
86 | - '<br/>' |
|
87 | - ), |
|
88 | - __FILE__, |
|
89 | - __FUNCTION__, |
|
90 | - __LINE__ |
|
91 | - ); |
|
92 | - return false; |
|
93 | - } |
|
94 | - return true; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * process_ticket_selections |
|
101 | - * |
|
102 | - * @return array|bool |
|
103 | - * @throws \EE_Error |
|
104 | - */ |
|
105 | - public function processTicketSelections() |
|
106 | - { |
|
107 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
108 | - // do we have an event id? |
|
109 | - if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
110 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
111 | - \EE_Error::add_error( |
|
112 | - sprintf( |
|
113 | - __( |
|
114 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - '<br/>' |
|
118 | - ), |
|
119 | - __FILE__, |
|
120 | - __FUNCTION__, |
|
121 | - __LINE__ |
|
122 | - ); |
|
123 | - } |
|
124 | - //if event id is valid |
|
125 | - $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
126 | - // d( \EE_Registry::instance()->REQ ); |
|
127 | - self::$_available_spaces = array( |
|
128 | - 'tickets' => array(), |
|
129 | - 'datetimes' => array(), |
|
130 | - ); |
|
131 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
132 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
133 | - \EE_Registry::instance()->load_core('Session'); |
|
134 | - // unless otherwise requested, clear the session |
|
135 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
136 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
137 | - } |
|
138 | - //d( \EE_Registry::instance()->SSN ); |
|
139 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
140 | - // validate/sanitize data |
|
141 | - $valid = $this->validatePostData($id); |
|
142 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
143 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
144 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
145 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
146 | - //check total tickets ordered vs max number of attendees that can register |
|
147 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
148 | - // ordering too many tickets !!! |
|
149 | - $total_tickets_string = _n( |
|
150 | - 'You have attempted to purchase %s ticket.', |
|
151 | - 'You have attempted to purchase %s tickets.', |
|
152 | - $valid['total_tickets'], |
|
153 | - 'event_espresso' |
|
154 | - ); |
|
155 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
156 | - // dev only message |
|
157 | - $max_atndz_string = _n( |
|
158 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
159 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
160 | - $valid['max_atndz'], |
|
161 | - 'event_espresso' |
|
162 | - ); |
|
163 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
164 | - \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - } else { |
|
166 | - // all data appears to be valid |
|
167 | - $tckts_slctd = false; |
|
168 | - $tickets_added = 0; |
|
169 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
170 | - if ($valid['total_tickets'] > 0) { |
|
171 | - // load cart |
|
172 | - \EE_Registry::instance()->load_core('Cart'); |
|
173 | - // cycle thru the number of data rows sent from the event listing |
|
174 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
175 | - // does this row actually contain a ticket quantity? |
|
176 | - if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
177 | - // YES we have a ticket quantity |
|
178 | - $tckts_slctd = true; |
|
179 | - // d( $valid['ticket_obj'][$x] ); |
|
180 | - if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
181 | - // then add ticket to cart |
|
182 | - $tickets_added += $this->addTicketToCart( |
|
183 | - $valid['ticket_obj'][$x], |
|
184 | - $valid['qty'][$x] |
|
185 | - ); |
|
186 | - if (\EE_Error::has_error()) { |
|
187 | - break; |
|
188 | - } |
|
189 | - } else { |
|
190 | - // nothing added to cart retrieved |
|
191 | - \EE_Error::add_error( |
|
192 | - sprintf( |
|
193 | - __( |
|
194 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - '<br/>' |
|
198 | - ), |
|
199 | - __FILE__, __FUNCTION__, __LINE__ |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - } |
|
205 | - do_action( |
|
206 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
207 | - \EE_Registry::instance()->CART, |
|
208 | - $this |
|
209 | - ); |
|
210 | - //d( \EE_Registry::instance()->CART ); |
|
211 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
212 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
213 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
214 | - do_action( |
|
215 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
216 | - \EE_Registry::instance()->CART, |
|
217 | - $this |
|
218 | - ); |
|
219 | - \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
220 | - \EE_Registry::instance()->CART->save_cart(false); |
|
221 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
222 | - // just return TRUE for registrations being made from admin |
|
223 | - if (is_admin()) { |
|
224 | - return true; |
|
225 | - } |
|
226 | - \EE_Error::get_notices(false, true); |
|
227 | - wp_safe_redirect( |
|
228 | - apply_filters( |
|
229 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
230 | - \EE_Registry::instance()->CFG->core->reg_page_url() |
|
231 | - ) |
|
232 | - ); |
|
233 | - exit(); |
|
234 | - } else { |
|
235 | - if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
236 | - // nothing added to cart |
|
237 | - \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
238 | - __FILE__, __FUNCTION__, __LINE__); |
|
239 | - } |
|
240 | - } |
|
241 | - } else { |
|
242 | - // no ticket quantities were selected |
|
243 | - \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
244 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
245 | - } |
|
246 | - } |
|
247 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
248 | - // at this point, just return if registration is being made from admin |
|
249 | - if (is_admin()) { |
|
250 | - return false; |
|
251 | - } |
|
252 | - if ($valid['return_url']) { |
|
253 | - \EE_Error::get_notices(false, true); |
|
254 | - wp_safe_redirect($valid['return_url']); |
|
255 | - exit(); |
|
256 | - } elseif (isset($event_to_add['id'])) { |
|
257 | - \EE_Error::get_notices(false, true); |
|
258 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
259 | - exit(); |
|
260 | - } else { |
|
261 | - echo \EE_Error::get_notices(); |
|
262 | - } |
|
263 | - return false; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * validate_post_data |
|
270 | - * |
|
271 | - * @param int $id |
|
272 | - * @return array|FALSE |
|
273 | - */ |
|
274 | - private function validatePostData($id = 0) |
|
275 | - { |
|
276 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
277 | - if ( ! $id) { |
|
278 | - \EE_Error::add_error( |
|
279 | - __('The event id provided was not valid.', 'event_espresso'), |
|
280 | - __FILE__, |
|
281 | - __FUNCTION__, |
|
282 | - __LINE__ |
|
283 | - ); |
|
284 | - return false; |
|
285 | - } |
|
286 | - // start with an empty array() |
|
287 | - $valid_data = array(); |
|
288 | - // grab valid id |
|
289 | - $valid_data['id'] = $id; |
|
290 | - // array of other form names |
|
291 | - $inputs_to_clean = array( |
|
292 | - 'event_id' => 'tkt-slctr-event-id', |
|
293 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
294 | - 'rows' => 'tkt-slctr-rows-', |
|
295 | - 'qty' => 'tkt-slctr-qty-', |
|
296 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
297 | - 'return_url' => 'tkt-slctr-return-url-', |
|
298 | - ); |
|
299 | - // let's track the total number of tickets ordered.' |
|
300 | - $valid_data['total_tickets'] = 0; |
|
301 | - // cycle through $inputs_to_clean array |
|
302 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
303 | - // check for POST data |
|
304 | - if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
305 | - // grab value |
|
306 | - $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
307 | - switch ($what) { |
|
308 | - // integers |
|
309 | - case 'event_id': |
|
310 | - $valid_data[$what] = absint($input_value); |
|
311 | - // get event via the event id we put in the form |
|
312 | - $valid_data['event'] = \EE_Registry::instance() |
|
313 | - ->load_model('Event') |
|
314 | - ->get_one_by_ID($valid_data['event_id']); |
|
315 | - break; |
|
316 | - case 'rows': |
|
317 | - case 'max_atndz': |
|
318 | - $valid_data[$what] = absint($input_value); |
|
319 | - break; |
|
320 | - // arrays of integers |
|
321 | - case 'qty': |
|
322 | - /** @var array $row_qty */ |
|
323 | - $row_qty = $input_value; |
|
324 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
325 | - if ( ! is_array($row_qty)) { |
|
326 | - // get number of rows |
|
327 | - $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
328 | - ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
329 | - : 1; |
|
330 | - // explode ints by the dash |
|
331 | - $row_qty = explode('-', $row_qty); |
|
332 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
333 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
334 | - $row_qty = array($row => $qty); |
|
335 | - for ($x = 1; $x <= $rows; $x++) { |
|
336 | - if ( ! isset($row_qty[$x])) { |
|
337 | - $row_qty[$x] = 0; |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - ksort($row_qty); |
|
342 | - // cycle thru values |
|
343 | - foreach ($row_qty as $qty) { |
|
344 | - $qty = absint($qty); |
|
345 | - // sanitize as integers |
|
346 | - $valid_data[$what][] = $qty; |
|
347 | - $valid_data['total_tickets'] += $qty; |
|
348 | - } |
|
349 | - break; |
|
350 | - // array of integers |
|
351 | - case 'ticket_id': |
|
352 | - $value_array = array(); |
|
353 | - // cycle thru values |
|
354 | - foreach ((array)$input_value as $key => $value) { |
|
355 | - // allow only numbers, letters, spaces, commas and dashes |
|
356 | - $value_array[$key] = wp_strip_all_tags($value); |
|
357 | - // get ticket via the ticket id we put in the form |
|
358 | - $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
359 | - $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
360 | - } |
|
361 | - $valid_data[$what] = $value_array; |
|
362 | - break; |
|
363 | - case 'return_url' : |
|
364 | - // grab and sanitize return-url |
|
365 | - $input_value = esc_url_raw($input_value); |
|
366 | - // was the request coming from an iframe ? if so, then: |
|
367 | - if (strpos($input_value, 'event_list=iframe')) { |
|
368 | - // get anchor fragment |
|
369 | - $input_value = explode('#', $input_value); |
|
370 | - $input_value = end($input_value); |
|
371 | - // use event list url instead, but append anchor |
|
372 | - $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
373 | - } |
|
374 | - $valid_data[$what] = $input_value; |
|
375 | - break; |
|
376 | - } // end switch $what |
|
377 | - } |
|
378 | - } // end foreach $inputs_to_clean |
|
379 | - return $valid_data; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * adds a ticket to the cart |
|
386 | - * |
|
387 | - * @param \EE_Ticket $ticket |
|
388 | - * @param int $qty |
|
389 | - * @return TRUE on success, FALSE on fail |
|
390 | - * @throws \EE_Error |
|
391 | - */ |
|
392 | - private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
393 | - { |
|
394 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
395 | - // get the number of spaces left for this datetime ticket |
|
396 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
397 | - // compare available spaces against the number of tickets being purchased |
|
398 | - if ($available_spaces >= $qty) { |
|
399 | - // allow addons to prevent a ticket from being added to cart |
|
400 | - if ( |
|
401 | - ! apply_filters( |
|
402 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
403 | - true, |
|
404 | - $ticket, |
|
405 | - $qty, |
|
406 | - $available_spaces |
|
407 | - ) |
|
408 | - ) { |
|
409 | - return false; |
|
410 | - } |
|
411 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
412 | - // add event to cart |
|
413 | - if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
414 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
415 | - return true; |
|
416 | - } |
|
417 | - return false; |
|
418 | - } |
|
419 | - // tickets can not be purchased but let's find the exact number left |
|
420 | - // for the last ticket selected PRIOR to subtracting tickets |
|
421 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
422 | - // greedy greedy greedy eh? |
|
423 | - if ($available_spaces > 0) { |
|
424 | - if ( |
|
425 | - apply_filters( |
|
426 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
427 | - true, |
|
428 | - $ticket, |
|
429 | - $qty, |
|
430 | - $available_spaces |
|
431 | - ) |
|
432 | - ) { |
|
433 | - $this->displayAvailabilityError($available_spaces); |
|
434 | - } |
|
435 | - } else { |
|
436 | - \EE_Error::add_error( |
|
437 | - __( |
|
438 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
439 | - 'event_espresso' |
|
440 | - ), |
|
441 | - __FILE__, __FUNCTION__, __LINE__ |
|
442 | - ); |
|
443 | - } |
|
444 | - return false; |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @param int $available_spaces |
|
451 | - * @throws \EE_Error |
|
452 | - */ |
|
453 | - private function displayAvailabilityError($available_spaces = 1) |
|
454 | - { |
|
455 | - // add error messaging - we're using the _n function that will generate |
|
456 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
457 | - if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
458 | - $msg = sprintf( |
|
459 | - _n( |
|
460 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
461 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
462 | - $available_spaces, |
|
463 | - 'event_espresso' |
|
464 | - ), |
|
465 | - $available_spaces, |
|
466 | - '<br />' |
|
467 | - ); |
|
468 | - } else { |
|
469 | - $msg = sprintf( |
|
470 | - _n( |
|
471 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
472 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
473 | - $available_spaces, |
|
474 | - 'event_espresso' |
|
475 | - ), |
|
476 | - $available_spaces, |
|
477 | - '<br />' |
|
478 | - ); |
|
479 | - } |
|
480 | - \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * ticketDatetimeAvailability |
|
487 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
488 | - * and tracks the spaces remaining for each of those datetimes |
|
489 | - * |
|
490 | - * @param \EE_Ticket $ticket - selected ticket |
|
491 | - * @param bool $get_original_ticket_spaces |
|
492 | - * @return int |
|
493 | - * @throws \EE_Error |
|
494 | - */ |
|
495 | - private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
496 | - { |
|
497 | - // if the $_available_spaces array has not been set up yet... |
|
498 | - if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
499 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
500 | - } |
|
501 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
502 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
503 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
504 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
505 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
506 | - if ($get_original_ticket_spaces) { |
|
507 | - // then grab the available spaces from the "tickets" array |
|
508 | - // and compare with the above to get the lowest number |
|
509 | - $available_spaces = min( |
|
510 | - $available_spaces, |
|
511 | - self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
512 | - ); |
|
513 | - } else { |
|
514 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
515 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - return $available_spaces; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param \EE_Ticket $ticket |
|
526 | - * @return void |
|
527 | - * @throws \EE_Error |
|
528 | - */ |
|
529 | - private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
530 | - { |
|
531 | - // first, get all of the datetimes that are available to this ticket |
|
532 | - $datetimes = $ticket->get_many_related( |
|
533 | - 'Datetime', |
|
534 | - array( |
|
535 | - array( |
|
536 | - 'DTT_EVT_end' => array( |
|
537 | - '>=', |
|
538 | - \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
539 | - ), |
|
540 | - ), |
|
541 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
542 | - ) |
|
543 | - ); |
|
544 | - if ( ! empty($datetimes)) { |
|
545 | - // now loop thru all of the datetimes |
|
546 | - foreach ($datetimes as $datetime) { |
|
547 | - if ($datetime instanceof \EE_Datetime) { |
|
548 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
549 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
550 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
551 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
552 | - self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
553 | - $ticket->qty() - $ticket->sold(), |
|
554 | - $spaces_remaining |
|
555 | - ); |
|
556 | - // if the remaining spaces for this datetime is already set, |
|
557 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
558 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
559 | - self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
560 | - self::$_available_spaces['datetimes'][$datetime->ID()] |
|
561 | - ) |
|
562 | - ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
563 | - : $spaces_remaining; |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * @param \EE_Ticket $ticket |
|
573 | - * @param int $qty |
|
574 | - * @return void |
|
575 | - */ |
|
576 | - private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
577 | - { |
|
578 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
579 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
580 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
581 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
582 | - self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
583 | - } |
|
584 | - } |
|
585 | - } |
|
22 | + /** |
|
23 | + * array of datetimes and the spaces available for them |
|
24 | + * |
|
25 | + * @access private |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + private static $_available_spaces = array(); |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * cancelTicketSelections |
|
34 | + * |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function cancelTicketSelections() |
|
38 | + { |
|
39 | + // check nonce |
|
40 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
41 | + return false; |
|
42 | + } |
|
43 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
44 | + if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
45 | + wp_safe_redirect( |
|
46 | + \EEH_Event_View::event_link_url( |
|
47 | + \EE_Registry::instance()->REQ->get('event_id') |
|
48 | + ) |
|
49 | + ); |
|
50 | + } else { |
|
51 | + wp_safe_redirect( |
|
52 | + site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
53 | + ); |
|
54 | + } |
|
55 | + exit(); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * processTicketSelectorNonce |
|
62 | + * |
|
63 | + * @param string $nonce_name |
|
64 | + * @param string $id |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
68 | + { |
|
69 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
70 | + if ( |
|
71 | + ! is_admin() |
|
72 | + && ( |
|
73 | + ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
74 | + || ! wp_verify_nonce( |
|
75 | + \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
76 | + $nonce_name |
|
77 | + ) |
|
78 | + ) |
|
79 | + ) { |
|
80 | + \EE_Error::add_error( |
|
81 | + sprintf( |
|
82 | + __( |
|
83 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
84 | + 'event_espresso' |
|
85 | + ), |
|
86 | + '<br/>' |
|
87 | + ), |
|
88 | + __FILE__, |
|
89 | + __FUNCTION__, |
|
90 | + __LINE__ |
|
91 | + ); |
|
92 | + return false; |
|
93 | + } |
|
94 | + return true; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * process_ticket_selections |
|
101 | + * |
|
102 | + * @return array|bool |
|
103 | + * @throws \EE_Error |
|
104 | + */ |
|
105 | + public function processTicketSelections() |
|
106 | + { |
|
107 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
108 | + // do we have an event id? |
|
109 | + if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
110 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
111 | + \EE_Error::add_error( |
|
112 | + sprintf( |
|
113 | + __( |
|
114 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + '<br/>' |
|
118 | + ), |
|
119 | + __FILE__, |
|
120 | + __FUNCTION__, |
|
121 | + __LINE__ |
|
122 | + ); |
|
123 | + } |
|
124 | + //if event id is valid |
|
125 | + $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
126 | + // d( \EE_Registry::instance()->REQ ); |
|
127 | + self::$_available_spaces = array( |
|
128 | + 'tickets' => array(), |
|
129 | + 'datetimes' => array(), |
|
130 | + ); |
|
131 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
132 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
133 | + \EE_Registry::instance()->load_core('Session'); |
|
134 | + // unless otherwise requested, clear the session |
|
135 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
136 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
137 | + } |
|
138 | + //d( \EE_Registry::instance()->SSN ); |
|
139 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
140 | + // validate/sanitize data |
|
141 | + $valid = $this->validatePostData($id); |
|
142 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
143 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
144 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
145 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
146 | + //check total tickets ordered vs max number of attendees that can register |
|
147 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
148 | + // ordering too many tickets !!! |
|
149 | + $total_tickets_string = _n( |
|
150 | + 'You have attempted to purchase %s ticket.', |
|
151 | + 'You have attempted to purchase %s tickets.', |
|
152 | + $valid['total_tickets'], |
|
153 | + 'event_espresso' |
|
154 | + ); |
|
155 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
156 | + // dev only message |
|
157 | + $max_atndz_string = _n( |
|
158 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
159 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
160 | + $valid['max_atndz'], |
|
161 | + 'event_espresso' |
|
162 | + ); |
|
163 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
164 | + \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + } else { |
|
166 | + // all data appears to be valid |
|
167 | + $tckts_slctd = false; |
|
168 | + $tickets_added = 0; |
|
169 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
170 | + if ($valid['total_tickets'] > 0) { |
|
171 | + // load cart |
|
172 | + \EE_Registry::instance()->load_core('Cart'); |
|
173 | + // cycle thru the number of data rows sent from the event listing |
|
174 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
175 | + // does this row actually contain a ticket quantity? |
|
176 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
177 | + // YES we have a ticket quantity |
|
178 | + $tckts_slctd = true; |
|
179 | + // d( $valid['ticket_obj'][$x] ); |
|
180 | + if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
181 | + // then add ticket to cart |
|
182 | + $tickets_added += $this->addTicketToCart( |
|
183 | + $valid['ticket_obj'][$x], |
|
184 | + $valid['qty'][$x] |
|
185 | + ); |
|
186 | + if (\EE_Error::has_error()) { |
|
187 | + break; |
|
188 | + } |
|
189 | + } else { |
|
190 | + // nothing added to cart retrieved |
|
191 | + \EE_Error::add_error( |
|
192 | + sprintf( |
|
193 | + __( |
|
194 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + '<br/>' |
|
198 | + ), |
|
199 | + __FILE__, __FUNCTION__, __LINE__ |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + } |
|
205 | + do_action( |
|
206 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
207 | + \EE_Registry::instance()->CART, |
|
208 | + $this |
|
209 | + ); |
|
210 | + //d( \EE_Registry::instance()->CART ); |
|
211 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
212 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
213 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
214 | + do_action( |
|
215 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
216 | + \EE_Registry::instance()->CART, |
|
217 | + $this |
|
218 | + ); |
|
219 | + \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
220 | + \EE_Registry::instance()->CART->save_cart(false); |
|
221 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
222 | + // just return TRUE for registrations being made from admin |
|
223 | + if (is_admin()) { |
|
224 | + return true; |
|
225 | + } |
|
226 | + \EE_Error::get_notices(false, true); |
|
227 | + wp_safe_redirect( |
|
228 | + apply_filters( |
|
229 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
230 | + \EE_Registry::instance()->CFG->core->reg_page_url() |
|
231 | + ) |
|
232 | + ); |
|
233 | + exit(); |
|
234 | + } else { |
|
235 | + if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
236 | + // nothing added to cart |
|
237 | + \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
238 | + __FILE__, __FUNCTION__, __LINE__); |
|
239 | + } |
|
240 | + } |
|
241 | + } else { |
|
242 | + // no ticket quantities were selected |
|
243 | + \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
244 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
245 | + } |
|
246 | + } |
|
247 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
248 | + // at this point, just return if registration is being made from admin |
|
249 | + if (is_admin()) { |
|
250 | + return false; |
|
251 | + } |
|
252 | + if ($valid['return_url']) { |
|
253 | + \EE_Error::get_notices(false, true); |
|
254 | + wp_safe_redirect($valid['return_url']); |
|
255 | + exit(); |
|
256 | + } elseif (isset($event_to_add['id'])) { |
|
257 | + \EE_Error::get_notices(false, true); |
|
258 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
259 | + exit(); |
|
260 | + } else { |
|
261 | + echo \EE_Error::get_notices(); |
|
262 | + } |
|
263 | + return false; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * validate_post_data |
|
270 | + * |
|
271 | + * @param int $id |
|
272 | + * @return array|FALSE |
|
273 | + */ |
|
274 | + private function validatePostData($id = 0) |
|
275 | + { |
|
276 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
277 | + if ( ! $id) { |
|
278 | + \EE_Error::add_error( |
|
279 | + __('The event id provided was not valid.', 'event_espresso'), |
|
280 | + __FILE__, |
|
281 | + __FUNCTION__, |
|
282 | + __LINE__ |
|
283 | + ); |
|
284 | + return false; |
|
285 | + } |
|
286 | + // start with an empty array() |
|
287 | + $valid_data = array(); |
|
288 | + // grab valid id |
|
289 | + $valid_data['id'] = $id; |
|
290 | + // array of other form names |
|
291 | + $inputs_to_clean = array( |
|
292 | + 'event_id' => 'tkt-slctr-event-id', |
|
293 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
294 | + 'rows' => 'tkt-slctr-rows-', |
|
295 | + 'qty' => 'tkt-slctr-qty-', |
|
296 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
297 | + 'return_url' => 'tkt-slctr-return-url-', |
|
298 | + ); |
|
299 | + // let's track the total number of tickets ordered.' |
|
300 | + $valid_data['total_tickets'] = 0; |
|
301 | + // cycle through $inputs_to_clean array |
|
302 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
303 | + // check for POST data |
|
304 | + if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
305 | + // grab value |
|
306 | + $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
307 | + switch ($what) { |
|
308 | + // integers |
|
309 | + case 'event_id': |
|
310 | + $valid_data[$what] = absint($input_value); |
|
311 | + // get event via the event id we put in the form |
|
312 | + $valid_data['event'] = \EE_Registry::instance() |
|
313 | + ->load_model('Event') |
|
314 | + ->get_one_by_ID($valid_data['event_id']); |
|
315 | + break; |
|
316 | + case 'rows': |
|
317 | + case 'max_atndz': |
|
318 | + $valid_data[$what] = absint($input_value); |
|
319 | + break; |
|
320 | + // arrays of integers |
|
321 | + case 'qty': |
|
322 | + /** @var array $row_qty */ |
|
323 | + $row_qty = $input_value; |
|
324 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
325 | + if ( ! is_array($row_qty)) { |
|
326 | + // get number of rows |
|
327 | + $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
328 | + ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
329 | + : 1; |
|
330 | + // explode ints by the dash |
|
331 | + $row_qty = explode('-', $row_qty); |
|
332 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
333 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
334 | + $row_qty = array($row => $qty); |
|
335 | + for ($x = 1; $x <= $rows; $x++) { |
|
336 | + if ( ! isset($row_qty[$x])) { |
|
337 | + $row_qty[$x] = 0; |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + ksort($row_qty); |
|
342 | + // cycle thru values |
|
343 | + foreach ($row_qty as $qty) { |
|
344 | + $qty = absint($qty); |
|
345 | + // sanitize as integers |
|
346 | + $valid_data[$what][] = $qty; |
|
347 | + $valid_data['total_tickets'] += $qty; |
|
348 | + } |
|
349 | + break; |
|
350 | + // array of integers |
|
351 | + case 'ticket_id': |
|
352 | + $value_array = array(); |
|
353 | + // cycle thru values |
|
354 | + foreach ((array)$input_value as $key => $value) { |
|
355 | + // allow only numbers, letters, spaces, commas and dashes |
|
356 | + $value_array[$key] = wp_strip_all_tags($value); |
|
357 | + // get ticket via the ticket id we put in the form |
|
358 | + $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
359 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
360 | + } |
|
361 | + $valid_data[$what] = $value_array; |
|
362 | + break; |
|
363 | + case 'return_url' : |
|
364 | + // grab and sanitize return-url |
|
365 | + $input_value = esc_url_raw($input_value); |
|
366 | + // was the request coming from an iframe ? if so, then: |
|
367 | + if (strpos($input_value, 'event_list=iframe')) { |
|
368 | + // get anchor fragment |
|
369 | + $input_value = explode('#', $input_value); |
|
370 | + $input_value = end($input_value); |
|
371 | + // use event list url instead, but append anchor |
|
372 | + $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
373 | + } |
|
374 | + $valid_data[$what] = $input_value; |
|
375 | + break; |
|
376 | + } // end switch $what |
|
377 | + } |
|
378 | + } // end foreach $inputs_to_clean |
|
379 | + return $valid_data; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * adds a ticket to the cart |
|
386 | + * |
|
387 | + * @param \EE_Ticket $ticket |
|
388 | + * @param int $qty |
|
389 | + * @return TRUE on success, FALSE on fail |
|
390 | + * @throws \EE_Error |
|
391 | + */ |
|
392 | + private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
393 | + { |
|
394 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
395 | + // get the number of spaces left for this datetime ticket |
|
396 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
397 | + // compare available spaces against the number of tickets being purchased |
|
398 | + if ($available_spaces >= $qty) { |
|
399 | + // allow addons to prevent a ticket from being added to cart |
|
400 | + if ( |
|
401 | + ! apply_filters( |
|
402 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
403 | + true, |
|
404 | + $ticket, |
|
405 | + $qty, |
|
406 | + $available_spaces |
|
407 | + ) |
|
408 | + ) { |
|
409 | + return false; |
|
410 | + } |
|
411 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
412 | + // add event to cart |
|
413 | + if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
414 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
415 | + return true; |
|
416 | + } |
|
417 | + return false; |
|
418 | + } |
|
419 | + // tickets can not be purchased but let's find the exact number left |
|
420 | + // for the last ticket selected PRIOR to subtracting tickets |
|
421 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
422 | + // greedy greedy greedy eh? |
|
423 | + if ($available_spaces > 0) { |
|
424 | + if ( |
|
425 | + apply_filters( |
|
426 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
427 | + true, |
|
428 | + $ticket, |
|
429 | + $qty, |
|
430 | + $available_spaces |
|
431 | + ) |
|
432 | + ) { |
|
433 | + $this->displayAvailabilityError($available_spaces); |
|
434 | + } |
|
435 | + } else { |
|
436 | + \EE_Error::add_error( |
|
437 | + __( |
|
438 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
439 | + 'event_espresso' |
|
440 | + ), |
|
441 | + __FILE__, __FUNCTION__, __LINE__ |
|
442 | + ); |
|
443 | + } |
|
444 | + return false; |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @param int $available_spaces |
|
451 | + * @throws \EE_Error |
|
452 | + */ |
|
453 | + private function displayAvailabilityError($available_spaces = 1) |
|
454 | + { |
|
455 | + // add error messaging - we're using the _n function that will generate |
|
456 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
457 | + if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
458 | + $msg = sprintf( |
|
459 | + _n( |
|
460 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
461 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
462 | + $available_spaces, |
|
463 | + 'event_espresso' |
|
464 | + ), |
|
465 | + $available_spaces, |
|
466 | + '<br />' |
|
467 | + ); |
|
468 | + } else { |
|
469 | + $msg = sprintf( |
|
470 | + _n( |
|
471 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
472 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
473 | + $available_spaces, |
|
474 | + 'event_espresso' |
|
475 | + ), |
|
476 | + $available_spaces, |
|
477 | + '<br />' |
|
478 | + ); |
|
479 | + } |
|
480 | + \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * ticketDatetimeAvailability |
|
487 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
488 | + * and tracks the spaces remaining for each of those datetimes |
|
489 | + * |
|
490 | + * @param \EE_Ticket $ticket - selected ticket |
|
491 | + * @param bool $get_original_ticket_spaces |
|
492 | + * @return int |
|
493 | + * @throws \EE_Error |
|
494 | + */ |
|
495 | + private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
496 | + { |
|
497 | + // if the $_available_spaces array has not been set up yet... |
|
498 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
499 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
500 | + } |
|
501 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
502 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
503 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
504 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
505 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
506 | + if ($get_original_ticket_spaces) { |
|
507 | + // then grab the available spaces from the "tickets" array |
|
508 | + // and compare with the above to get the lowest number |
|
509 | + $available_spaces = min( |
|
510 | + $available_spaces, |
|
511 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
512 | + ); |
|
513 | + } else { |
|
514 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
515 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + return $available_spaces; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param \EE_Ticket $ticket |
|
526 | + * @return void |
|
527 | + * @throws \EE_Error |
|
528 | + */ |
|
529 | + private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
530 | + { |
|
531 | + // first, get all of the datetimes that are available to this ticket |
|
532 | + $datetimes = $ticket->get_many_related( |
|
533 | + 'Datetime', |
|
534 | + array( |
|
535 | + array( |
|
536 | + 'DTT_EVT_end' => array( |
|
537 | + '>=', |
|
538 | + \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
539 | + ), |
|
540 | + ), |
|
541 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
542 | + ) |
|
543 | + ); |
|
544 | + if ( ! empty($datetimes)) { |
|
545 | + // now loop thru all of the datetimes |
|
546 | + foreach ($datetimes as $datetime) { |
|
547 | + if ($datetime instanceof \EE_Datetime) { |
|
548 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
549 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
550 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
551 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
552 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
553 | + $ticket->qty() - $ticket->sold(), |
|
554 | + $spaces_remaining |
|
555 | + ); |
|
556 | + // if the remaining spaces for this datetime is already set, |
|
557 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
558 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
559 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
560 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
561 | + ) |
|
562 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
563 | + : $spaces_remaining; |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * @param \EE_Ticket $ticket |
|
573 | + * @param int $qty |
|
574 | + * @return void |
|
575 | + */ |
|
576 | + private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
577 | + { |
|
578 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
579 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
580 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
581 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
582 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
583 | + } |
|
584 | + } |
|
585 | + } |
|
586 | 586 | |
587 | 587 | |
588 | 588 | } |
@@ -24,59 +24,59 @@ |
||
24 | 24 | class CoreLoader implements LoaderDecoratorInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Registry|CoffeeShop $generator |
|
29 | - */ |
|
30 | - private $generator; |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * CoreLoader constructor. |
|
36 | - * |
|
37 | - * @param EE_Registry|CoffeeShop $generator |
|
38 | - * @throws InvalidArgumentException |
|
39 | - */ |
|
40 | - public function __construct($generator) |
|
41 | - { |
|
42 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
43 | - throw new InvalidArgumentException( |
|
44 | - esc_html__( |
|
45 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
46 | - 'event_espresso' |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
50 | - $this->generator = $generator; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $fqcn |
|
57 | - * @param array $arguments |
|
58 | - * @return mixed |
|
59 | - * @throws EE_Error |
|
60 | - * @throws ServiceNotFoundException |
|
61 | - */ |
|
62 | - public function load($fqcn, $arguments = array()) |
|
63 | - { |
|
64 | - return $this->generator instanceof EE_Registry |
|
65 | - ? $this->generator->create($fqcn, $arguments) |
|
66 | - : $this->generator->brew($fqcn, $arguments); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * calls reset() on generator if method exists |
|
73 | - */ |
|
74 | - public function reset() |
|
75 | - { |
|
76 | - if (method_exists($this->generator, 'reset')) { |
|
77 | - $this->generator->reset(); |
|
78 | - } |
|
79 | - } |
|
27 | + /** |
|
28 | + * @var EE_Registry|CoffeeShop $generator |
|
29 | + */ |
|
30 | + private $generator; |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * CoreLoader constructor. |
|
36 | + * |
|
37 | + * @param EE_Registry|CoffeeShop $generator |
|
38 | + * @throws InvalidArgumentException |
|
39 | + */ |
|
40 | + public function __construct($generator) |
|
41 | + { |
|
42 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
43 | + throw new InvalidArgumentException( |
|
44 | + esc_html__( |
|
45 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
46 | + 'event_espresso' |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | + $this->generator = $generator; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $fqcn |
|
57 | + * @param array $arguments |
|
58 | + * @return mixed |
|
59 | + * @throws EE_Error |
|
60 | + * @throws ServiceNotFoundException |
|
61 | + */ |
|
62 | + public function load($fqcn, $arguments = array()) |
|
63 | + { |
|
64 | + return $this->generator instanceof EE_Registry |
|
65 | + ? $this->generator->create($fqcn, $arguments) |
|
66 | + : $this->generator->brew($fqcn, $arguments); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * calls reset() on generator if method exists |
|
73 | + */ |
|
74 | + public function reset() |
|
75 | + { |
|
76 | + if (method_exists($this->generator, 'reset')) { |
|
77 | + $this->generator->reset(); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | // End of file CoreLoader.php |
@@ -22,116 +22,116 @@ |
||
22 | 22 | class CachingLoader extends LoaderDecorator |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $identifier |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * CachingLoader constructor. |
|
39 | - * |
|
40 | - * @param LoaderDecoratorInterface $loader |
|
41 | - * @param CollectionInterface $cache |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | - { |
|
47 | - parent::__construct($loader); |
|
48 | - $this->cache = $cache; |
|
49 | - $this->setIdentifier($identifier); |
|
50 | - if ($this->identifier !== '') { |
|
51 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | - // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | - // where "IDENTIFIER" = the string that was set during construction |
|
54 | - add_action( |
|
55 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | - array($this, 'reset') |
|
57 | - ); |
|
58 | - } |
|
59 | - // to clear ALL caches, simply do the following: |
|
60 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | - add_action( |
|
62 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | - array($this, 'reset') |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function identifier() |
|
73 | - { |
|
74 | - return $this->identifier; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $identifier |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - */ |
|
83 | - private function setIdentifier($identifier) |
|
84 | - { |
|
85 | - if ( ! is_string($identifier)) { |
|
86 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | - } |
|
88 | - $this->identifier = $identifier; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $fqcn |
|
95 | - * @param array $arguments |
|
96 | - * @return mixed |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws ServiceNotFoundException |
|
99 | - */ |
|
100 | - public function load($fqcn, $arguments = array()) |
|
101 | - { |
|
102 | - $fqcn = ltrim($fqcn, '\\'); |
|
103 | - // caching can be turned off via the following code: |
|
104 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | - if( |
|
106 | - apply_filters( |
|
107 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | - false, |
|
109 | - $this |
|
110 | - ) |
|
111 | - ){ |
|
112 | - return $this->loader->load($fqcn, $arguments); |
|
113 | - } |
|
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
116 | - return $this->cache->get($identifier); |
|
117 | - } |
|
118 | - $object = $this->loader->load($fqcn, $arguments); |
|
119 | - if($object instanceof $fqcn) { |
|
120 | - $this->cache->add($object, $identifier); |
|
121 | - } |
|
122 | - return $object; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * empties cache and calls reset() on loader if method exists |
|
129 | - */ |
|
130 | - public function reset() |
|
131 | - { |
|
132 | - $this->cache->detachAll(); |
|
133 | - $this->loader->reset(); |
|
134 | - } |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $identifier |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * CachingLoader constructor. |
|
39 | + * |
|
40 | + * @param LoaderDecoratorInterface $loader |
|
41 | + * @param CollectionInterface $cache |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | + { |
|
47 | + parent::__construct($loader); |
|
48 | + $this->cache = $cache; |
|
49 | + $this->setIdentifier($identifier); |
|
50 | + if ($this->identifier !== '') { |
|
51 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | + // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | + // where "IDENTIFIER" = the string that was set during construction |
|
54 | + add_action( |
|
55 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | + array($this, 'reset') |
|
57 | + ); |
|
58 | + } |
|
59 | + // to clear ALL caches, simply do the following: |
|
60 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | + add_action( |
|
62 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | + array($this, 'reset') |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function identifier() |
|
73 | + { |
|
74 | + return $this->identifier; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $identifier |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + */ |
|
83 | + private function setIdentifier($identifier) |
|
84 | + { |
|
85 | + if ( ! is_string($identifier)) { |
|
86 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | + } |
|
88 | + $this->identifier = $identifier; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $fqcn |
|
95 | + * @param array $arguments |
|
96 | + * @return mixed |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws ServiceNotFoundException |
|
99 | + */ |
|
100 | + public function load($fqcn, $arguments = array()) |
|
101 | + { |
|
102 | + $fqcn = ltrim($fqcn, '\\'); |
|
103 | + // caching can be turned off via the following code: |
|
104 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | + if( |
|
106 | + apply_filters( |
|
107 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | + false, |
|
109 | + $this |
|
110 | + ) |
|
111 | + ){ |
|
112 | + return $this->loader->load($fqcn, $arguments); |
|
113 | + } |
|
114 | + $identifier = md5($fqcn . serialize($arguments)); |
|
115 | + if($this->cache->has($identifier)){ |
|
116 | + return $this->cache->get($identifier); |
|
117 | + } |
|
118 | + $object = $this->loader->load($fqcn, $arguments); |
|
119 | + if($object instanceof $fqcn) { |
|
120 | + $this->cache->add($object, $identifier); |
|
121 | + } |
|
122 | + return $object; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * empties cache and calls reset() on loader if method exists |
|
129 | + */ |
|
130 | + public function reset() |
|
131 | + { |
|
132 | + $this->cache->detachAll(); |
|
133 | + $this->loader->reset(); |
|
134 | + } |
|
135 | 135 | |
136 | 136 | |
137 | 137 | } |
@@ -102,21 +102,21 @@ |
||
102 | 102 | $fqcn = ltrim($fqcn, '\\'); |
103 | 103 | // caching can be turned off via the following code: |
104 | 104 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
105 | - if( |
|
105 | + if ( |
|
106 | 106 | apply_filters( |
107 | 107 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
108 | 108 | false, |
109 | 109 | $this |
110 | 110 | ) |
111 | - ){ |
|
111 | + ) { |
|
112 | 112 | return $this->loader->load($fqcn, $arguments); |
113 | 113 | } |
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
114 | + $identifier = md5($fqcn.serialize($arguments)); |
|
115 | + if ($this->cache->has($identifier)) { |
|
116 | 116 | return $this->cache->get($identifier); |
117 | 117 | } |
118 | 118 | $object = $this->loader->load($fqcn, $arguments); |
119 | - if($object instanceof $fqcn) { |
|
119 | + if ($object instanceof $fqcn) { |
|
120 | 120 | $this->cache->add($object, $identifier); |
121 | 121 | } |
122 | 122 | return $object; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
130 | 130 | { |
131 | 131 | // check if class object is instantiated, and instantiated properly |
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | 133 | self::$_instance = new EE_Dependency_Map($request, $response); |
134 | 134 | } |
135 | 135 | return self::$_instance; |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
184 | 184 | ) { |
185 | 185 | $registered = false; |
186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
186 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
187 | + self::$_instance->_dependency_map[$class] = array(); |
|
188 | 188 | } |
189 | 189 | // we need to make sure that any aliases used when registering a dependency |
190 | 190 | // get resolved to the correct class name |
191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
191 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
192 | 192 | $alias = self::$_instance->get_alias($dependency); |
193 | 193 | if ( |
194 | 194 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
195 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
196 | 196 | ) { |
197 | 197 | unset($dependencies[$dependency]); |
198 | 198 | $dependencies[$alias] = $load_source; |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
206 | 206 | // Union is way faster than array_merge() but should be used with caution... |
207 | 207 | // especially with numerically indexed arrays |
208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
208 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
209 | 209 | // now we need to ensure that the resulting dependencies |
210 | 210 | // array only has the entries that are required for the class |
211 | 211 | // so first count how many dependencies were originally registered for the class |
212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
212 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
213 | 213 | // if that count is non-zero (meaning dependencies were already registered) |
214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
214 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
215 | 215 | // then truncate the final array to match that count |
216 | 216 | ? array_slice($dependencies, 0, $dependency_count) |
217 | 217 | // otherwise just take the incoming array because nothing previously existed |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | ); |
254 | 254 | } |
255 | 255 | $class_name = self::$_instance->get_alias($class_name); |
256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
256 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | 257 | self::$_instance->_class_loaders[$class_name] = $loader; |
258 | 258 | return true; |
259 | 259 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | public function class_loader($class_name) |
327 | 327 | { |
328 | 328 | // don't use loaders for FQCNs |
329 | - if(strpos($class_name, '\\') !== false){ |
|
329 | + if (strpos($class_name, '\\') !== false) { |
|
330 | 330 | return ''; |
331 | 331 | } |
332 | 332 | $class_name = $this->get_alias($class_name); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | public function add_alias($class_name, $alias, $for_class = '') |
356 | 356 | { |
357 | 357 | if ($for_class !== '') { |
358 | - if (! isset($this->_aliases[$for_class])) { |
|
358 | + if ( ! isset($this->_aliases[$for_class])) { |
|
359 | 359 | $this->_aliases[$for_class] = array(); |
360 | 360 | } |
361 | 361 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -401,10 +401,10 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function get_alias($class_name = '', $for_class = '') |
403 | 403 | { |
404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
404 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
405 | 405 | return $class_name; |
406 | 406 | } |
407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
407 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
408 | 408 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
409 | 409 | } |
410 | 410 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -641,10 +641,10 @@ discard block |
||
641 | 641 | 'EE_Front_Controller' => 'load_core', |
642 | 642 | 'EE_Module_Request_Router' => 'load_core', |
643 | 643 | 'EE_Registry' => 'load_core', |
644 | - 'EE_Request' => function () use (&$request) { |
|
644 | + 'EE_Request' => function() use (&$request) { |
|
645 | 645 | return $request; |
646 | 646 | }, |
647 | - 'EE_Response' => function () use (&$response) { |
|
647 | + 'EE_Response' => function() use (&$response) { |
|
648 | 648 | return $response; |
649 | 649 | }, |
650 | 650 | 'EE_Request_Handler' => 'load_core', |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | 'EE_Messages_Queue' => 'load_lib', |
664 | 664 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
665 | 665 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
666 | - 'EE_Messages_Generator' => function () { |
|
666 | + 'EE_Messages_Generator' => function() { |
|
667 | 667 | return EE_Registry::instance()->load_lib( |
668 | 668 | 'Messages_Generator', |
669 | 669 | array(), |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | false |
672 | 672 | ); |
673 | 673 | }, |
674 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
674 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
675 | 675 | return EE_Registry::instance()->load_lib( |
676 | 676 | 'Messages_Template_Defaults', |
677 | 677 | $arguments, |
@@ -683,19 +683,19 @@ discard block |
||
683 | 683 | 'EEM_Message_Template_Group' => 'load_model', |
684 | 684 | 'EEM_Message_Template' => 'load_model', |
685 | 685 | //load_helper |
686 | - 'EEH_Parse_Shortcodes' => function () { |
|
686 | + 'EEH_Parse_Shortcodes' => function() { |
|
687 | 687 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
688 | 688 | return new EEH_Parse_Shortcodes(); |
689 | 689 | } |
690 | 690 | return null; |
691 | 691 | }, |
692 | - 'EE_Template_Config' => function () { |
|
692 | + 'EE_Template_Config' => function() { |
|
693 | 693 | return EE_Config::instance()->template_settings; |
694 | 694 | }, |
695 | - 'EE_Currency_Config' => function () { |
|
695 | + 'EE_Currency_Config' => function() { |
|
696 | 696 | return EE_Config::instance()->currency; |
697 | 697 | }, |
698 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
698 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
699 | 699 | return $loader; |
700 | 700 | }, |
701 | 701 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,740 +21,740 @@ discard block |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @type EE_Dependency_Map $_instance |
|
57 | - */ |
|
58 | - protected static $_instance; |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Request $request |
|
62 | - */ |
|
63 | - protected $_request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @type EE_Response $response |
|
67 | - */ |
|
68 | - protected $_response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type LoaderInterface $loader |
|
72 | - */ |
|
73 | - protected $loader; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type array $_dependency_map |
|
77 | - */ |
|
78 | - protected $_dependency_map = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * @type array $_class_loaders |
|
82 | - */ |
|
83 | - protected $_class_loaders = array(); |
|
84 | - |
|
85 | - /** |
|
86 | - * @type array $_aliases |
|
87 | - */ |
|
88 | - protected $_aliases = array(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * EE_Dependency_Map constructor. |
|
94 | - * |
|
95 | - * @param EE_Request $request |
|
96 | - * @param EE_Response $response |
|
97 | - */ |
|
98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | - { |
|
100 | - $this->_request = $request; |
|
101 | - $this->_response = $response; |
|
102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | - do_action('EE_Dependency_Map____construct'); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws InvalidArgumentException |
|
112 | - */ |
|
113 | - public function initialize() |
|
114 | - { |
|
115 | - $this->_register_core_dependencies(); |
|
116 | - $this->_register_core_class_loaders(); |
|
117 | - $this->_register_core_aliases(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @singleton method used to instantiate class object |
|
124 | - * @access public |
|
125 | - * @param EE_Request $request |
|
126 | - * @param EE_Response $response |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | - { |
|
131 | - // check if class object is instantiated, and instantiated properly |
|
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | - } |
|
135 | - return self::$_instance; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param LoaderInterface $loader |
|
142 | - */ |
|
143 | - public function setLoader(LoaderInterface $loader) |
|
144 | - { |
|
145 | - $this->loader = $loader; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $class |
|
152 | - * @param array $dependencies |
|
153 | - * @param int $overwrite |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public static function register_dependencies( |
|
157 | - $class, |
|
158 | - array $dependencies, |
|
159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | - ) { |
|
161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | - * to the class specified by the first parameter. |
|
169 | - * IMPORTANT !!! |
|
170 | - * The order of elements in the incoming $dependencies array MUST match |
|
171 | - * the order of the constructor parameters for the class in question. |
|
172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | - * |
|
175 | - * @param string $class |
|
176 | - * @param array $dependencies |
|
177 | - * @param int $overwrite |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function registerDependencies( |
|
181 | - $class, |
|
182 | - array $dependencies, |
|
183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | - ) { |
|
185 | - $registered = false; |
|
186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | - } |
|
189 | - // we need to make sure that any aliases used when registering a dependency |
|
190 | - // get resolved to the correct class name |
|
191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | - $alias = self::$_instance->get_alias($dependency); |
|
193 | - if ( |
|
194 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | - ) { |
|
197 | - unset($dependencies[$dependency]); |
|
198 | - $dependencies[$alias] = $load_source; |
|
199 | - $registered = true; |
|
200 | - } |
|
201 | - } |
|
202 | - // now add our two lists of dependencies together. |
|
203 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | - // so $dependencies is NOT overwritten because it is listed first |
|
205 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | - // Union is way faster than array_merge() but should be used with caution... |
|
207 | - // especially with numerically indexed arrays |
|
208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | - // now we need to ensure that the resulting dependencies |
|
210 | - // array only has the entries that are required for the class |
|
211 | - // so first count how many dependencies were originally registered for the class |
|
212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | - // if that count is non-zero (meaning dependencies were already registered) |
|
214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | - // then truncate the final array to match that count |
|
216 | - ? array_slice($dependencies, 0, $dependency_count) |
|
217 | - // otherwise just take the incoming array because nothing previously existed |
|
218 | - : $dependencies; |
|
219 | - return $registered; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $class_name |
|
226 | - * @param string $loader |
|
227 | - * @return bool |
|
228 | - * @throws DomainException |
|
229 | - */ |
|
230 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | - { |
|
232 | - if (strpos($class_name, '\\') !== false) { |
|
233 | - throw new DomainException( |
|
234 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | - ); |
|
236 | - } |
|
237 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | - if ( |
|
239 | - ! is_callable($loader) |
|
240 | - && ( |
|
241 | - strpos($loader, 'load_') !== 0 |
|
242 | - || ! method_exists('EE_Registry', $loader) |
|
243 | - ) |
|
244 | - ) { |
|
245 | - throw new DomainException( |
|
246 | - sprintf( |
|
247 | - esc_html__( |
|
248 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | - 'event_espresso' |
|
250 | - ), |
|
251 | - $loader |
|
252 | - ) |
|
253 | - ); |
|
254 | - } |
|
255 | - $class_name = self::$_instance->get_alias($class_name); |
|
256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | - return true; |
|
259 | - } |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function dependency_map() |
|
269 | - { |
|
270 | - return $this->_dependency_map; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | - * |
|
278 | - * @param string $class_name |
|
279 | - * @return boolean |
|
280 | - */ |
|
281 | - public function has($class_name = '') |
|
282 | - { |
|
283 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | - * |
|
291 | - * @param string $class_name |
|
292 | - * @param string $dependency |
|
293 | - * @return bool |
|
294 | - */ |
|
295 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | - { |
|
297 | - $dependency = $this->get_alias($dependency); |
|
298 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | - ? true |
|
300 | - : false; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @param string $dependency |
|
310 | - * @return int |
|
311 | - */ |
|
312 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | - { |
|
314 | - $dependency = $this->get_alias($dependency); |
|
315 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | - ? $this->_dependency_map[$class_name][$dependency] |
|
317 | - : EE_Dependency_Map::not_registered; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $class_name |
|
324 | - * @return string | Closure |
|
325 | - */ |
|
326 | - public function class_loader($class_name) |
|
327 | - { |
|
328 | - // don't use loaders for FQCNs |
|
329 | - if(strpos($class_name, '\\') !== false){ |
|
330 | - return ''; |
|
331 | - } |
|
332 | - $class_name = $this->get_alias($class_name); |
|
333 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @return array |
|
340 | - */ |
|
341 | - public function class_loaders() |
|
342 | - { |
|
343 | - return $this->_class_loaders; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * adds an alias for a classname |
|
350 | - * |
|
351 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | - */ |
|
355 | - public function add_alias($class_name, $alias, $for_class = '') |
|
356 | - { |
|
357 | - if ($for_class !== '') { |
|
358 | - if (! isset($this->_aliases[$for_class])) { |
|
359 | - $this->_aliases[$for_class] = array(); |
|
360 | - } |
|
361 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | - } |
|
363 | - $this->_aliases[$class_name] = $alias; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * returns TRUE if the provided class name has an alias |
|
370 | - * |
|
371 | - * @param string $class_name |
|
372 | - * @param string $for_class |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function has_alias($class_name = '', $for_class = '') |
|
376 | - { |
|
377 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | - || ( |
|
379 | - isset($this->_aliases[$class_name]) |
|
380 | - && ! is_array($this->_aliases[$class_name]) |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | - * for example: |
|
390 | - * if the following two entries were added to the _aliases array: |
|
391 | - * array( |
|
392 | - * 'interface_alias' => 'some\namespace\interface' |
|
393 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | - * ) |
|
395 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | - * to load an instance of 'some\namespace\classname' |
|
397 | - * |
|
398 | - * @param string $class_name |
|
399 | - * @param string $for_class |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_alias($class_name = '', $for_class = '') |
|
403 | - { |
|
404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
405 | - return $class_name; |
|
406 | - } |
|
407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | - } |
|
410 | - return $this->get_alias($this->_aliases[$class_name]); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | - * This is done by using the following class constants: |
|
419 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | - */ |
|
422 | - protected function _register_core_dependencies() |
|
423 | - { |
|
424 | - $this->_dependency_map = array( |
|
425 | - 'EE_Request_Handler' => array( |
|
426 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EE_System' => array( |
|
429 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
431 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
432 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
433 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
434 | - ), |
|
435 | - 'EE_Session' => array( |
|
436 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
437 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
438 | - ), |
|
439 | - 'EE_Cart' => array( |
|
440 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_Front_Controller' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
446 | - ), |
|
447 | - 'EE_Messenger_Collection_Loader' => array( |
|
448 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | - ), |
|
450 | - 'EE_Message_Type_Collection_Loader' => array( |
|
451 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
452 | - ), |
|
453 | - 'EE_Message_Resource_Manager' => array( |
|
454 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
455 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
456 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
457 | - ), |
|
458 | - 'EE_Message_Factory' => array( |
|
459 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_messages' => array( |
|
462 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_Messages_Generator' => array( |
|
465 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
466 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
468 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messages_Processor' => array( |
|
471 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_Messages_Queue' => array( |
|
474 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Messages_Template_Defaults' => array( |
|
477 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
478 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Message_To_Generate_From_Request' => array( |
|
481 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
485 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
488 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
489 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
490 | - ), |
|
491 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
492 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
495 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
496 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
499 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
502 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
503 | - ), |
|
504 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
505 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
508 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
511 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
514 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
517 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
520 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
523 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
529 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
532 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EE_Data_Migration_Class_Base' => array( |
|
538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EE_DMS_Core_4_1_0' => array( |
|
542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EE_DMS_Core_4_2_0' => array( |
|
546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EE_DMS_Core_4_3_0' => array( |
|
550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EE_DMS_Core_4_4_0' => array( |
|
554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EE_DMS_Core_4_5_0' => array( |
|
558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | - ), |
|
561 | - 'EE_DMS_Core_4_6_0' => array( |
|
562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | - ), |
|
565 | - 'EE_DMS_Core_4_7_0' => array( |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EE_DMS_Core_4_8_0' => array( |
|
570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | - ), |
|
573 | - 'EE_DMS_Core_4_9_0' => array( |
|
574 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | - ), |
|
577 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | - ), |
|
581 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ), |
|
584 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | - ), |
|
593 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ), |
|
596 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
608 | - ), |
|
609 | - ); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * Registers how core classes are loaded. |
|
616 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
617 | - * 'EE_Request_Handler' => 'load_core' |
|
618 | - * 'EE_Messages_Queue' => 'load_lib' |
|
619 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
620 | - * or, if greater control is required, by providing a custom closure. For example: |
|
621 | - * 'Some_Class' => function () { |
|
622 | - * return new Some_Class(); |
|
623 | - * }, |
|
624 | - * This is required for instantiating dependencies |
|
625 | - * where an interface has been type hinted in a class constructor. For example: |
|
626 | - * 'Required_Interface' => function () { |
|
627 | - * return new A_Class_That_Implements_Required_Interface(); |
|
628 | - * }, |
|
629 | - */ |
|
630 | - protected function _register_core_class_loaders() |
|
631 | - { |
|
632 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
633 | - //be used in a closure. |
|
634 | - $request = &$this->_request; |
|
635 | - $response = &$this->_response; |
|
636 | - $loader = &$this->loader; |
|
637 | - $this->_class_loaders = array( |
|
638 | - //load_core |
|
639 | - 'EE_Maintenance_Mode' => 'load_core', |
|
640 | - 'EE_Capabilities' => 'load_core', |
|
641 | - 'EE_Encryption' => 'load_core', |
|
642 | - 'EE_Front_Controller' => 'load_core', |
|
643 | - 'EE_Module_Request_Router' => 'load_core', |
|
644 | - 'EE_Registry' => 'load_core', |
|
645 | - 'EE_Request' => function () use (&$request) { |
|
646 | - return $request; |
|
647 | - }, |
|
648 | - 'EE_Response' => function () use (&$response) { |
|
649 | - return $response; |
|
650 | - }, |
|
651 | - 'EE_Request_Handler' => 'load_core', |
|
652 | - 'EE_Session' => 'load_core', |
|
653 | - 'EE_System' => 'load_core', |
|
654 | - 'EE_Maintenance_Mode' => 'load_core', |
|
655 | - 'EE_Register_CPTs' => 'load_core', |
|
656 | - 'EE_Admin' => 'load_core', |
|
657 | - //load_lib |
|
658 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
659 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
660 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
661 | - 'EE_Messenger_Collection' => 'load_lib', |
|
662 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
663 | - 'EE_Messages_Processor' => 'load_lib', |
|
664 | - 'EE_Message_Repository' => 'load_lib', |
|
665 | - 'EE_Messages_Queue' => 'load_lib', |
|
666 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
667 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
668 | - 'EE_Messages_Generator' => function () { |
|
669 | - return EE_Registry::instance()->load_lib( |
|
670 | - 'Messages_Generator', |
|
671 | - array(), |
|
672 | - false, |
|
673 | - false |
|
674 | - ); |
|
675 | - }, |
|
676 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
677 | - return EE_Registry::instance()->load_lib( |
|
678 | - 'Messages_Template_Defaults', |
|
679 | - $arguments, |
|
680 | - false, |
|
681 | - false |
|
682 | - ); |
|
683 | - }, |
|
684 | - //load_model |
|
685 | - 'EEM_Message_Template_Group' => 'load_model', |
|
686 | - 'EEM_Message_Template' => 'load_model', |
|
687 | - //load_helper |
|
688 | - 'EEH_Parse_Shortcodes' => function () { |
|
689 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
690 | - return new EEH_Parse_Shortcodes(); |
|
691 | - } |
|
692 | - return null; |
|
693 | - }, |
|
694 | - 'EE_Template_Config' => function () { |
|
695 | - return EE_Config::instance()->template_settings; |
|
696 | - }, |
|
697 | - 'EE_Currency_Config' => function () { |
|
698 | - return EE_Config::instance()->currency; |
|
699 | - }, |
|
700 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
701 | - return $loader; |
|
702 | - }, |
|
703 | - ); |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * can be used for supplying alternate names for classes, |
|
710 | - * or for connecting interface names to instantiable classes |
|
711 | - */ |
|
712 | - protected function _register_core_aliases() |
|
713 | - { |
|
714 | - $this->_aliases = array( |
|
715 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
716 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
717 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
718 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
719 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
720 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
721 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
722 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
723 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
724 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
725 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
726 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
727 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
728 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
729 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
730 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
731 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
732 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
733 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
734 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
735 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
736 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
737 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
738 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
739 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
740 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
741 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
742 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
743 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
744 | - ); |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
751 | - * request Primarily used by unit tests. |
|
752 | - */ |
|
753 | - public function reset() |
|
754 | - { |
|
755 | - $this->_register_core_class_loaders(); |
|
756 | - $this->_register_core_dependencies(); |
|
757 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @type EE_Dependency_Map $_instance |
|
57 | + */ |
|
58 | + protected static $_instance; |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Request $request |
|
62 | + */ |
|
63 | + protected $_request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @type EE_Response $response |
|
67 | + */ |
|
68 | + protected $_response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type LoaderInterface $loader |
|
72 | + */ |
|
73 | + protected $loader; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type array $_dependency_map |
|
77 | + */ |
|
78 | + protected $_dependency_map = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * @type array $_class_loaders |
|
82 | + */ |
|
83 | + protected $_class_loaders = array(); |
|
84 | + |
|
85 | + /** |
|
86 | + * @type array $_aliases |
|
87 | + */ |
|
88 | + protected $_aliases = array(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * EE_Dependency_Map constructor. |
|
94 | + * |
|
95 | + * @param EE_Request $request |
|
96 | + * @param EE_Response $response |
|
97 | + */ |
|
98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | + { |
|
100 | + $this->_request = $request; |
|
101 | + $this->_response = $response; |
|
102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | + do_action('EE_Dependency_Map____construct'); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws InvalidArgumentException |
|
112 | + */ |
|
113 | + public function initialize() |
|
114 | + { |
|
115 | + $this->_register_core_dependencies(); |
|
116 | + $this->_register_core_class_loaders(); |
|
117 | + $this->_register_core_aliases(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @singleton method used to instantiate class object |
|
124 | + * @access public |
|
125 | + * @param EE_Request $request |
|
126 | + * @param EE_Response $response |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | + { |
|
131 | + // check if class object is instantiated, and instantiated properly |
|
132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | + } |
|
135 | + return self::$_instance; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param LoaderInterface $loader |
|
142 | + */ |
|
143 | + public function setLoader(LoaderInterface $loader) |
|
144 | + { |
|
145 | + $this->loader = $loader; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $class |
|
152 | + * @param array $dependencies |
|
153 | + * @param int $overwrite |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public static function register_dependencies( |
|
157 | + $class, |
|
158 | + array $dependencies, |
|
159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | + ) { |
|
161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | + * to the class specified by the first parameter. |
|
169 | + * IMPORTANT !!! |
|
170 | + * The order of elements in the incoming $dependencies array MUST match |
|
171 | + * the order of the constructor parameters for the class in question. |
|
172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | + * |
|
175 | + * @param string $class |
|
176 | + * @param array $dependencies |
|
177 | + * @param int $overwrite |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function registerDependencies( |
|
181 | + $class, |
|
182 | + array $dependencies, |
|
183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | + ) { |
|
185 | + $registered = false; |
|
186 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
187 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | + } |
|
189 | + // we need to make sure that any aliases used when registering a dependency |
|
190 | + // get resolved to the correct class name |
|
191 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | + $alias = self::$_instance->get_alias($dependency); |
|
193 | + if ( |
|
194 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
195 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | + ) { |
|
197 | + unset($dependencies[$dependency]); |
|
198 | + $dependencies[$alias] = $load_source; |
|
199 | + $registered = true; |
|
200 | + } |
|
201 | + } |
|
202 | + // now add our two lists of dependencies together. |
|
203 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
204 | + // so $dependencies is NOT overwritten because it is listed first |
|
205 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
206 | + // Union is way faster than array_merge() but should be used with caution... |
|
207 | + // especially with numerically indexed arrays |
|
208 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | + // now we need to ensure that the resulting dependencies |
|
210 | + // array only has the entries that are required for the class |
|
211 | + // so first count how many dependencies were originally registered for the class |
|
212 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | + // if that count is non-zero (meaning dependencies were already registered) |
|
214 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | + // then truncate the final array to match that count |
|
216 | + ? array_slice($dependencies, 0, $dependency_count) |
|
217 | + // otherwise just take the incoming array because nothing previously existed |
|
218 | + : $dependencies; |
|
219 | + return $registered; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $class_name |
|
226 | + * @param string $loader |
|
227 | + * @return bool |
|
228 | + * @throws DomainException |
|
229 | + */ |
|
230 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
231 | + { |
|
232 | + if (strpos($class_name, '\\') !== false) { |
|
233 | + throw new DomainException( |
|
234 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
235 | + ); |
|
236 | + } |
|
237 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
238 | + if ( |
|
239 | + ! is_callable($loader) |
|
240 | + && ( |
|
241 | + strpos($loader, 'load_') !== 0 |
|
242 | + || ! method_exists('EE_Registry', $loader) |
|
243 | + ) |
|
244 | + ) { |
|
245 | + throw new DomainException( |
|
246 | + sprintf( |
|
247 | + esc_html__( |
|
248 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
249 | + 'event_espresso' |
|
250 | + ), |
|
251 | + $loader |
|
252 | + ) |
|
253 | + ); |
|
254 | + } |
|
255 | + $class_name = self::$_instance->get_alias($class_name); |
|
256 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
258 | + return true; |
|
259 | + } |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function dependency_map() |
|
269 | + { |
|
270 | + return $this->_dependency_map; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
277 | + * |
|
278 | + * @param string $class_name |
|
279 | + * @return boolean |
|
280 | + */ |
|
281 | + public function has($class_name = '') |
|
282 | + { |
|
283 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
290 | + * |
|
291 | + * @param string $class_name |
|
292 | + * @param string $dependency |
|
293 | + * @return bool |
|
294 | + */ |
|
295 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
296 | + { |
|
297 | + $dependency = $this->get_alias($dependency); |
|
298 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
299 | + ? true |
|
300 | + : false; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @param string $dependency |
|
310 | + * @return int |
|
311 | + */ |
|
312 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
313 | + { |
|
314 | + $dependency = $this->get_alias($dependency); |
|
315 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
316 | + ? $this->_dependency_map[$class_name][$dependency] |
|
317 | + : EE_Dependency_Map::not_registered; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @param string $class_name |
|
324 | + * @return string | Closure |
|
325 | + */ |
|
326 | + public function class_loader($class_name) |
|
327 | + { |
|
328 | + // don't use loaders for FQCNs |
|
329 | + if(strpos($class_name, '\\') !== false){ |
|
330 | + return ''; |
|
331 | + } |
|
332 | + $class_name = $this->get_alias($class_name); |
|
333 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @return array |
|
340 | + */ |
|
341 | + public function class_loaders() |
|
342 | + { |
|
343 | + return $this->_class_loaders; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * adds an alias for a classname |
|
350 | + * |
|
351 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
352 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
353 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
354 | + */ |
|
355 | + public function add_alias($class_name, $alias, $for_class = '') |
|
356 | + { |
|
357 | + if ($for_class !== '') { |
|
358 | + if (! isset($this->_aliases[$for_class])) { |
|
359 | + $this->_aliases[$for_class] = array(); |
|
360 | + } |
|
361 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
362 | + } |
|
363 | + $this->_aliases[$class_name] = $alias; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * returns TRUE if the provided class name has an alias |
|
370 | + * |
|
371 | + * @param string $class_name |
|
372 | + * @param string $for_class |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function has_alias($class_name = '', $for_class = '') |
|
376 | + { |
|
377 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
378 | + || ( |
|
379 | + isset($this->_aliases[$class_name]) |
|
380 | + && ! is_array($this->_aliases[$class_name]) |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
388 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
389 | + * for example: |
|
390 | + * if the following two entries were added to the _aliases array: |
|
391 | + * array( |
|
392 | + * 'interface_alias' => 'some\namespace\interface' |
|
393 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
394 | + * ) |
|
395 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
396 | + * to load an instance of 'some\namespace\classname' |
|
397 | + * |
|
398 | + * @param string $class_name |
|
399 | + * @param string $for_class |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_alias($class_name = '', $for_class = '') |
|
403 | + { |
|
404 | + if (! $this->has_alias($class_name, $for_class)) { |
|
405 | + return $class_name; |
|
406 | + } |
|
407 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
409 | + } |
|
410 | + return $this->get_alias($this->_aliases[$class_name]); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
417 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
418 | + * This is done by using the following class constants: |
|
419 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
420 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
421 | + */ |
|
422 | + protected function _register_core_dependencies() |
|
423 | + { |
|
424 | + $this->_dependency_map = array( |
|
425 | + 'EE_Request_Handler' => array( |
|
426 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EE_System' => array( |
|
429 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
430 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
431 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
432 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
433 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
434 | + ), |
|
435 | + 'EE_Session' => array( |
|
436 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
437 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
438 | + ), |
|
439 | + 'EE_Cart' => array( |
|
440 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_Front_Controller' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
446 | + ), |
|
447 | + 'EE_Messenger_Collection_Loader' => array( |
|
448 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | + ), |
|
450 | + 'EE_Message_Type_Collection_Loader' => array( |
|
451 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
452 | + ), |
|
453 | + 'EE_Message_Resource_Manager' => array( |
|
454 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
455 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
456 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
457 | + ), |
|
458 | + 'EE_Message_Factory' => array( |
|
459 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_messages' => array( |
|
462 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_Messages_Generator' => array( |
|
465 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
466 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
467 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
468 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messages_Processor' => array( |
|
471 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_Messages_Queue' => array( |
|
474 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Messages_Template_Defaults' => array( |
|
477 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
478 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Message_To_Generate_From_Request' => array( |
|
481 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
485 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
488 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
489 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
490 | + ), |
|
491 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
492 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
495 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
496 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
499 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
502 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
503 | + ), |
|
504 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
505 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
508 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
511 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
514 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
517 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
520 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
523 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
529 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
532 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EE_Data_Migration_Class_Base' => array( |
|
538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EE_DMS_Core_4_1_0' => array( |
|
542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EE_DMS_Core_4_2_0' => array( |
|
546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EE_DMS_Core_4_3_0' => array( |
|
550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EE_DMS_Core_4_4_0' => array( |
|
554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EE_DMS_Core_4_5_0' => array( |
|
558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | + ), |
|
561 | + 'EE_DMS_Core_4_6_0' => array( |
|
562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | + ), |
|
565 | + 'EE_DMS_Core_4_7_0' => array( |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EE_DMS_Core_4_8_0' => array( |
|
570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | + ), |
|
573 | + 'EE_DMS_Core_4_9_0' => array( |
|
574 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | + ), |
|
577 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | + ), |
|
581 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ), |
|
584 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | + ), |
|
593 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ), |
|
596 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
608 | + ), |
|
609 | + ); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * Registers how core classes are loaded. |
|
616 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
617 | + * 'EE_Request_Handler' => 'load_core' |
|
618 | + * 'EE_Messages_Queue' => 'load_lib' |
|
619 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
620 | + * or, if greater control is required, by providing a custom closure. For example: |
|
621 | + * 'Some_Class' => function () { |
|
622 | + * return new Some_Class(); |
|
623 | + * }, |
|
624 | + * This is required for instantiating dependencies |
|
625 | + * where an interface has been type hinted in a class constructor. For example: |
|
626 | + * 'Required_Interface' => function () { |
|
627 | + * return new A_Class_That_Implements_Required_Interface(); |
|
628 | + * }, |
|
629 | + */ |
|
630 | + protected function _register_core_class_loaders() |
|
631 | + { |
|
632 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
633 | + //be used in a closure. |
|
634 | + $request = &$this->_request; |
|
635 | + $response = &$this->_response; |
|
636 | + $loader = &$this->loader; |
|
637 | + $this->_class_loaders = array( |
|
638 | + //load_core |
|
639 | + 'EE_Maintenance_Mode' => 'load_core', |
|
640 | + 'EE_Capabilities' => 'load_core', |
|
641 | + 'EE_Encryption' => 'load_core', |
|
642 | + 'EE_Front_Controller' => 'load_core', |
|
643 | + 'EE_Module_Request_Router' => 'load_core', |
|
644 | + 'EE_Registry' => 'load_core', |
|
645 | + 'EE_Request' => function () use (&$request) { |
|
646 | + return $request; |
|
647 | + }, |
|
648 | + 'EE_Response' => function () use (&$response) { |
|
649 | + return $response; |
|
650 | + }, |
|
651 | + 'EE_Request_Handler' => 'load_core', |
|
652 | + 'EE_Session' => 'load_core', |
|
653 | + 'EE_System' => 'load_core', |
|
654 | + 'EE_Maintenance_Mode' => 'load_core', |
|
655 | + 'EE_Register_CPTs' => 'load_core', |
|
656 | + 'EE_Admin' => 'load_core', |
|
657 | + //load_lib |
|
658 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
659 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
660 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
661 | + 'EE_Messenger_Collection' => 'load_lib', |
|
662 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
663 | + 'EE_Messages_Processor' => 'load_lib', |
|
664 | + 'EE_Message_Repository' => 'load_lib', |
|
665 | + 'EE_Messages_Queue' => 'load_lib', |
|
666 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
667 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
668 | + 'EE_Messages_Generator' => function () { |
|
669 | + return EE_Registry::instance()->load_lib( |
|
670 | + 'Messages_Generator', |
|
671 | + array(), |
|
672 | + false, |
|
673 | + false |
|
674 | + ); |
|
675 | + }, |
|
676 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
677 | + return EE_Registry::instance()->load_lib( |
|
678 | + 'Messages_Template_Defaults', |
|
679 | + $arguments, |
|
680 | + false, |
|
681 | + false |
|
682 | + ); |
|
683 | + }, |
|
684 | + //load_model |
|
685 | + 'EEM_Message_Template_Group' => 'load_model', |
|
686 | + 'EEM_Message_Template' => 'load_model', |
|
687 | + //load_helper |
|
688 | + 'EEH_Parse_Shortcodes' => function () { |
|
689 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
690 | + return new EEH_Parse_Shortcodes(); |
|
691 | + } |
|
692 | + return null; |
|
693 | + }, |
|
694 | + 'EE_Template_Config' => function () { |
|
695 | + return EE_Config::instance()->template_settings; |
|
696 | + }, |
|
697 | + 'EE_Currency_Config' => function () { |
|
698 | + return EE_Config::instance()->currency; |
|
699 | + }, |
|
700 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
701 | + return $loader; |
|
702 | + }, |
|
703 | + ); |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * can be used for supplying alternate names for classes, |
|
710 | + * or for connecting interface names to instantiable classes |
|
711 | + */ |
|
712 | + protected function _register_core_aliases() |
|
713 | + { |
|
714 | + $this->_aliases = array( |
|
715 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
716 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
717 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
718 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
719 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
720 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
721 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
722 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
723 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
724 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
725 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
726 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
727 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
728 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
729 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
730 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
731 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
732 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
733 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
734 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
735 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
736 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
737 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
738 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
739 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
740 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
741 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
742 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
743 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
744 | + ); |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
751 | + * request Primarily used by unit tests. |
|
752 | + */ |
|
753 | + public function reset() |
|
754 | + { |
|
755 | + $this->_register_core_class_loaders(); |
|
756 | + $this->_register_core_dependencies(); |
|
757 | + } |
|
758 | 758 | |
759 | 759 | |
760 | 760 | } |
@@ -34,139 +34,139 @@ |
||
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * the actual shortcode tag that gets registered with WordPress |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getTag() |
|
43 | - { |
|
44 | - return 'ESPRESSO_EVENTS'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * the time in seconds to cache the results of the processShortcode() method |
|
51 | - * 0 means the processShortcode() results will NOT be cached at all |
|
52 | - * |
|
53 | - * @return int |
|
54 | - */ |
|
55 | - public function cacheExpiration() |
|
56 | - { |
|
57 | - return 0; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | - * this may be required for shortcodes that utilize a corresponding module, |
|
65 | - * and need to enqueue assets for that module |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function initializeShortcode() |
|
70 | - { |
|
71 | - EED_Events_Archive::instance()->event_list(); |
|
72 | - $this->shortcodeHasBeenInitialized(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * callback that runs when the shortcode is encountered in post content. |
|
79 | - * IMPORTANT !!! |
|
80 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | - * |
|
82 | - * @param array $attributes |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function processShortcode($attributes = array()) |
|
86 | - { |
|
87 | - // grab attributes and merge with defaults |
|
88 | - $attributes = $this->getAttributes($attributes); |
|
89 | - // make sure we use the_excerpt() |
|
90 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | - // apply query filters |
|
92 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | - // run the query |
|
94 | - global $wp_query; |
|
95 | - // yes we have to overwrite the main wp query, but it's ok... |
|
96 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | - $wp_query = new EventListQuery($attributes); |
|
98 | - // check what template is loaded and load filters accordingly |
|
99 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | - // load our template |
|
101 | - $event_list = EEH_Template::locate_template( |
|
102 | - 'loop-espresso_events.php', |
|
103 | - array(), |
|
104 | - true, |
|
105 | - true |
|
106 | - ); |
|
107 | - // now reset the query and post data |
|
108 | - wp_reset_query(); |
|
109 | - wp_reset_postdata(); |
|
110 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | - // remove query filters |
|
112 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | - // pull our content from the output buffer and return it |
|
114 | - return $event_list; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * merge incoming attributes with filtered defaults |
|
121 | - * |
|
122 | - * @param array $attributes |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - private function getAttributes(array $attributes) |
|
126 | - { |
|
127 | - return array_merge( |
|
128 | - (array)apply_filters( |
|
129 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | - array( |
|
131 | - 'title' => '', |
|
132 | - 'limit' => 10, |
|
133 | - 'css_class' => '', |
|
134 | - 'show_expired' => false, |
|
135 | - 'month' => '', |
|
136 | - 'category_slug' => '', |
|
137 | - 'order_by' => 'start_date', |
|
138 | - 'sort' => 'ASC', |
|
139 | - 'show_title' => true, |
|
140 | - ) |
|
141 | - ), |
|
142 | - $attributes |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * array for defining custom attribute sanitization callbacks, |
|
150 | - * where keys match keys in your attributes array, |
|
151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | - * So for example, if you had an integer attribute named "event_id" |
|
153 | - * that you wanted to be sanitized using absint(), |
|
154 | - * then you would pass the following for your $custom_sanitization array: |
|
155 | - * array('event_id' => 'absint') |
|
156 | - * |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - protected function customAttributeSanitizationMap() |
|
160 | - { |
|
161 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | - return array( |
|
163 | - 'category_slug' => 'skip_sanitization', |
|
164 | - 'show_expired' => 'skip_sanitization', |
|
165 | - 'order_by' => 'skip_sanitization', |
|
166 | - 'month' => 'skip_sanitization', |
|
167 | - 'sort' => 'skip_sanitization', |
|
168 | - ); |
|
169 | - } |
|
37 | + /** |
|
38 | + * the actual shortcode tag that gets registered with WordPress |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getTag() |
|
43 | + { |
|
44 | + return 'ESPRESSO_EVENTS'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * the time in seconds to cache the results of the processShortcode() method |
|
51 | + * 0 means the processShortcode() results will NOT be cached at all |
|
52 | + * |
|
53 | + * @return int |
|
54 | + */ |
|
55 | + public function cacheExpiration() |
|
56 | + { |
|
57 | + return 0; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
64 | + * this may be required for shortcodes that utilize a corresponding module, |
|
65 | + * and need to enqueue assets for that module |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function initializeShortcode() |
|
70 | + { |
|
71 | + EED_Events_Archive::instance()->event_list(); |
|
72 | + $this->shortcodeHasBeenInitialized(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * callback that runs when the shortcode is encountered in post content. |
|
79 | + * IMPORTANT !!! |
|
80 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
81 | + * |
|
82 | + * @param array $attributes |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function processShortcode($attributes = array()) |
|
86 | + { |
|
87 | + // grab attributes and merge with defaults |
|
88 | + $attributes = $this->getAttributes($attributes); |
|
89 | + // make sure we use the_excerpt() |
|
90 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
91 | + // apply query filters |
|
92 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
93 | + // run the query |
|
94 | + global $wp_query; |
|
95 | + // yes we have to overwrite the main wp query, but it's ok... |
|
96 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
97 | + $wp_query = new EventListQuery($attributes); |
|
98 | + // check what template is loaded and load filters accordingly |
|
99 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
100 | + // load our template |
|
101 | + $event_list = EEH_Template::locate_template( |
|
102 | + 'loop-espresso_events.php', |
|
103 | + array(), |
|
104 | + true, |
|
105 | + true |
|
106 | + ); |
|
107 | + // now reset the query and post data |
|
108 | + wp_reset_query(); |
|
109 | + wp_reset_postdata(); |
|
110 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
111 | + // remove query filters |
|
112 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
113 | + // pull our content from the output buffer and return it |
|
114 | + return $event_list; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * merge incoming attributes with filtered defaults |
|
121 | + * |
|
122 | + * @param array $attributes |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + private function getAttributes(array $attributes) |
|
126 | + { |
|
127 | + return array_merge( |
|
128 | + (array)apply_filters( |
|
129 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
130 | + array( |
|
131 | + 'title' => '', |
|
132 | + 'limit' => 10, |
|
133 | + 'css_class' => '', |
|
134 | + 'show_expired' => false, |
|
135 | + 'month' => '', |
|
136 | + 'category_slug' => '', |
|
137 | + 'order_by' => 'start_date', |
|
138 | + 'sort' => 'ASC', |
|
139 | + 'show_title' => true, |
|
140 | + ) |
|
141 | + ), |
|
142 | + $attributes |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * array for defining custom attribute sanitization callbacks, |
|
150 | + * where keys match keys in your attributes array, |
|
151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | + * So for example, if you had an integer attribute named "event_id" |
|
153 | + * that you wanted to be sanitized using absint(), |
|
154 | + * then you would pass the following for your $custom_sanitization array: |
|
155 | + * array('event_id' => 'absint') |
|
156 | + * |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + protected function customAttributeSanitizationMap() |
|
160 | + { |
|
161 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
162 | + return array( |
|
163 | + 'category_slug' => 'skip_sanitization', |
|
164 | + 'show_expired' => 'skip_sanitization', |
|
165 | + 'order_by' => 'skip_sanitization', |
|
166 | + 'month' => 'skip_sanitization', |
|
167 | + 'sort' => 'skip_sanitization', |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | 172 |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
16 | 16 | $I->ensurePluginActive( |
17 | - 'event-espresso-mer-multi-event-registration', |
|
18 | - 'activated' |
|
17 | + 'event-espresso-mer-multi-event-registration', |
|
18 | + 'activated' |
|
19 | 19 | ); |
20 | 20 | |
21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -76,38 +76,38 @@ discard block |
||
76 | 76 | $I->loginAsAdmin(); |
77 | 77 | $I->amOnMessagesActivityListTablePage(); |
78 | 78 | $I->see( |
79 | - '[email protected]', |
|
80 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
81 | - 'to', |
|
82 | - 'Registration Multi-status Summary', |
|
83 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
84 | - '', |
|
85 | - 'Primary Registrant' |
|
86 | - ) |
|
79 | + '[email protected]', |
|
80 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
81 | + 'to', |
|
82 | + 'Registration Multi-status Summary', |
|
83 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
84 | + '', |
|
85 | + 'Primary Registrant' |
|
86 | + ) |
|
87 | 87 | ); |
88 | 88 | $I->see( |
89 | - '[email protected]', |
|
90 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
91 | - 'to', |
|
92 | - 'Registration Multi-status Summary', |
|
93 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
94 | - ) |
|
89 | + '[email protected]', |
|
90 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
91 | + 'to', |
|
92 | + 'Registration Multi-status Summary', |
|
93 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
94 | + ) |
|
95 | 95 | ); |
96 | 96 | //verify count |
97 | 97 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
98 | - 1, |
|
99 | - '[email protected]', |
|
100 | - 'to', |
|
101 | - 'Registration Multi-status Summary', |
|
102 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
103 | - 'Email', |
|
104 | - 'Primary Registrant' |
|
98 | + 1, |
|
99 | + '[email protected]', |
|
100 | + 'to', |
|
101 | + 'Registration Multi-status Summary', |
|
102 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
103 | + 'Email', |
|
104 | + 'Primary Registrant' |
|
105 | 105 | ); |
106 | 106 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
107 | - 1, |
|
108 | - '[email protected]', |
|
109 | - 'to', |
|
110 | - 'Registration Multi-status Summary' |
|
107 | + 1, |
|
108 | + '[email protected]', |
|
109 | + 'to', |
|
110 | + 'Registration Multi-status Summary' |
|
111 | 111 | ); |
112 | 112 | |
113 | 113 | //okay now let's do some registrations for just the first event and verify that registration multi-status summary is NOT |
@@ -137,25 +137,25 @@ discard block |
||
137 | 137 | $I->loginAsAdmin(); |
138 | 138 | $I->amOnMessagesActivityListTablePage(); |
139 | 139 | $I->dontSee( |
140 | - '[email protected]', |
|
141 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
142 | - 'to', |
|
143 | - 'Registration Multi-status Summary', |
|
144 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
145 | - '', |
|
146 | - 'Primary Registrant' |
|
147 | - ) |
|
140 | + '[email protected]', |
|
141 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
142 | + 'to', |
|
143 | + 'Registration Multi-status Summary', |
|
144 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
145 | + '', |
|
146 | + 'Primary Registrant' |
|
147 | + ) |
|
148 | 148 | ); |
149 | 149 | //there should still only be one admin multi-status summary thing. |
150 | 150 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
151 | - 1, |
|
152 | - '[email protected]', |
|
153 | - 'to', |
|
154 | - 'Registration Multi-status Summary' |
|
151 | + 1, |
|
152 | + '[email protected]', |
|
153 | + 'to', |
|
154 | + 'Registration Multi-status Summary' |
|
155 | 155 | ); |
156 | 156 | |
157 | 157 | //deactivate MER plugin so its not active for future tests |
158 | 158 | $I->ensurePluginDeactivated( |
159 | - 'event-espresso-mer-multi-event-registration', |
|
160 | - 'Plugin deactivated' |
|
159 | + 'event-espresso-mer-multi-event-registration', |
|
160 | + 'Plugin deactivated' |
|
161 | 161 | ); |
162 | 162 | \ No newline at end of file |
@@ -13,1086 +13,1086 @@ |
||
13 | 13 | class EED_Messages extends EED_Module |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * This holds the EE_messages controller |
|
18 | - * |
|
19 | - * @deprecated 4.9.0 |
|
20 | - * @var EE_messages $_EEMSG |
|
21 | - */ |
|
22 | - protected static $_EEMSG; |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | - */ |
|
27 | - protected static $_message_resource_manager; |
|
28 | - |
|
29 | - /** |
|
30 | - * This holds the EE_Messages_Processor business class. |
|
31 | - * |
|
32 | - * @type EE_Messages_Processor |
|
33 | - */ |
|
34 | - protected static $_MSG_PROCESSOR; |
|
35 | - |
|
36 | - /** |
|
37 | - * holds all the paths for various messages components. |
|
38 | - * Utilized by autoloader registry |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $_MSG_PATHS; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | - * Format is: |
|
48 | - * array( |
|
49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | - * ) |
|
51 | - * |
|
52 | - * @var EE_Messages_Template_Pack[] |
|
53 | - */ |
|
54 | - protected static $_TMP_PACKS = array(); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @return EED_Messages |
|
59 | - */ |
|
60 | - public static function instance() |
|
61 | - { |
|
62 | - return parent::get_instance(__CLASS__); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks() |
|
73 | - { |
|
74 | - //actions |
|
75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | - //filters |
|
79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | - //register routes |
|
84 | - self::_register_routes(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public static function set_hooks_admin() |
|
94 | - { |
|
95 | - //actions |
|
96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | - //filters |
|
108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * All the message triggers done by route go in here. |
|
119 | - * |
|
120 | - * @since 4.5.0 |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected static function _register_routes() |
|
124 | - { |
|
125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This is called when a browser display trigger is executed. |
|
135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | - * browser. |
|
137 | - * |
|
138 | - * @since 4.9.0 |
|
139 | - * @param WP $WP |
|
140 | - */ |
|
141 | - public function browser_trigger($WP) |
|
142 | - { |
|
143 | - //ensure controller is loaded |
|
144 | - self::_load_controller(); |
|
145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | - try { |
|
147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | - } catch (EE_Error $e) { |
|
150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | - 'event_espresso'); |
|
152 | - // add specific message for developers if WP_DEBUG in on |
|
153 | - $error_msg .= '||' . $e->getMessage(); |
|
154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * This is called when a browser error trigger is executed. |
|
161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | - * message and display it. |
|
163 | - * |
|
164 | - * @since 4.9.0 |
|
165 | - * @param $WP |
|
166 | - */ |
|
167 | - public function browser_error_trigger($WP) |
|
168 | - { |
|
169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | - if ($token) { |
|
171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | - if ($message instanceof EE_Message) { |
|
173 | - header('HTTP/1.1 200 OK'); |
|
174 | - $error_msg = nl2br($message->error_message()); |
|
175 | - ?> |
|
16 | + /** |
|
17 | + * This holds the EE_messages controller |
|
18 | + * |
|
19 | + * @deprecated 4.9.0 |
|
20 | + * @var EE_messages $_EEMSG |
|
21 | + */ |
|
22 | + protected static $_EEMSG; |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | + */ |
|
27 | + protected static $_message_resource_manager; |
|
28 | + |
|
29 | + /** |
|
30 | + * This holds the EE_Messages_Processor business class. |
|
31 | + * |
|
32 | + * @type EE_Messages_Processor |
|
33 | + */ |
|
34 | + protected static $_MSG_PROCESSOR; |
|
35 | + |
|
36 | + /** |
|
37 | + * holds all the paths for various messages components. |
|
38 | + * Utilized by autoloader registry |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $_MSG_PATHS; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | + * Format is: |
|
48 | + * array( |
|
49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | + * ) |
|
51 | + * |
|
52 | + * @var EE_Messages_Template_Pack[] |
|
53 | + */ |
|
54 | + protected static $_TMP_PACKS = array(); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @return EED_Messages |
|
59 | + */ |
|
60 | + public static function instance() |
|
61 | + { |
|
62 | + return parent::get_instance(__CLASS__); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks() |
|
73 | + { |
|
74 | + //actions |
|
75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | + //filters |
|
79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | + //register routes |
|
84 | + self::_register_routes(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public static function set_hooks_admin() |
|
94 | + { |
|
95 | + //actions |
|
96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | + //filters |
|
108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * All the message triggers done by route go in here. |
|
119 | + * |
|
120 | + * @since 4.5.0 |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected static function _register_routes() |
|
124 | + { |
|
125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This is called when a browser display trigger is executed. |
|
135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | + * browser. |
|
137 | + * |
|
138 | + * @since 4.9.0 |
|
139 | + * @param WP $WP |
|
140 | + */ |
|
141 | + public function browser_trigger($WP) |
|
142 | + { |
|
143 | + //ensure controller is loaded |
|
144 | + self::_load_controller(); |
|
145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | + try { |
|
147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | + } catch (EE_Error $e) { |
|
150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | + 'event_espresso'); |
|
152 | + // add specific message for developers if WP_DEBUG in on |
|
153 | + $error_msg .= '||' . $e->getMessage(); |
|
154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * This is called when a browser error trigger is executed. |
|
161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | + * message and display it. |
|
163 | + * |
|
164 | + * @since 4.9.0 |
|
165 | + * @param $WP |
|
166 | + */ |
|
167 | + public function browser_error_trigger($WP) |
|
168 | + { |
|
169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | + if ($token) { |
|
171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | + if ($message instanceof EE_Message) { |
|
173 | + header('HTTP/1.1 200 OK'); |
|
174 | + $error_msg = nl2br($message->error_message()); |
|
175 | + ?> |
|
176 | 176 | <!DOCTYPE html> |
177 | 177 | <html> |
178 | 178 | <head></head> |
179 | 179 | <body> |
180 | 180 | <?php echo empty($error_msg) |
181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | - 'event_espresso') |
|
183 | - : wp_kses( |
|
184 | - $error_msg, |
|
185 | - array( |
|
186 | - 'a' => array( |
|
187 | - 'href' => array(), |
|
188 | - 'title' => array(), |
|
189 | - ), |
|
190 | - 'span' => array(), |
|
191 | - 'div' => array(), |
|
192 | - 'p' => array(), |
|
193 | - 'strong' => array(), |
|
194 | - 'em' => array(), |
|
195 | - 'br' => array(), |
|
196 | - ) |
|
197 | - ); ?> |
|
181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | + 'event_espresso') |
|
183 | + : wp_kses( |
|
184 | + $error_msg, |
|
185 | + array( |
|
186 | + 'a' => array( |
|
187 | + 'href' => array(), |
|
188 | + 'title' => array(), |
|
189 | + ), |
|
190 | + 'span' => array(), |
|
191 | + 'div' => array(), |
|
192 | + 'p' => array(), |
|
193 | + 'strong' => array(), |
|
194 | + 'em' => array(), |
|
195 | + 'br' => array(), |
|
196 | + ) |
|
197 | + ); ?> |
|
198 | 198 | </body> |
199 | 199 | </html> |
200 | 200 | <?php |
201 | - exit; |
|
202 | - } |
|
203 | - } |
|
204 | - return; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * This runs when the msg_url_trigger route has initiated. |
|
210 | - * |
|
211 | - * @since 4.5.0 |
|
212 | - * @param WP $WP |
|
213 | - * @throws EE_Error |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function run($WP) |
|
217 | - { |
|
218 | - //ensure controller is loaded |
|
219 | - self::_load_controller(); |
|
220 | - // attempt to process message |
|
221 | - try { |
|
222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | - } catch (EE_Error $e) { |
|
226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | - 'event_espresso'); |
|
228 | - // add specific message for developers if WP_DEBUG in on |
|
229 | - $error_msg .= '||' . $e->getMessage(); |
|
230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
237 | - * |
|
238 | - * @param WP $WP |
|
239 | - */ |
|
240 | - public function execute_batch_request($WP) |
|
241 | - { |
|
242 | - $this->run_cron(); |
|
243 | - header('HTTP/1.1 200 OK'); |
|
244 | - exit(); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | - * request. |
|
251 | - */ |
|
252 | - public function run_cron() |
|
253 | - { |
|
254 | - self::_load_controller(); |
|
255 | - //get required vars |
|
256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | - |
|
259 | - //now let's verify transient, if not valid exit immediately |
|
260 | - if (! get_transient($transient_key)) { |
|
261 | - /** |
|
262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | - */ |
|
264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | - } |
|
266 | - |
|
267 | - //if made it here, lets' delete the transient to keep the db clean |
|
268 | - delete_transient($transient_key); |
|
269 | - |
|
270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | - |
|
272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | - self::$_MSG_PROCESSOR->$method(); |
|
275 | - } else { |
|
276 | - //no matching task |
|
277 | - /** |
|
278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | - */ |
|
280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | - $cron_type))); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * This is used to retrieve the template pack for the given name. |
|
291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | - * the default template pack is returned. |
|
293 | - * |
|
294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | - * in generating the Pack class name). |
|
297 | - * @return EE_Messages_Template_Pack |
|
298 | - */ |
|
299 | - public static function get_template_pack($template_pack_name) |
|
300 | - { |
|
301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Retrieves an array of all template packs. |
|
308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | - * |
|
310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | - * @return EE_Messages_Template_Pack[] |
|
312 | - */ |
|
313 | - public static function get_template_packs() |
|
314 | - { |
|
315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | - |
|
317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | - $template_pack_collection->rewind(); |
|
320 | - $template_packs = array(); |
|
321 | - while ($template_pack_collection->valid()) { |
|
322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | - $template_pack_collection->next(); |
|
324 | - } |
|
325 | - return $template_packs; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | - * |
|
332 | - * @since 4.5.0 |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public static function set_autoloaders() |
|
336 | - { |
|
337 | - if (empty(self::$_MSG_PATHS)) { |
|
338 | - self::_set_messages_paths(); |
|
339 | - foreach (self::$_MSG_PATHS as $path) { |
|
340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | - } |
|
342 | - // add aliases |
|
343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | - * for use by the Messages Autoloaders |
|
352 | - * |
|
353 | - * @since 4.5.0 |
|
354 | - * @return void. |
|
355 | - */ |
|
356 | - protected static function _set_messages_paths() |
|
357 | - { |
|
358 | - $dir_ref = array( |
|
359 | - 'messages/message_type', |
|
360 | - 'messages/messenger', |
|
361 | - 'messages/defaults', |
|
362 | - 'messages/defaults/email', |
|
363 | - 'messages/data_class', |
|
364 | - 'messages/validators', |
|
365 | - 'messages/validators/email', |
|
366 | - 'messages/validators/html', |
|
367 | - 'shortcodes', |
|
368 | - ); |
|
369 | - $paths = array(); |
|
370 | - foreach ($dir_ref as $index => $dir) { |
|
371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | - } |
|
373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Takes care of loading dependencies |
|
379 | - * |
|
380 | - * @since 4.5.0 |
|
381 | - * @return void |
|
382 | - */ |
|
383 | - protected static function _load_controller() |
|
384 | - { |
|
385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | - self::set_autoloaders(); |
|
388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @param EE_Transaction $transaction |
|
397 | - */ |
|
398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
399 | - { |
|
400 | - self::_load_controller(); |
|
401 | - $data = array($transaction, null); |
|
402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
408 | - * |
|
409 | - * @param EE_Transaction object |
|
410 | - * @param EE_Payment object |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | - { |
|
415 | - self::_load_controller(); |
|
416 | - $data = array($transaction, $payment); |
|
417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @param EE_Transaction $transaction |
|
427 | - */ |
|
428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | - { |
|
430 | - self::_load_controller(); |
|
431 | - $data = array($transaction, null); |
|
432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Trigger for Registration messages |
|
438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | - * incoming transaction. |
|
440 | - * |
|
441 | - * @param EE_Registration $registration |
|
442 | - * @param array $extra_details |
|
443 | - * @return void |
|
444 | - */ |
|
445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | - { |
|
447 | - |
|
448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | - //no messages please |
|
450 | - return; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - //get all registrations so we make sure we send messages for the right status. |
|
455 | - $all_registrations = $registration->transaction()->registrations(); |
|
456 | - |
|
457 | - //cached array of statuses so we only trigger messages once per status. |
|
458 | - $statuses_sent = array(); |
|
459 | - self::_load_controller(); |
|
460 | - $mtgs = array(); |
|
461 | - |
|
462 | - //loop through registrations and trigger messages once per status. |
|
463 | - foreach ($all_registrations as $reg) { |
|
464 | - |
|
465 | - //already triggered? |
|
466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | - continue; |
|
468 | - } |
|
469 | - |
|
470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | - $mtgs = array_merge( |
|
472 | - $mtgs, |
|
473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | - $message_type, |
|
475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
476 | - ) |
|
477 | - ); |
|
478 | - $statuses_sent[] = $reg->status_ID(); |
|
479 | - } |
|
480 | - |
|
481 | - if (count($statuses_sent) > 1) { |
|
482 | - $mtgs = array_merge( |
|
483 | - $mtgs, |
|
484 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
485 | - 'registration_summary', |
|
486 | - array($registration->transaction(), null) |
|
487 | - ) |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - //batch queue and initiate request |
|
492 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
493 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * This is a helper method used to very whether a registration notification should be sent or |
|
499 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
500 | - * |
|
501 | - * @param EE_Registration $registration [description] |
|
502 | - * @param array $extra_details [description] |
|
503 | - * @return bool true = send away, false = nope halt the presses. |
|
504 | - */ |
|
505 | - protected static function _verify_registration_notification_send( |
|
506 | - EE_Registration $registration, |
|
507 | - $extra_details = array() |
|
508 | - ) { |
|
509 | - //self::log( |
|
510 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
511 | - // $registration->transaction(), |
|
512 | - // array( '$extra_details' => $extra_details ) |
|
513 | - //); |
|
514 | - // currently only using this to send messages for the primary registrant |
|
515 | - if (! $registration->is_primary_registrant()) { |
|
516 | - return false; |
|
517 | - } |
|
518 | - // first we check if we're in admin and not doing front ajax |
|
519 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
520 | - //make sure appropriate admin params are set for sending messages |
|
521 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
522 | - //no messages sent please. |
|
523 | - return false; |
|
524 | - } |
|
525 | - } else { |
|
526 | - // frontend request (either regular or via AJAX) |
|
527 | - // TXN is NOT finalized ? |
|
528 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
529 | - return false; |
|
530 | - } |
|
531 | - // return visit but nothing changed ??? |
|
532 | - if ( |
|
533 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
534 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
535 | - ) { |
|
536 | - return false; |
|
537 | - } |
|
538 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
539 | - if ( |
|
540 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
541 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
542 | - ) { |
|
543 | - return false; |
|
544 | - } |
|
545 | - } |
|
546 | - // release the kraken |
|
547 | - return true; |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
553 | - * status id. |
|
554 | - * |
|
555 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
556 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
557 | - * @param string $reg_status |
|
558 | - * @return array |
|
559 | - */ |
|
560 | - protected static function _get_reg_status_array($reg_status = '') |
|
561 | - { |
|
562 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
563 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
564 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
565 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * Simply returns the payment message type for the given payment status. |
|
571 | - * |
|
572 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
573 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
574 | - * @param string $payment_status The payment status being matched. |
|
575 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
576 | - */ |
|
577 | - protected static function _get_payment_message_type($payment_status) |
|
578 | - { |
|
579 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
580 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
581 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
582 | - : false; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
588 | - * |
|
589 | - * @access public |
|
590 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
591 | - * @return bool success/fail |
|
592 | - */ |
|
593 | - public static function process_resend($req_data) |
|
594 | - { |
|
595 | - self::_load_controller(); |
|
596 | - |
|
597 | - //if $msgID in this request then skip to the new resend_message |
|
598 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
599 | - return self::resend_message(); |
|
600 | - } |
|
601 | - |
|
602 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
603 | - $req_data = (array)$req_data; |
|
604 | - foreach ($req_data as $request_key => $request_value) { |
|
605 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
606 | - } |
|
607 | - |
|
608 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
609 | - return false; |
|
610 | - } |
|
611 | - |
|
612 | - try { |
|
613 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
614 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
615 | - } catch (EE_Error $e) { |
|
616 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
617 | - return false; |
|
618 | - } |
|
619 | - EE_Error::add_success( |
|
620 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
621 | - ); |
|
622 | - return true; //everything got queued. |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
628 | - * |
|
629 | - * @return bool |
|
630 | - */ |
|
631 | - public static function resend_message() |
|
632 | - { |
|
633 | - self::_load_controller(); |
|
634 | - |
|
635 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
636 | - if (! $msgID) { |
|
637 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
638 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
643 | - |
|
644 | - //setup success message. |
|
645 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
646 | - EE_Error::add_success(sprintf( |
|
647 | - _n( |
|
648 | - 'There was %d message queued for resending.', |
|
649 | - 'There were %d messages queued for resending.', |
|
650 | - $count_ready_for_resend, |
|
651 | - 'event_espresso' |
|
652 | - ), |
|
653 | - $count_ready_for_resend |
|
654 | - )); |
|
655 | - return true; |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Message triggers for manual payment applied by admin |
|
661 | - * |
|
662 | - * @param EE_Payment $payment EE_payment object |
|
663 | - * @return bool success/fail |
|
664 | - */ |
|
665 | - public static function process_admin_payment(EE_Payment $payment) |
|
666 | - { |
|
667 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
668 | - //we need to get the transaction object |
|
669 | - $transaction = $payment->transaction(); |
|
670 | - if ($transaction instanceof EE_Transaction) { |
|
671 | - $data = array($transaction, $payment); |
|
672 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
673 | - |
|
674 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
675 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
676 | - |
|
677 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
678 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
679 | - |
|
680 | - self::_load_controller(); |
|
681 | - |
|
682 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
683 | - |
|
684 | - //get count of queued for generation |
|
685 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
686 | - EEM_Message::status_incomplete, |
|
687 | - EEM_Message::status_idle, |
|
688 | - )); |
|
689 | - |
|
690 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
691 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
692 | - return true; |
|
693 | - } else { |
|
694 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
695 | - /** |
|
696 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
697 | - * IMMEDIATE generation. |
|
698 | - */ |
|
699 | - if ($count_failed > 0) { |
|
700 | - EE_Error::add_error(sprintf( |
|
701 | - _n( |
|
702 | - 'The payment notification generation failed.', |
|
703 | - '%d payment notifications failed being sent.', |
|
704 | - $count_failed, |
|
705 | - 'event_espresso' |
|
706 | - ), |
|
707 | - $count_failed |
|
708 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
709 | - |
|
710 | - return false; |
|
711 | - } else { |
|
712 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
713 | - return true; |
|
714 | - } |
|
715 | - } |
|
716 | - } else { |
|
717 | - EE_Error::add_error( |
|
718 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
719 | - 'event_espresso' |
|
720 | - ); |
|
721 | - return false; |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
728 | - * |
|
729 | - * @since 4.3.0 |
|
730 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
731 | - * @param int $grp_id a specific message template group id. |
|
732 | - * @return void |
|
733 | - */ |
|
734 | - public static function send_newsletter_message($registrations, $grp_id) |
|
735 | - { |
|
736 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
737 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
738 | - self::_load_controller(); |
|
739 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
745 | - * |
|
746 | - * @since 4.3.0 |
|
747 | - * @param string $registration_message_trigger_url |
|
748 | - * @param EE_Registration $registration |
|
749 | - * @param string $messenger |
|
750 | - * @param string $message_type |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - public static function registration_message_trigger_url( |
|
754 | - $registration_message_trigger_url, |
|
755 | - EE_Registration $registration, |
|
756 | - $messenger = 'html', |
|
757 | - $message_type = 'invoice' |
|
758 | - ) { |
|
759 | - // whitelist $messenger |
|
760 | - switch ($messenger) { |
|
761 | - case 'pdf' : |
|
762 | - $sending_messenger = 'pdf'; |
|
763 | - $generating_messenger = 'html'; |
|
764 | - break; |
|
765 | - case 'html' : |
|
766 | - default : |
|
767 | - $sending_messenger = 'html'; |
|
768 | - $generating_messenger = 'html'; |
|
769 | - break; |
|
770 | - } |
|
771 | - // whitelist $message_type |
|
772 | - switch ($message_type) { |
|
773 | - case 'receipt' : |
|
774 | - $message_type = 'receipt'; |
|
775 | - break; |
|
776 | - case 'invoice' : |
|
777 | - default : |
|
778 | - $message_type = 'invoice'; |
|
779 | - break; |
|
780 | - } |
|
781 | - // verify that both the messenger AND the message type are active |
|
782 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
783 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
784 | - $template_query_params = array( |
|
785 | - 'MTP_is_active' => true, |
|
786 | - 'MTP_messenger' => $generating_messenger, |
|
787 | - 'MTP_message_type' => $message_type, |
|
788 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
789 | - ); |
|
790 | - //get the message template group. |
|
791 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
792 | - //if we don't have an EE_Message_Template_Group then return |
|
793 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
794 | - // remove EVT_ID from query params so that global templates get picked up |
|
795 | - unset($template_query_params['Event.EVT_ID']); |
|
796 | - //get global template as the fallback |
|
797 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
798 | - } |
|
799 | - //if we don't have an EE_Message_Template_Group then return |
|
800 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
801 | - return ''; |
|
802 | - } |
|
803 | - // generate the URL |
|
804 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
805 | - $sending_messenger, |
|
806 | - $generating_messenger, |
|
807 | - 'purchaser', |
|
808 | - $message_type, |
|
809 | - $registration, |
|
810 | - $msg_template_group->ID(), |
|
811 | - $registration->transaction_ID() |
|
812 | - ); |
|
813 | - |
|
814 | - } |
|
815 | - return $registration_message_trigger_url; |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - /** |
|
820 | - * Use to generate and return a message preview! |
|
821 | - * |
|
822 | - * @param string $type This should correspond with a valid message type |
|
823 | - * @param string $context This should correspond with a valid context for the message type |
|
824 | - * @param string $messenger This should correspond with a valid messenger. |
|
825 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
826 | - * preview |
|
827 | - * @return string|bool The body of the message or if send is requested, sends. |
|
828 | - */ |
|
829 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
830 | - { |
|
831 | - self::_load_controller(); |
|
832 | - $mtg = new EE_Message_To_Generate( |
|
833 | - $messenger, |
|
834 | - $type, |
|
835 | - array(), |
|
836 | - $context, |
|
837 | - true |
|
838 | - ); |
|
839 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
840 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
841 | - return $generated_preview_queue->get_message_repository()->current()->content(); |
|
842 | - } else { |
|
843 | - return $generated_preview_queue; |
|
844 | - } |
|
845 | - } |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
850 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
851 | - * content found in the EE_Message objects in the queue. |
|
852 | - * |
|
853 | - * @since 4.9.0 |
|
854 | - * @param string $messenger a string matching a valid active messenger in the system |
|
855 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
856 | - * type name is still required to send along the message type to the |
|
857 | - * messenger because this is used for determining what specific |
|
858 | - * variations might be loaded for the generated message. |
|
859 | - * @param EE_Messages_Queue $queue |
|
860 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
861 | - * aggregate EE_Message object. |
|
862 | - * @return bool success or fail. |
|
863 | - */ |
|
864 | - public static function send_message_with_messenger_only( |
|
865 | - $messenger, |
|
866 | - $message_type, |
|
867 | - EE_Messages_Queue $queue, |
|
868 | - $custom_subject = '' |
|
869 | - ) { |
|
870 | - self::_load_controller(); |
|
871 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
872 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
873 | - 'Message_To_Generate_From_Queue', |
|
874 | - array( |
|
875 | - $messenger, |
|
876 | - $message_type, |
|
877 | - $queue, |
|
878 | - $custom_subject, |
|
879 | - ) |
|
880 | - ); |
|
881 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
887 | - * |
|
888 | - * @since 4.9.0 |
|
889 | - * @param array $message_ids An array of message ids |
|
890 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
891 | - * messages. |
|
892 | - */ |
|
893 | - public static function generate_now($message_ids) |
|
894 | - { |
|
895 | - self::_load_controller(); |
|
896 | - $messages = EEM_Message::instance()->get_all( |
|
897 | - array( |
|
898 | - 0 => array( |
|
899 | - 'MSG_ID' => array('IN', $message_ids), |
|
900 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
901 | - ), |
|
902 | - ) |
|
903 | - ); |
|
904 | - $generated_queue = false; |
|
905 | - if ($messages) { |
|
906 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
907 | - } |
|
908 | - |
|
909 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
910 | - EE_Error::add_error( |
|
911 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
912 | - 'event_espresso'), |
|
913 | - __FILE__, __FUNCTION__, __LINE__ |
|
914 | - ); |
|
915 | - } |
|
916 | - return $generated_queue; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
922 | - * EEM_Message::status_idle |
|
923 | - * |
|
924 | - * @since 4.9.0 |
|
925 | - * @param $message_ids |
|
926 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
927 | - */ |
|
928 | - public static function send_now($message_ids) |
|
929 | - { |
|
930 | - self::_load_controller(); |
|
931 | - $messages = EEM_Message::instance()->get_all( |
|
932 | - array( |
|
933 | - 0 => array( |
|
934 | - 'MSG_ID' => array('IN', $message_ids), |
|
935 | - 'STS_ID' => array( |
|
936 | - 'IN', |
|
937 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
938 | - ), |
|
939 | - ), |
|
940 | - ) |
|
941 | - ); |
|
942 | - $sent_queue = false; |
|
943 | - if ($messages) { |
|
944 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
945 | - } |
|
946 | - |
|
947 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
948 | - EE_Error::add_error( |
|
949 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
950 | - 'event_espresso'), |
|
951 | - __FILE__, __FUNCTION__, __LINE__ |
|
952 | - ); |
|
953 | - } else { |
|
954 | - //can count how many sent by using the messages in the queue |
|
955 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
956 | - if ($sent_count > 0) { |
|
957 | - EE_Error::add_success( |
|
958 | - sprintf( |
|
959 | - _n( |
|
960 | - 'There was %d message successfully sent.', |
|
961 | - 'There were %d messages successfully sent.', |
|
962 | - $sent_count, |
|
963 | - 'event_espresso' |
|
964 | - ), |
|
965 | - $sent_count |
|
966 | - ) |
|
967 | - ); |
|
968 | - } else { |
|
969 | - EE_Error::overwrite_errors(); |
|
970 | - EE_Error::add_error( |
|
971 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
201 | + exit; |
|
202 | + } |
|
203 | + } |
|
204 | + return; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * This runs when the msg_url_trigger route has initiated. |
|
210 | + * |
|
211 | + * @since 4.5.0 |
|
212 | + * @param WP $WP |
|
213 | + * @throws EE_Error |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function run($WP) |
|
217 | + { |
|
218 | + //ensure controller is loaded |
|
219 | + self::_load_controller(); |
|
220 | + // attempt to process message |
|
221 | + try { |
|
222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | + } catch (EE_Error $e) { |
|
226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | + 'event_espresso'); |
|
228 | + // add specific message for developers if WP_DEBUG in on |
|
229 | + $error_msg .= '||' . $e->getMessage(); |
|
230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
237 | + * |
|
238 | + * @param WP $WP |
|
239 | + */ |
|
240 | + public function execute_batch_request($WP) |
|
241 | + { |
|
242 | + $this->run_cron(); |
|
243 | + header('HTTP/1.1 200 OK'); |
|
244 | + exit(); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | + * request. |
|
251 | + */ |
|
252 | + public function run_cron() |
|
253 | + { |
|
254 | + self::_load_controller(); |
|
255 | + //get required vars |
|
256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | + |
|
259 | + //now let's verify transient, if not valid exit immediately |
|
260 | + if (! get_transient($transient_key)) { |
|
261 | + /** |
|
262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | + */ |
|
264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | + } |
|
266 | + |
|
267 | + //if made it here, lets' delete the transient to keep the db clean |
|
268 | + delete_transient($transient_key); |
|
269 | + |
|
270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | + |
|
272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | + self::$_MSG_PROCESSOR->$method(); |
|
275 | + } else { |
|
276 | + //no matching task |
|
277 | + /** |
|
278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | + */ |
|
280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | + $cron_type))); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * This is used to retrieve the template pack for the given name. |
|
291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | + * the default template pack is returned. |
|
293 | + * |
|
294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | + * in generating the Pack class name). |
|
297 | + * @return EE_Messages_Template_Pack |
|
298 | + */ |
|
299 | + public static function get_template_pack($template_pack_name) |
|
300 | + { |
|
301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Retrieves an array of all template packs. |
|
308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | + * |
|
310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | + * @return EE_Messages_Template_Pack[] |
|
312 | + */ |
|
313 | + public static function get_template_packs() |
|
314 | + { |
|
315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | + |
|
317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | + $template_pack_collection->rewind(); |
|
320 | + $template_packs = array(); |
|
321 | + while ($template_pack_collection->valid()) { |
|
322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | + $template_pack_collection->next(); |
|
324 | + } |
|
325 | + return $template_packs; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | + * |
|
332 | + * @since 4.5.0 |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public static function set_autoloaders() |
|
336 | + { |
|
337 | + if (empty(self::$_MSG_PATHS)) { |
|
338 | + self::_set_messages_paths(); |
|
339 | + foreach (self::$_MSG_PATHS as $path) { |
|
340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | + } |
|
342 | + // add aliases |
|
343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | + * for use by the Messages Autoloaders |
|
352 | + * |
|
353 | + * @since 4.5.0 |
|
354 | + * @return void. |
|
355 | + */ |
|
356 | + protected static function _set_messages_paths() |
|
357 | + { |
|
358 | + $dir_ref = array( |
|
359 | + 'messages/message_type', |
|
360 | + 'messages/messenger', |
|
361 | + 'messages/defaults', |
|
362 | + 'messages/defaults/email', |
|
363 | + 'messages/data_class', |
|
364 | + 'messages/validators', |
|
365 | + 'messages/validators/email', |
|
366 | + 'messages/validators/html', |
|
367 | + 'shortcodes', |
|
368 | + ); |
|
369 | + $paths = array(); |
|
370 | + foreach ($dir_ref as $index => $dir) { |
|
371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | + } |
|
373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Takes care of loading dependencies |
|
379 | + * |
|
380 | + * @since 4.5.0 |
|
381 | + * @return void |
|
382 | + */ |
|
383 | + protected static function _load_controller() |
|
384 | + { |
|
385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | + self::set_autoloaders(); |
|
388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @param EE_Transaction $transaction |
|
397 | + */ |
|
398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
399 | + { |
|
400 | + self::_load_controller(); |
|
401 | + $data = array($transaction, null); |
|
402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
408 | + * |
|
409 | + * @param EE_Transaction object |
|
410 | + * @param EE_Payment object |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | + { |
|
415 | + self::_load_controller(); |
|
416 | + $data = array($transaction, $payment); |
|
417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @param EE_Transaction $transaction |
|
427 | + */ |
|
428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | + { |
|
430 | + self::_load_controller(); |
|
431 | + $data = array($transaction, null); |
|
432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Trigger for Registration messages |
|
438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | + * incoming transaction. |
|
440 | + * |
|
441 | + * @param EE_Registration $registration |
|
442 | + * @param array $extra_details |
|
443 | + * @return void |
|
444 | + */ |
|
445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | + { |
|
447 | + |
|
448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | + //no messages please |
|
450 | + return; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + //get all registrations so we make sure we send messages for the right status. |
|
455 | + $all_registrations = $registration->transaction()->registrations(); |
|
456 | + |
|
457 | + //cached array of statuses so we only trigger messages once per status. |
|
458 | + $statuses_sent = array(); |
|
459 | + self::_load_controller(); |
|
460 | + $mtgs = array(); |
|
461 | + |
|
462 | + //loop through registrations and trigger messages once per status. |
|
463 | + foreach ($all_registrations as $reg) { |
|
464 | + |
|
465 | + //already triggered? |
|
466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | + continue; |
|
468 | + } |
|
469 | + |
|
470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | + $mtgs = array_merge( |
|
472 | + $mtgs, |
|
473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | + $message_type, |
|
475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
476 | + ) |
|
477 | + ); |
|
478 | + $statuses_sent[] = $reg->status_ID(); |
|
479 | + } |
|
480 | + |
|
481 | + if (count($statuses_sent) > 1) { |
|
482 | + $mtgs = array_merge( |
|
483 | + $mtgs, |
|
484 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
485 | + 'registration_summary', |
|
486 | + array($registration->transaction(), null) |
|
487 | + ) |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + //batch queue and initiate request |
|
492 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
493 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * This is a helper method used to very whether a registration notification should be sent or |
|
499 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
500 | + * |
|
501 | + * @param EE_Registration $registration [description] |
|
502 | + * @param array $extra_details [description] |
|
503 | + * @return bool true = send away, false = nope halt the presses. |
|
504 | + */ |
|
505 | + protected static function _verify_registration_notification_send( |
|
506 | + EE_Registration $registration, |
|
507 | + $extra_details = array() |
|
508 | + ) { |
|
509 | + //self::log( |
|
510 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
511 | + // $registration->transaction(), |
|
512 | + // array( '$extra_details' => $extra_details ) |
|
513 | + //); |
|
514 | + // currently only using this to send messages for the primary registrant |
|
515 | + if (! $registration->is_primary_registrant()) { |
|
516 | + return false; |
|
517 | + } |
|
518 | + // first we check if we're in admin and not doing front ajax |
|
519 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
520 | + //make sure appropriate admin params are set for sending messages |
|
521 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
522 | + //no messages sent please. |
|
523 | + return false; |
|
524 | + } |
|
525 | + } else { |
|
526 | + // frontend request (either regular or via AJAX) |
|
527 | + // TXN is NOT finalized ? |
|
528 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
529 | + return false; |
|
530 | + } |
|
531 | + // return visit but nothing changed ??? |
|
532 | + if ( |
|
533 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
534 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
535 | + ) { |
|
536 | + return false; |
|
537 | + } |
|
538 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
539 | + if ( |
|
540 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
541 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
542 | + ) { |
|
543 | + return false; |
|
544 | + } |
|
545 | + } |
|
546 | + // release the kraken |
|
547 | + return true; |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
553 | + * status id. |
|
554 | + * |
|
555 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
556 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
557 | + * @param string $reg_status |
|
558 | + * @return array |
|
559 | + */ |
|
560 | + protected static function _get_reg_status_array($reg_status = '') |
|
561 | + { |
|
562 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
563 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
564 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
565 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * Simply returns the payment message type for the given payment status. |
|
571 | + * |
|
572 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
573 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
574 | + * @param string $payment_status The payment status being matched. |
|
575 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
576 | + */ |
|
577 | + protected static function _get_payment_message_type($payment_status) |
|
578 | + { |
|
579 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
580 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
581 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
582 | + : false; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
588 | + * |
|
589 | + * @access public |
|
590 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
591 | + * @return bool success/fail |
|
592 | + */ |
|
593 | + public static function process_resend($req_data) |
|
594 | + { |
|
595 | + self::_load_controller(); |
|
596 | + |
|
597 | + //if $msgID in this request then skip to the new resend_message |
|
598 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
599 | + return self::resend_message(); |
|
600 | + } |
|
601 | + |
|
602 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
603 | + $req_data = (array)$req_data; |
|
604 | + foreach ($req_data as $request_key => $request_value) { |
|
605 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
606 | + } |
|
607 | + |
|
608 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
609 | + return false; |
|
610 | + } |
|
611 | + |
|
612 | + try { |
|
613 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
614 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
615 | + } catch (EE_Error $e) { |
|
616 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
617 | + return false; |
|
618 | + } |
|
619 | + EE_Error::add_success( |
|
620 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
621 | + ); |
|
622 | + return true; //everything got queued. |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
628 | + * |
|
629 | + * @return bool |
|
630 | + */ |
|
631 | + public static function resend_message() |
|
632 | + { |
|
633 | + self::_load_controller(); |
|
634 | + |
|
635 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
636 | + if (! $msgID) { |
|
637 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
638 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
643 | + |
|
644 | + //setup success message. |
|
645 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
646 | + EE_Error::add_success(sprintf( |
|
647 | + _n( |
|
648 | + 'There was %d message queued for resending.', |
|
649 | + 'There were %d messages queued for resending.', |
|
650 | + $count_ready_for_resend, |
|
651 | + 'event_espresso' |
|
652 | + ), |
|
653 | + $count_ready_for_resend |
|
654 | + )); |
|
655 | + return true; |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Message triggers for manual payment applied by admin |
|
661 | + * |
|
662 | + * @param EE_Payment $payment EE_payment object |
|
663 | + * @return bool success/fail |
|
664 | + */ |
|
665 | + public static function process_admin_payment(EE_Payment $payment) |
|
666 | + { |
|
667 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
668 | + //we need to get the transaction object |
|
669 | + $transaction = $payment->transaction(); |
|
670 | + if ($transaction instanceof EE_Transaction) { |
|
671 | + $data = array($transaction, $payment); |
|
672 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
673 | + |
|
674 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
675 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
676 | + |
|
677 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
678 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
679 | + |
|
680 | + self::_load_controller(); |
|
681 | + |
|
682 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
683 | + |
|
684 | + //get count of queued for generation |
|
685 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
686 | + EEM_Message::status_incomplete, |
|
687 | + EEM_Message::status_idle, |
|
688 | + )); |
|
689 | + |
|
690 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
691 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
692 | + return true; |
|
693 | + } else { |
|
694 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
695 | + /** |
|
696 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
697 | + * IMMEDIATE generation. |
|
698 | + */ |
|
699 | + if ($count_failed > 0) { |
|
700 | + EE_Error::add_error(sprintf( |
|
701 | + _n( |
|
702 | + 'The payment notification generation failed.', |
|
703 | + '%d payment notifications failed being sent.', |
|
704 | + $count_failed, |
|
705 | + 'event_espresso' |
|
706 | + ), |
|
707 | + $count_failed |
|
708 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
709 | + |
|
710 | + return false; |
|
711 | + } else { |
|
712 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
713 | + return true; |
|
714 | + } |
|
715 | + } |
|
716 | + } else { |
|
717 | + EE_Error::add_error( |
|
718 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
719 | + 'event_espresso' |
|
720 | + ); |
|
721 | + return false; |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
728 | + * |
|
729 | + * @since 4.3.0 |
|
730 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
731 | + * @param int $grp_id a specific message template group id. |
|
732 | + * @return void |
|
733 | + */ |
|
734 | + public static function send_newsletter_message($registrations, $grp_id) |
|
735 | + { |
|
736 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
737 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
738 | + self::_load_controller(); |
|
739 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
745 | + * |
|
746 | + * @since 4.3.0 |
|
747 | + * @param string $registration_message_trigger_url |
|
748 | + * @param EE_Registration $registration |
|
749 | + * @param string $messenger |
|
750 | + * @param string $message_type |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + public static function registration_message_trigger_url( |
|
754 | + $registration_message_trigger_url, |
|
755 | + EE_Registration $registration, |
|
756 | + $messenger = 'html', |
|
757 | + $message_type = 'invoice' |
|
758 | + ) { |
|
759 | + // whitelist $messenger |
|
760 | + switch ($messenger) { |
|
761 | + case 'pdf' : |
|
762 | + $sending_messenger = 'pdf'; |
|
763 | + $generating_messenger = 'html'; |
|
764 | + break; |
|
765 | + case 'html' : |
|
766 | + default : |
|
767 | + $sending_messenger = 'html'; |
|
768 | + $generating_messenger = 'html'; |
|
769 | + break; |
|
770 | + } |
|
771 | + // whitelist $message_type |
|
772 | + switch ($message_type) { |
|
773 | + case 'receipt' : |
|
774 | + $message_type = 'receipt'; |
|
775 | + break; |
|
776 | + case 'invoice' : |
|
777 | + default : |
|
778 | + $message_type = 'invoice'; |
|
779 | + break; |
|
780 | + } |
|
781 | + // verify that both the messenger AND the message type are active |
|
782 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
783 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
784 | + $template_query_params = array( |
|
785 | + 'MTP_is_active' => true, |
|
786 | + 'MTP_messenger' => $generating_messenger, |
|
787 | + 'MTP_message_type' => $message_type, |
|
788 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
789 | + ); |
|
790 | + //get the message template group. |
|
791 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
792 | + //if we don't have an EE_Message_Template_Group then return |
|
793 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
794 | + // remove EVT_ID from query params so that global templates get picked up |
|
795 | + unset($template_query_params['Event.EVT_ID']); |
|
796 | + //get global template as the fallback |
|
797 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
798 | + } |
|
799 | + //if we don't have an EE_Message_Template_Group then return |
|
800 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
801 | + return ''; |
|
802 | + } |
|
803 | + // generate the URL |
|
804 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
805 | + $sending_messenger, |
|
806 | + $generating_messenger, |
|
807 | + 'purchaser', |
|
808 | + $message_type, |
|
809 | + $registration, |
|
810 | + $msg_template_group->ID(), |
|
811 | + $registration->transaction_ID() |
|
812 | + ); |
|
813 | + |
|
814 | + } |
|
815 | + return $registration_message_trigger_url; |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + /** |
|
820 | + * Use to generate and return a message preview! |
|
821 | + * |
|
822 | + * @param string $type This should correspond with a valid message type |
|
823 | + * @param string $context This should correspond with a valid context for the message type |
|
824 | + * @param string $messenger This should correspond with a valid messenger. |
|
825 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
826 | + * preview |
|
827 | + * @return string|bool The body of the message or if send is requested, sends. |
|
828 | + */ |
|
829 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
830 | + { |
|
831 | + self::_load_controller(); |
|
832 | + $mtg = new EE_Message_To_Generate( |
|
833 | + $messenger, |
|
834 | + $type, |
|
835 | + array(), |
|
836 | + $context, |
|
837 | + true |
|
838 | + ); |
|
839 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
840 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
841 | + return $generated_preview_queue->get_message_repository()->current()->content(); |
|
842 | + } else { |
|
843 | + return $generated_preview_queue; |
|
844 | + } |
|
845 | + } |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
850 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
851 | + * content found in the EE_Message objects in the queue. |
|
852 | + * |
|
853 | + * @since 4.9.0 |
|
854 | + * @param string $messenger a string matching a valid active messenger in the system |
|
855 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
856 | + * type name is still required to send along the message type to the |
|
857 | + * messenger because this is used for determining what specific |
|
858 | + * variations might be loaded for the generated message. |
|
859 | + * @param EE_Messages_Queue $queue |
|
860 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
861 | + * aggregate EE_Message object. |
|
862 | + * @return bool success or fail. |
|
863 | + */ |
|
864 | + public static function send_message_with_messenger_only( |
|
865 | + $messenger, |
|
866 | + $message_type, |
|
867 | + EE_Messages_Queue $queue, |
|
868 | + $custom_subject = '' |
|
869 | + ) { |
|
870 | + self::_load_controller(); |
|
871 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
872 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
873 | + 'Message_To_Generate_From_Queue', |
|
874 | + array( |
|
875 | + $messenger, |
|
876 | + $message_type, |
|
877 | + $queue, |
|
878 | + $custom_subject, |
|
879 | + ) |
|
880 | + ); |
|
881 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
887 | + * |
|
888 | + * @since 4.9.0 |
|
889 | + * @param array $message_ids An array of message ids |
|
890 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
891 | + * messages. |
|
892 | + */ |
|
893 | + public static function generate_now($message_ids) |
|
894 | + { |
|
895 | + self::_load_controller(); |
|
896 | + $messages = EEM_Message::instance()->get_all( |
|
897 | + array( |
|
898 | + 0 => array( |
|
899 | + 'MSG_ID' => array('IN', $message_ids), |
|
900 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
901 | + ), |
|
902 | + ) |
|
903 | + ); |
|
904 | + $generated_queue = false; |
|
905 | + if ($messages) { |
|
906 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
907 | + } |
|
908 | + |
|
909 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
910 | + EE_Error::add_error( |
|
911 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
912 | + 'event_espresso'), |
|
913 | + __FILE__, __FUNCTION__, __LINE__ |
|
914 | + ); |
|
915 | + } |
|
916 | + return $generated_queue; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
922 | + * EEM_Message::status_idle |
|
923 | + * |
|
924 | + * @since 4.9.0 |
|
925 | + * @param $message_ids |
|
926 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
927 | + */ |
|
928 | + public static function send_now($message_ids) |
|
929 | + { |
|
930 | + self::_load_controller(); |
|
931 | + $messages = EEM_Message::instance()->get_all( |
|
932 | + array( |
|
933 | + 0 => array( |
|
934 | + 'MSG_ID' => array('IN', $message_ids), |
|
935 | + 'STS_ID' => array( |
|
936 | + 'IN', |
|
937 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
938 | + ), |
|
939 | + ), |
|
940 | + ) |
|
941 | + ); |
|
942 | + $sent_queue = false; |
|
943 | + if ($messages) { |
|
944 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
945 | + } |
|
946 | + |
|
947 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
948 | + EE_Error::add_error( |
|
949 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
950 | + 'event_espresso'), |
|
951 | + __FILE__, __FUNCTION__, __LINE__ |
|
952 | + ); |
|
953 | + } else { |
|
954 | + //can count how many sent by using the messages in the queue |
|
955 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
956 | + if ($sent_count > 0) { |
|
957 | + EE_Error::add_success( |
|
958 | + sprintf( |
|
959 | + _n( |
|
960 | + 'There was %d message successfully sent.', |
|
961 | + 'There were %d messages successfully sent.', |
|
962 | + $sent_count, |
|
963 | + 'event_espresso' |
|
964 | + ), |
|
965 | + $sent_count |
|
966 | + ) |
|
967 | + ); |
|
968 | + } else { |
|
969 | + EE_Error::overwrite_errors(); |
|
970 | + EE_Error::add_error( |
|
971 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
972 | 972 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
973 | - 'event_espresso'), |
|
974 | - __FILE__, __FUNCTION__, __LINE__ |
|
975 | - ); |
|
976 | - } |
|
977 | - } |
|
978 | - return $sent_queue; |
|
979 | - } |
|
980 | - |
|
981 | - |
|
982 | - /** |
|
983 | - * This will queue the incoming message ids for resending. |
|
984 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
985 | - * |
|
986 | - * @since 4.9.0 |
|
987 | - * @param array $message_ids An array of EE_Message IDs |
|
988 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
989 | - * resending. |
|
990 | - */ |
|
991 | - public static function queue_for_resending($message_ids) |
|
992 | - { |
|
993 | - self::_load_controller(); |
|
994 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
995 | - |
|
996 | - //get queue and count |
|
997 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
998 | - |
|
999 | - if ( |
|
1000 | - $queue_count > 0 |
|
1001 | - ) { |
|
1002 | - EE_Error::add_success( |
|
1003 | - sprintf( |
|
1004 | - _n( |
|
1005 | - '%d message successfully queued for resending.', |
|
1006 | - '%d messages successfully queued for resending.', |
|
1007 | - $queue_count, |
|
1008 | - 'event_espresso' |
|
1009 | - ), |
|
1010 | - $queue_count |
|
1011 | - ) |
|
1012 | - ); |
|
1013 | - /** |
|
1014 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1015 | - */ |
|
1016 | - } elseif ( |
|
1017 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1018 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1019 | - ) { |
|
1020 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1021 | - if ($queue_count > 0) { |
|
1022 | - EE_Error::add_success( |
|
1023 | - sprintf( |
|
1024 | - _n( |
|
1025 | - '%d message successfully sent.', |
|
1026 | - '%d messages successfully sent.', |
|
1027 | - $queue_count, |
|
1028 | - 'event_espresso' |
|
1029 | - ), |
|
1030 | - $queue_count |
|
1031 | - ) |
|
1032 | - ); |
|
1033 | - } else { |
|
1034 | - EE_Error::add_error( |
|
1035 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1036 | - 'event_espresso'), |
|
1037 | - __FILE__, __FUNCTION__, __LINE__ |
|
1038 | - ); |
|
1039 | - } |
|
1040 | - } else { |
|
1041 | - EE_Error::add_error( |
|
1042 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1043 | - 'event_espresso'), |
|
1044 | - __FILE__, __FUNCTION__, __LINE__ |
|
1045 | - ); |
|
1046 | - } |
|
1047 | - return (bool)$queue_count; |
|
1048 | - } |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * debug |
|
1053 | - * |
|
1054 | - * @param string $class |
|
1055 | - * @param string $func |
|
1056 | - * @param string $line |
|
1057 | - * @param \EE_Transaction $transaction |
|
1058 | - * @param array $info |
|
1059 | - * @param bool $display_request |
|
1060 | - */ |
|
1061 | - protected static function log( |
|
1062 | - $class = '', |
|
1063 | - $func = '', |
|
1064 | - $line = '', |
|
1065 | - EE_Transaction $transaction, |
|
1066 | - $info = array(), |
|
1067 | - $display_request = false |
|
1068 | - ) { |
|
1069 | - if (WP_DEBUG && false) { |
|
1070 | - if ($transaction instanceof EE_Transaction) { |
|
1071 | - // don't serialize objects |
|
1072 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1073 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1074 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1075 | - if ($transaction->ID()) { |
|
1076 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1077 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1078 | - } |
|
1079 | - } |
|
1080 | - } |
|
1081 | - |
|
1082 | - } |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * Resets all the static properties in this class when called. |
|
1087 | - */ |
|
1088 | - public static function reset() |
|
1089 | - { |
|
1090 | - self::$_EEMSG = null; |
|
1091 | - self::$_message_resource_manager = null; |
|
1092 | - self::$_MSG_PROCESSOR = null; |
|
1093 | - self::$_MSG_PATHS = null; |
|
1094 | - self::$_TMP_PACKS = array(); |
|
1095 | - } |
|
973 | + 'event_espresso'), |
|
974 | + __FILE__, __FUNCTION__, __LINE__ |
|
975 | + ); |
|
976 | + } |
|
977 | + } |
|
978 | + return $sent_queue; |
|
979 | + } |
|
980 | + |
|
981 | + |
|
982 | + /** |
|
983 | + * This will queue the incoming message ids for resending. |
|
984 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
985 | + * |
|
986 | + * @since 4.9.0 |
|
987 | + * @param array $message_ids An array of EE_Message IDs |
|
988 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
989 | + * resending. |
|
990 | + */ |
|
991 | + public static function queue_for_resending($message_ids) |
|
992 | + { |
|
993 | + self::_load_controller(); |
|
994 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
995 | + |
|
996 | + //get queue and count |
|
997 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
998 | + |
|
999 | + if ( |
|
1000 | + $queue_count > 0 |
|
1001 | + ) { |
|
1002 | + EE_Error::add_success( |
|
1003 | + sprintf( |
|
1004 | + _n( |
|
1005 | + '%d message successfully queued for resending.', |
|
1006 | + '%d messages successfully queued for resending.', |
|
1007 | + $queue_count, |
|
1008 | + 'event_espresso' |
|
1009 | + ), |
|
1010 | + $queue_count |
|
1011 | + ) |
|
1012 | + ); |
|
1013 | + /** |
|
1014 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1015 | + */ |
|
1016 | + } elseif ( |
|
1017 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1018 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1019 | + ) { |
|
1020 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1021 | + if ($queue_count > 0) { |
|
1022 | + EE_Error::add_success( |
|
1023 | + sprintf( |
|
1024 | + _n( |
|
1025 | + '%d message successfully sent.', |
|
1026 | + '%d messages successfully sent.', |
|
1027 | + $queue_count, |
|
1028 | + 'event_espresso' |
|
1029 | + ), |
|
1030 | + $queue_count |
|
1031 | + ) |
|
1032 | + ); |
|
1033 | + } else { |
|
1034 | + EE_Error::add_error( |
|
1035 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1036 | + 'event_espresso'), |
|
1037 | + __FILE__, __FUNCTION__, __LINE__ |
|
1038 | + ); |
|
1039 | + } |
|
1040 | + } else { |
|
1041 | + EE_Error::add_error( |
|
1042 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1043 | + 'event_espresso'), |
|
1044 | + __FILE__, __FUNCTION__, __LINE__ |
|
1045 | + ); |
|
1046 | + } |
|
1047 | + return (bool)$queue_count; |
|
1048 | + } |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * debug |
|
1053 | + * |
|
1054 | + * @param string $class |
|
1055 | + * @param string $func |
|
1056 | + * @param string $line |
|
1057 | + * @param \EE_Transaction $transaction |
|
1058 | + * @param array $info |
|
1059 | + * @param bool $display_request |
|
1060 | + */ |
|
1061 | + protected static function log( |
|
1062 | + $class = '', |
|
1063 | + $func = '', |
|
1064 | + $line = '', |
|
1065 | + EE_Transaction $transaction, |
|
1066 | + $info = array(), |
|
1067 | + $display_request = false |
|
1068 | + ) { |
|
1069 | + if (WP_DEBUG && false) { |
|
1070 | + if ($transaction instanceof EE_Transaction) { |
|
1071 | + // don't serialize objects |
|
1072 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1073 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1074 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1075 | + if ($transaction->ID()) { |
|
1076 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1077 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1078 | + } |
|
1079 | + } |
|
1080 | + } |
|
1081 | + |
|
1082 | + } |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * Resets all the static properties in this class when called. |
|
1087 | + */ |
|
1088 | + public static function reset() |
|
1089 | + { |
|
1090 | + self::$_EEMSG = null; |
|
1091 | + self::$_message_resource_manager = null; |
|
1092 | + self::$_MSG_PROCESSOR = null; |
|
1093 | + self::$_MSG_PATHS = null; |
|
1094 | + self::$_TMP_PACKS = array(); |
|
1095 | + } |
|
1096 | 1096 | |
1097 | 1097 | } |
1098 | 1098 | // End of file EED_Messages.module.php |