@@ -24,459 +24,459 @@ |
||
24 | 24 | class Registry |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Template_Config $template_config |
|
29 | - */ |
|
30 | - protected $template_config; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Currency_Config $currency_config |
|
34 | - */ |
|
35 | - protected $currency_config; |
|
36 | - |
|
37 | - /** |
|
38 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $jsdata = array(); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | - * page source. |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $script_handles_with_data = array(); |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @var DomainInterface |
|
55 | - */ |
|
56 | - protected $domain; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Registry constructor. |
|
61 | - * Hooking into WP actions for script registry. |
|
62 | - * |
|
63 | - * @param EE_Template_Config $template_config |
|
64 | - * @param EE_Currency_Config $currency_config |
|
65 | - * @param DomainInterface $domain |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - EE_Template_Config $template_config, |
|
69 | - EE_Currency_Config $currency_config, |
|
70 | - DomainInterface $domain |
|
71 | - ) { |
|
72 | - $this->template_config = $template_config; |
|
73 | - $this->currency_config = $currency_config; |
|
74 | - $this->domain = $domain; |
|
75 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
76 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
77 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
78 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
79 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
80 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Callback for the WP script actions. |
|
87 | - * Used to register globally accessible core scripts. |
|
88 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
89 | - */ |
|
90 | - public function scripts() |
|
91 | - { |
|
92 | - global $wp_version; |
|
93 | - wp_register_script( |
|
94 | - 'eejs-core', |
|
95 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
96 | - array(), |
|
97 | - EVENT_ESPRESSO_VERSION, |
|
98 | - true |
|
99 | - ); |
|
100 | - //only run this if WordPress 4.4.0 > is in use. |
|
101 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
102 | - //js.api |
|
103 | - wp_register_script( |
|
104 | - 'eejs-api', |
|
105 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
106 | - array('underscore', 'eejs-core'), |
|
107 | - EVENT_ESPRESSO_VERSION, |
|
108 | - true |
|
109 | - ); |
|
110 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
111 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
112 | - } |
|
113 | - if (! is_admin()) { |
|
114 | - $this->loadCoreCss(); |
|
115 | - } |
|
116 | - $this->loadCoreJs(); |
|
117 | - $this->loadJqueryValidate(); |
|
118 | - $this->loadAccountingJs(); |
|
119 | - $this->loadQtipJs(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Call back for the script print in frontend and backend. |
|
126 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
127 | - * |
|
128 | - * @since 4.9.31.rc.015 |
|
129 | - */ |
|
130 | - public function enqueueData() |
|
131 | - { |
|
132 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
133 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
134 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
135 | - $this->localizeAccountingJs(); |
|
136 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
137 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Used to add data to eejs.data object. |
|
144 | - * Note: Overriding existing data is not allowed. |
|
145 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
146 | - * If the data you add is something like this: |
|
147 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
148 | - * It will be exposed in the page source as: |
|
149 | - * eejs.data.my_plugin_data.foo == gar |
|
150 | - * |
|
151 | - * @param string $key Key used to access your data |
|
152 | - * @param string|array $value Value to attach to key |
|
153 | - * @throws InvalidArgumentException |
|
154 | - */ |
|
155 | - public function addData($key, $value) |
|
156 | - { |
|
157 | - if ($this->verifyDataNotExisting($key)) { |
|
158 | - $this->jsdata[$key] = $value; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
166 | - * elements in an array. |
|
167 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
168 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
169 | - * object like this, eejs.data.test = [ my_data, |
|
170 | - * ] |
|
171 | - * If there has already been a scalar value attached to the data object given key, then |
|
172 | - * this will throw an exception. |
|
173 | - * |
|
174 | - * @param string $key Key to attach data to. |
|
175 | - * @param string|array $value Value being registered. |
|
176 | - * @throws InvalidArgumentException |
|
177 | - */ |
|
178 | - public function pushData($key, $value) |
|
179 | - { |
|
180 | - if (isset($this->jsdata[$key]) |
|
181 | - && ! is_array($this->jsdata[$key]) |
|
182 | - ) { |
|
183 | - throw new invalidArgumentException( |
|
184 | - sprintf( |
|
185 | - __( |
|
186 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
27 | + /** |
|
28 | + * @var EE_Template_Config $template_config |
|
29 | + */ |
|
30 | + protected $template_config; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Currency_Config $currency_config |
|
34 | + */ |
|
35 | + protected $currency_config; |
|
36 | + |
|
37 | + /** |
|
38 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $jsdata = array(); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | + * page source. |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $script_handles_with_data = array(); |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @var DomainInterface |
|
55 | + */ |
|
56 | + protected $domain; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Registry constructor. |
|
61 | + * Hooking into WP actions for script registry. |
|
62 | + * |
|
63 | + * @param EE_Template_Config $template_config |
|
64 | + * @param EE_Currency_Config $currency_config |
|
65 | + * @param DomainInterface $domain |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + EE_Template_Config $template_config, |
|
69 | + EE_Currency_Config $currency_config, |
|
70 | + DomainInterface $domain |
|
71 | + ) { |
|
72 | + $this->template_config = $template_config; |
|
73 | + $this->currency_config = $currency_config; |
|
74 | + $this->domain = $domain; |
|
75 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
76 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
77 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
78 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
79 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
80 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Callback for the WP script actions. |
|
87 | + * Used to register globally accessible core scripts. |
|
88 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
89 | + */ |
|
90 | + public function scripts() |
|
91 | + { |
|
92 | + global $wp_version; |
|
93 | + wp_register_script( |
|
94 | + 'eejs-core', |
|
95 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
96 | + array(), |
|
97 | + EVENT_ESPRESSO_VERSION, |
|
98 | + true |
|
99 | + ); |
|
100 | + //only run this if WordPress 4.4.0 > is in use. |
|
101 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
102 | + //js.api |
|
103 | + wp_register_script( |
|
104 | + 'eejs-api', |
|
105 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
106 | + array('underscore', 'eejs-core'), |
|
107 | + EVENT_ESPRESSO_VERSION, |
|
108 | + true |
|
109 | + ); |
|
110 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
111 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
112 | + } |
|
113 | + if (! is_admin()) { |
|
114 | + $this->loadCoreCss(); |
|
115 | + } |
|
116 | + $this->loadCoreJs(); |
|
117 | + $this->loadJqueryValidate(); |
|
118 | + $this->loadAccountingJs(); |
|
119 | + $this->loadQtipJs(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Call back for the script print in frontend and backend. |
|
126 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
127 | + * |
|
128 | + * @since 4.9.31.rc.015 |
|
129 | + */ |
|
130 | + public function enqueueData() |
|
131 | + { |
|
132 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
133 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
134 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
135 | + $this->localizeAccountingJs(); |
|
136 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
137 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Used to add data to eejs.data object. |
|
144 | + * Note: Overriding existing data is not allowed. |
|
145 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
146 | + * If the data you add is something like this: |
|
147 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
148 | + * It will be exposed in the page source as: |
|
149 | + * eejs.data.my_plugin_data.foo == gar |
|
150 | + * |
|
151 | + * @param string $key Key used to access your data |
|
152 | + * @param string|array $value Value to attach to key |
|
153 | + * @throws InvalidArgumentException |
|
154 | + */ |
|
155 | + public function addData($key, $value) |
|
156 | + { |
|
157 | + if ($this->verifyDataNotExisting($key)) { |
|
158 | + $this->jsdata[$key] = $value; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
166 | + * elements in an array. |
|
167 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
168 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
169 | + * object like this, eejs.data.test = [ my_data, |
|
170 | + * ] |
|
171 | + * If there has already been a scalar value attached to the data object given key, then |
|
172 | + * this will throw an exception. |
|
173 | + * |
|
174 | + * @param string $key Key to attach data to. |
|
175 | + * @param string|array $value Value being registered. |
|
176 | + * @throws InvalidArgumentException |
|
177 | + */ |
|
178 | + public function pushData($key, $value) |
|
179 | + { |
|
180 | + if (isset($this->jsdata[$key]) |
|
181 | + && ! is_array($this->jsdata[$key]) |
|
182 | + ) { |
|
183 | + throw new invalidArgumentException( |
|
184 | + sprintf( |
|
185 | + __( |
|
186 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
187 | 187 | push values to this data element when it is an array.', |
188 | - 'event_espresso' |
|
189 | - ), |
|
190 | - $key, |
|
191 | - __METHOD__ |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - $this->jsdata[$key][] = $value; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Used to set content used by javascript for a template. |
|
202 | - * Note: Overrides of existing registered templates are not allowed. |
|
203 | - * |
|
204 | - * @param string $template_reference |
|
205 | - * @param string $template_content |
|
206 | - * @throws InvalidArgumentException |
|
207 | - */ |
|
208 | - public function addTemplate($template_reference, $template_content) |
|
209 | - { |
|
210 | - if (! isset($this->jsdata['templates'])) { |
|
211 | - $this->jsdata['templates'] = array(); |
|
212 | - } |
|
213 | - //no overrides allowed. |
|
214 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
215 | - throw new invalidArgumentException( |
|
216 | - sprintf( |
|
217 | - __( |
|
218 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $template_reference |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Retrieve the template content already registered for the given reference. |
|
232 | - * |
|
233 | - * @param string $template_reference |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function getTemplate($template_reference) |
|
237 | - { |
|
238 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
239 | - ? $this->jsdata['templates'][$template_reference] |
|
240 | - : ''; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Retrieve registered data. |
|
247 | - * |
|
248 | - * @param string $key Name of key to attach data to. |
|
249 | - * @return mixed If there is no for the given key, then false is returned. |
|
250 | - */ |
|
251 | - public function getData($key) |
|
252 | - { |
|
253 | - return isset($this->jsdata[$key]) |
|
254 | - ? $this->jsdata[$key] |
|
255 | - : false; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Verifies whether the given data exists already on the jsdata array. |
|
262 | - * Overriding data is not allowed. |
|
263 | - * |
|
264 | - * @param string $key Index for data. |
|
265 | - * @return bool If valid then return true. |
|
266 | - * @throws InvalidArgumentException if data already exists. |
|
267 | - */ |
|
268 | - protected function verifyDataNotExisting($key) |
|
269 | - { |
|
270 | - if (isset($this->jsdata[$key])) { |
|
271 | - if (is_array($this->jsdata[$key])) { |
|
272 | - throw new InvalidArgumentException( |
|
273 | - sprintf( |
|
274 | - __( |
|
275 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
188 | + 'event_espresso' |
|
189 | + ), |
|
190 | + $key, |
|
191 | + __METHOD__ |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + $this->jsdata[$key][] = $value; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Used to set content used by javascript for a template. |
|
202 | + * Note: Overrides of existing registered templates are not allowed. |
|
203 | + * |
|
204 | + * @param string $template_reference |
|
205 | + * @param string $template_content |
|
206 | + * @throws InvalidArgumentException |
|
207 | + */ |
|
208 | + public function addTemplate($template_reference, $template_content) |
|
209 | + { |
|
210 | + if (! isset($this->jsdata['templates'])) { |
|
211 | + $this->jsdata['templates'] = array(); |
|
212 | + } |
|
213 | + //no overrides allowed. |
|
214 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
215 | + throw new invalidArgumentException( |
|
216 | + sprintf( |
|
217 | + __( |
|
218 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $template_reference |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Retrieve the template content already registered for the given reference. |
|
232 | + * |
|
233 | + * @param string $template_reference |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function getTemplate($template_reference) |
|
237 | + { |
|
238 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
239 | + ? $this->jsdata['templates'][$template_reference] |
|
240 | + : ''; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Retrieve registered data. |
|
247 | + * |
|
248 | + * @param string $key Name of key to attach data to. |
|
249 | + * @return mixed If there is no for the given key, then false is returned. |
|
250 | + */ |
|
251 | + public function getData($key) |
|
252 | + { |
|
253 | + return isset($this->jsdata[$key]) |
|
254 | + ? $this->jsdata[$key] |
|
255 | + : false; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Verifies whether the given data exists already on the jsdata array. |
|
262 | + * Overriding data is not allowed. |
|
263 | + * |
|
264 | + * @param string $key Index for data. |
|
265 | + * @return bool If valid then return true. |
|
266 | + * @throws InvalidArgumentException if data already exists. |
|
267 | + */ |
|
268 | + protected function verifyDataNotExisting($key) |
|
269 | + { |
|
270 | + if (isset($this->jsdata[$key])) { |
|
271 | + if (is_array($this->jsdata[$key])) { |
|
272 | + throw new InvalidArgumentException( |
|
273 | + sprintf( |
|
274 | + __( |
|
275 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
276 | 276 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
277 | 277 | %2$s method to push your value to the array.', |
278 | - 'event_espresso' |
|
279 | - ), |
|
280 | - $key, |
|
281 | - 'pushData()' |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - throw new InvalidArgumentException( |
|
286 | - sprintf( |
|
287 | - __( |
|
288 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
278 | + 'event_espresso' |
|
279 | + ), |
|
280 | + $key, |
|
281 | + 'pushData()' |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + throw new InvalidArgumentException( |
|
286 | + sprintf( |
|
287 | + __( |
|
288 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
289 | 289 | allowed. Consider attaching your value to a different key', |
290 | - 'event_espresso' |
|
291 | - ), |
|
292 | - $key |
|
293 | - ) |
|
294 | - ); |
|
295 | - } |
|
296 | - return true; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * registers core default stylesheets |
|
303 | - */ |
|
304 | - private function loadCoreCss() |
|
305 | - { |
|
306 | - if ($this->template_config->enable_default_style) { |
|
307 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
308 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
309 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
310 | - wp_register_style( |
|
311 | - 'espresso_default', |
|
312 | - $default_stylesheet_path, |
|
313 | - array('dashicons'), |
|
314 | - EVENT_ESPRESSO_VERSION |
|
315 | - ); |
|
316 | - //Load custom style sheet if available |
|
317 | - if ($this->template_config->custom_style_sheet !== null) { |
|
318 | - wp_register_style( |
|
319 | - 'espresso_custom_css', |
|
320 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
321 | - array('espresso_default'), |
|
322 | - EVENT_ESPRESSO_VERSION |
|
323 | - ); |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * registers core default javascript |
|
332 | - */ |
|
333 | - private function loadCoreJs() |
|
334 | - { |
|
335 | - // load core js |
|
336 | - wp_register_script( |
|
337 | - 'espresso_core', |
|
338 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
339 | - array('jquery'), |
|
340 | - EVENT_ESPRESSO_VERSION, |
|
341 | - true |
|
342 | - ); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * registers jQuery Validate for form validation |
|
349 | - */ |
|
350 | - private function loadJqueryValidate() |
|
351 | - { |
|
352 | - // register jQuery Validate and additional methods |
|
353 | - wp_register_script( |
|
354 | - 'jquery-validate', |
|
355 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
356 | - array('jquery'), |
|
357 | - '1.15.0', |
|
358 | - true |
|
359 | - ); |
|
360 | - wp_register_script( |
|
361 | - 'jquery-validate-extra-methods', |
|
362 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
363 | - array('jquery', 'jquery-validate'), |
|
364 | - '1.15.0', |
|
365 | - true |
|
366 | - ); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * registers accounting.js for performing client-side calculations |
|
373 | - */ |
|
374 | - private function loadAccountingJs() |
|
375 | - { |
|
376 | - //accounting.js library |
|
377 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
378 | - wp_register_script( |
|
379 | - 'ee-accounting-core', |
|
380 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
381 | - array('underscore'), |
|
382 | - '0.3.2', |
|
383 | - true |
|
384 | - ); |
|
385 | - wp_register_script( |
|
386 | - 'ee-accounting', |
|
387 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
388 | - array('ee-accounting-core'), |
|
389 | - EVENT_ESPRESSO_VERSION, |
|
390 | - true |
|
391 | - ); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * registers accounting.js for performing client-side calculations |
|
398 | - */ |
|
399 | - private function localizeAccountingJs() |
|
400 | - { |
|
401 | - wp_localize_script( |
|
402 | - 'ee-accounting', |
|
403 | - 'EE_ACCOUNTING_CFG', |
|
404 | - array( |
|
405 | - 'currency' => array( |
|
406 | - 'symbol' => $this->currency_config->sign, |
|
407 | - 'format' => array( |
|
408 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
409 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
410 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
411 | - ), |
|
412 | - 'decimal' => $this->currency_config->dec_mrk, |
|
413 | - 'thousand' => $this->currency_config->thsnds, |
|
414 | - 'precision' => $this->currency_config->dec_plc, |
|
415 | - ), |
|
416 | - 'number' => array( |
|
417 | - 'precision' => $this->currency_config->dec_plc, |
|
418 | - 'thousand' => $this->currency_config->thsnds, |
|
419 | - 'decimal' => $this->currency_config->dec_mrk, |
|
420 | - ), |
|
421 | - ) |
|
422 | - ); |
|
423 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * registers assets for cleaning your ears |
|
430 | - */ |
|
431 | - private function loadQtipJs() |
|
432 | - { |
|
433 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
434 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
435 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
436 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * This is used to set registered script handles that have data. |
|
443 | - * @param string $script_handle |
|
444 | - */ |
|
445 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
446 | - { |
|
447 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
453 | - * Dependency stored in WP_Scripts if its set. |
|
454 | - */ |
|
455 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
456 | - { |
|
457 | - if (empty($this->script_handles_with_data)) { |
|
458 | - return; |
|
459 | - } |
|
460 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
461 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
462 | - } |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
468 | - * @param string $script_handle |
|
469 | - */ |
|
470 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
471 | - { |
|
472 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
473 | - global $wp_scripts; |
|
474 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
475 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
476 | - unset($this->script_handles_with_data[$script_handle]); |
|
477 | - } |
|
478 | - } |
|
479 | - } |
|
290 | + 'event_espresso' |
|
291 | + ), |
|
292 | + $key |
|
293 | + ) |
|
294 | + ); |
|
295 | + } |
|
296 | + return true; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * registers core default stylesheets |
|
303 | + */ |
|
304 | + private function loadCoreCss() |
|
305 | + { |
|
306 | + if ($this->template_config->enable_default_style) { |
|
307 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
308 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
309 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
310 | + wp_register_style( |
|
311 | + 'espresso_default', |
|
312 | + $default_stylesheet_path, |
|
313 | + array('dashicons'), |
|
314 | + EVENT_ESPRESSO_VERSION |
|
315 | + ); |
|
316 | + //Load custom style sheet if available |
|
317 | + if ($this->template_config->custom_style_sheet !== null) { |
|
318 | + wp_register_style( |
|
319 | + 'espresso_custom_css', |
|
320 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
321 | + array('espresso_default'), |
|
322 | + EVENT_ESPRESSO_VERSION |
|
323 | + ); |
|
324 | + } |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * registers core default javascript |
|
332 | + */ |
|
333 | + private function loadCoreJs() |
|
334 | + { |
|
335 | + // load core js |
|
336 | + wp_register_script( |
|
337 | + 'espresso_core', |
|
338 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
339 | + array('jquery'), |
|
340 | + EVENT_ESPRESSO_VERSION, |
|
341 | + true |
|
342 | + ); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * registers jQuery Validate for form validation |
|
349 | + */ |
|
350 | + private function loadJqueryValidate() |
|
351 | + { |
|
352 | + // register jQuery Validate and additional methods |
|
353 | + wp_register_script( |
|
354 | + 'jquery-validate', |
|
355 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
356 | + array('jquery'), |
|
357 | + '1.15.0', |
|
358 | + true |
|
359 | + ); |
|
360 | + wp_register_script( |
|
361 | + 'jquery-validate-extra-methods', |
|
362 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
363 | + array('jquery', 'jquery-validate'), |
|
364 | + '1.15.0', |
|
365 | + true |
|
366 | + ); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * registers accounting.js for performing client-side calculations |
|
373 | + */ |
|
374 | + private function loadAccountingJs() |
|
375 | + { |
|
376 | + //accounting.js library |
|
377 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
378 | + wp_register_script( |
|
379 | + 'ee-accounting-core', |
|
380 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
381 | + array('underscore'), |
|
382 | + '0.3.2', |
|
383 | + true |
|
384 | + ); |
|
385 | + wp_register_script( |
|
386 | + 'ee-accounting', |
|
387 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
388 | + array('ee-accounting-core'), |
|
389 | + EVENT_ESPRESSO_VERSION, |
|
390 | + true |
|
391 | + ); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * registers accounting.js for performing client-side calculations |
|
398 | + */ |
|
399 | + private function localizeAccountingJs() |
|
400 | + { |
|
401 | + wp_localize_script( |
|
402 | + 'ee-accounting', |
|
403 | + 'EE_ACCOUNTING_CFG', |
|
404 | + array( |
|
405 | + 'currency' => array( |
|
406 | + 'symbol' => $this->currency_config->sign, |
|
407 | + 'format' => array( |
|
408 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
409 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
410 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
411 | + ), |
|
412 | + 'decimal' => $this->currency_config->dec_mrk, |
|
413 | + 'thousand' => $this->currency_config->thsnds, |
|
414 | + 'precision' => $this->currency_config->dec_plc, |
|
415 | + ), |
|
416 | + 'number' => array( |
|
417 | + 'precision' => $this->currency_config->dec_plc, |
|
418 | + 'thousand' => $this->currency_config->thsnds, |
|
419 | + 'decimal' => $this->currency_config->dec_mrk, |
|
420 | + ), |
|
421 | + ) |
|
422 | + ); |
|
423 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * registers assets for cleaning your ears |
|
430 | + */ |
|
431 | + private function loadQtipJs() |
|
432 | + { |
|
433 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
434 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
435 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
436 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * This is used to set registered script handles that have data. |
|
443 | + * @param string $script_handle |
|
444 | + */ |
|
445 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
446 | + { |
|
447 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
453 | + * Dependency stored in WP_Scripts if its set. |
|
454 | + */ |
|
455 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
456 | + { |
|
457 | + if (empty($this->script_handles_with_data)) { |
|
458 | + return; |
|
459 | + } |
|
460 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
461 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
462 | + } |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
468 | + * @param string $script_handle |
|
469 | + */ |
|
470 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
471 | + { |
|
472 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
473 | + global $wp_scripts; |
|
474 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
475 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
476 | + unset($this->script_handles_with_data[$script_handle]); |
|
477 | + } |
|
478 | + } |
|
479 | + } |
|
480 | 480 | |
481 | 481 | |
482 | 482 | } |
@@ -8,649 +8,649 @@ |
||
8 | 8 | class EE_Email_messenger extends EE_messenger |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * To field for email |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $_to = ''; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * CC field for email. |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_cc = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * From field for email |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $_from = ''; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Subject field for email |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_subject = ''; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Content field for email |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_content = ''; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * constructor |
|
47 | - * |
|
48 | - * @access public |
|
49 | - */ |
|
50 | - public function __construct() |
|
51 | - { |
|
52 | - //set name and description properties |
|
53 | - $this->name = 'email'; |
|
54 | - $this->description = sprintf( |
|
55 | - esc_html__( |
|
56 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '<code>wp_mail</code>' |
|
60 | - ); |
|
61 | - $this->label = array( |
|
62 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
63 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
64 | - ); |
|
65 | - $this->activate_on_install = true; |
|
66 | - |
|
67 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
68 | - // properties |
|
69 | - parent::__construct(); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * see abstract declaration in parent class for details. |
|
75 | - */ |
|
76 | - protected function _set_admin_pages() |
|
77 | - { |
|
78 | - $this->admin_registered_pages = array( |
|
79 | - 'events_edit' => true, |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * see abstract declaration in parent class for details |
|
86 | - */ |
|
87 | - protected function _set_valid_shortcodes() |
|
88 | - { |
|
89 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
90 | - // message type. |
|
91 | - $this->_valid_shortcodes = array( |
|
92 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
94 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * see abstract declaration in parent class for details |
|
101 | - * |
|
102 | - * @access protected |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function _set_validator_config() |
|
106 | - { |
|
107 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
108 | - |
|
109 | - $this->_validator_config = array( |
|
110 | - 'to' => array( |
|
111 | - 'shortcodes' => $valid_shortcodes['to'], |
|
112 | - 'type' => 'email', |
|
113 | - ), |
|
114 | - 'cc' => array( |
|
115 | - 'shortcodes' => $valid_shortcodes['to'], |
|
116 | - 'type' => 'email', |
|
117 | - ), |
|
118 | - 'from' => array( |
|
119 | - 'shortcodes' => $valid_shortcodes['from'], |
|
120 | - 'type' => 'email', |
|
121 | - ), |
|
122 | - 'subject' => array( |
|
123 | - 'shortcodes' => array( |
|
124 | - 'organization', |
|
125 | - 'primary_registration_details', |
|
126 | - 'event_author', |
|
127 | - 'primary_registration_details', |
|
128 | - 'recipient_details', |
|
129 | - ), |
|
130 | - ), |
|
131 | - 'content' => array( |
|
132 | - 'shortcodes' => array( |
|
133 | - 'event_list', |
|
134 | - 'attendee_list', |
|
135 | - 'ticket_list', |
|
136 | - 'organization', |
|
137 | - 'primary_registration_details', |
|
138 | - 'primary_registration_list', |
|
139 | - 'event_author', |
|
140 | - 'recipient_details', |
|
141 | - 'recipient_list', |
|
142 | - 'transaction', |
|
143 | - 'messenger', |
|
144 | - ), |
|
145 | - ), |
|
146 | - 'attendee_list' => array( |
|
147 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
148 | - 'required' => array('[ATTENDEE_LIST]'), |
|
149 | - ), |
|
150 | - 'event_list' => array( |
|
151 | - 'shortcodes' => array( |
|
152 | - 'event', |
|
153 | - 'attendee_list', |
|
154 | - 'ticket_list', |
|
155 | - 'venue', |
|
156 | - 'datetime_list', |
|
157 | - 'attendee', |
|
158 | - 'primary_registration_details', |
|
159 | - 'primary_registration_list', |
|
160 | - 'event_author', |
|
161 | - 'recipient_details', |
|
162 | - 'recipient_list', |
|
163 | - ), |
|
164 | - 'required' => array('[EVENT_LIST]'), |
|
165 | - ), |
|
166 | - 'ticket_list' => array( |
|
167 | - 'shortcodes' => array( |
|
168 | - 'event_list', |
|
169 | - 'attendee_list', |
|
170 | - 'ticket', |
|
171 | - 'datetime_list', |
|
172 | - 'primary_registration_details', |
|
173 | - 'recipient_details', |
|
174 | - ), |
|
175 | - 'required' => array('[TICKET_LIST]'), |
|
176 | - ), |
|
177 | - 'datetime_list' => array( |
|
178 | - 'shortcodes' => array('datetime'), |
|
179 | - 'required' => array('[DATETIME_LIST]'), |
|
180 | - ), |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @see parent EE_messenger class for docs |
|
187 | - * @since 4.5.0 |
|
188 | - */ |
|
189 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
190 | - { |
|
191 | - if ($sending_messenger_name = 'html') { |
|
192 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - public function add_email_css( |
|
198 | - $variation_path, |
|
199 | - $messenger, |
|
200 | - $message_type, |
|
201 | - $type, |
|
202 | - $variation, |
|
203 | - $file_extension, |
|
204 | - $url, |
|
205 | - EE_Messages_Template_Pack $template_pack |
|
206 | - ) { |
|
207 | - //prevent recursion on this callback. |
|
208 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
209 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
210 | - |
|
211 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
212 | - return $variation; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * See parent for details |
|
218 | - * |
|
219 | - * @access protected |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - protected function _set_test_settings_fields() |
|
223 | - { |
|
224 | - $this->_test_settings_fields = array( |
|
225 | - 'to' => array( |
|
226 | - 'input' => 'text', |
|
227 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
228 | - 'type' => 'email', |
|
229 | - 'required' => true, |
|
230 | - 'validation' => true, |
|
231 | - 'css_class' => 'large-text', |
|
232 | - 'format' => '%s', |
|
233 | - 'default' => get_bloginfo('admin_email'), |
|
234 | - ), |
|
235 | - 'subject' => array( |
|
236 | - 'input' => 'hidden', |
|
237 | - 'label' => '', |
|
238 | - 'type' => 'string', |
|
239 | - 'required' => false, |
|
240 | - 'validation' => false, |
|
241 | - 'format' => '%s', |
|
242 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
243 | - 'default' => '', |
|
244 | - 'css_class' => '', |
|
245 | - ), |
|
246 | - ); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * _set_template_fields |
|
252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - protected function _set_template_fields() |
|
258 | - { |
|
259 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
260 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
261 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
262 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
263 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
264 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
265 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
266 | - // will not be displayed/parsed. |
|
267 | - $this->_template_fields = array( |
|
268 | - 'to' => array( |
|
269 | - 'input' => 'text', |
|
270 | - 'label' => esc_html_x( |
|
271 | - 'To', |
|
272 | - 'Label for the "To" field for email addresses', |
|
273 | - 'event_espresso' |
|
274 | - ), |
|
275 | - 'type' => 'string', |
|
276 | - 'required' => true, |
|
277 | - 'validation' => true, |
|
278 | - 'css_class' => 'large-text', |
|
279 | - 'format' => '%s', |
|
280 | - ), |
|
281 | - 'cc' => array( |
|
282 | - 'input' => 'text', |
|
283 | - 'label' => esc_html_x( |
|
284 | - 'CC', |
|
285 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
286 | - 'event_espresso' |
|
287 | - ), |
|
288 | - 'type' => 'string', |
|
289 | - 'required' => false, |
|
290 | - 'validation' => true, |
|
291 | - 'css_class' => 'large-text', |
|
292 | - 'format' => '%s', |
|
293 | - ), |
|
294 | - 'from' => array( |
|
295 | - 'input' => 'text', |
|
296 | - 'label' => esc_html_x( |
|
297 | - 'From', |
|
298 | - 'Label for the "From" field for email addresses.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - 'type' => 'string', |
|
302 | - 'required' => true, |
|
303 | - 'validation' => true, |
|
304 | - 'css_class' => 'large-text', |
|
305 | - 'format' => '%s', |
|
306 | - ), |
|
307 | - 'subject' => array( |
|
308 | - 'input' => 'text', |
|
309 | - 'label' => esc_html_x( |
|
310 | - 'Subject', |
|
311 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
312 | - 'event_espresso' |
|
313 | - ), |
|
314 | - 'type' => 'string', |
|
315 | - 'required' => true, |
|
316 | - 'validation' => true, |
|
317 | - 'css_class' => 'large-text', |
|
318 | - 'format' => '%s', |
|
319 | - ), |
|
320 | - 'content' => '', |
|
321 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
322 | - 'extra' => array( |
|
323 | - 'content' => array( |
|
324 | - 'main' => array( |
|
325 | - 'input' => 'wp_editor', |
|
326 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
327 | - 'type' => 'string', |
|
328 | - 'required' => true, |
|
329 | - 'validation' => true, |
|
330 | - 'format' => '%s', |
|
331 | - 'rows' => '15', |
|
332 | - ), |
|
333 | - 'event_list' => array( |
|
334 | - 'input' => 'wp_editor', |
|
335 | - 'label' => '[EVENT_LIST]', |
|
336 | - 'type' => 'string', |
|
337 | - 'required' => true, |
|
338 | - 'validation' => true, |
|
339 | - 'format' => '%s', |
|
340 | - 'rows' => '15', |
|
341 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
342 | - ), |
|
343 | - 'attendee_list' => array( |
|
344 | - 'input' => 'textarea', |
|
345 | - 'label' => '[ATTENDEE_LIST]', |
|
346 | - 'type' => 'string', |
|
347 | - 'required' => true, |
|
348 | - 'validation' => true, |
|
349 | - 'format' => '%s', |
|
350 | - 'css_class' => 'large-text', |
|
351 | - 'rows' => '5', |
|
352 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
353 | - ), |
|
354 | - 'ticket_list' => array( |
|
355 | - 'input' => 'textarea', |
|
356 | - 'label' => '[TICKET_LIST]', |
|
357 | - 'type' => 'string', |
|
358 | - 'required' => true, |
|
359 | - 'validation' => true, |
|
360 | - 'format' => '%s', |
|
361 | - 'css_class' => 'large-text', |
|
362 | - 'rows' => '10', |
|
363 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
364 | - ), |
|
365 | - 'datetime_list' => array( |
|
366 | - 'input' => 'textarea', |
|
367 | - 'label' => '[DATETIME_LIST]', |
|
368 | - 'type' => 'string', |
|
369 | - 'required' => true, |
|
370 | - 'validation' => true, |
|
371 | - 'format' => '%s', |
|
372 | - 'css_class' => 'large-text', |
|
373 | - 'rows' => '10', |
|
374 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
375 | - ), |
|
376 | - ), |
|
377 | - ), |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * See definition of this class in parent |
|
384 | - */ |
|
385 | - protected function _set_default_message_types() |
|
386 | - { |
|
387 | - $this->_default_message_types = array( |
|
388 | - 'payment', |
|
389 | - 'payment_refund', |
|
390 | - 'registration', |
|
391 | - 'not_approved_registration', |
|
392 | - 'pending_approval', |
|
393 | - ); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @see definition of this class in parent |
|
399 | - * @since 4.5.0 |
|
400 | - */ |
|
401 | - protected function _set_valid_message_types() |
|
402 | - { |
|
403 | - $this->_valid_message_types = array( |
|
404 | - 'payment', |
|
405 | - 'registration', |
|
406 | - 'not_approved_registration', |
|
407 | - 'declined_registration', |
|
408 | - 'cancelled_registration', |
|
409 | - 'pending_approval', |
|
410 | - 'registration_summary', |
|
411 | - 'payment_reminder', |
|
412 | - 'payment_declined', |
|
413 | - 'payment_refund', |
|
414 | - ); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * setting up admin_settings_fields for messenger. |
|
420 | - */ |
|
421 | - protected function _set_admin_settings_fields() |
|
422 | - { |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * We just deliver the messages don't kill us!! |
|
427 | - * |
|
428 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
429 | - * present. |
|
430 | - * @throws EE_Error |
|
431 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
432 | - */ |
|
433 | - protected function _send_message() |
|
434 | - { |
|
435 | - $success = wp_mail( |
|
436 | - $this->_to, |
|
437 | - //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
438 | - //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
439 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
440 | - $this->_body(), |
|
441 | - $this->_headers() |
|
442 | - ); |
|
443 | - if (! $success) { |
|
444 | - EE_Error::add_error( |
|
445 | - sprintf( |
|
446 | - esc_html__( |
|
447 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
448 | - 'event_espresso' |
|
449 | - ), |
|
450 | - $this->_to, |
|
451 | - $this->_from, |
|
452 | - '<br />' |
|
453 | - ), |
|
454 | - __FILE__, |
|
455 | - __FUNCTION__, |
|
456 | - __LINE__ |
|
457 | - ); |
|
458 | - } |
|
459 | - return $success; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * see parent for definition |
|
465 | - * |
|
466 | - * @return string html body of the message content and the related css. |
|
467 | - * @throws EE_Error |
|
468 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
469 | - */ |
|
470 | - protected function _preview() |
|
471 | - { |
|
472 | - return $this->_body(true); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Setup headers for email |
|
478 | - * |
|
479 | - * @access protected |
|
480 | - * @return string formatted header for email |
|
481 | - */ |
|
482 | - protected function _headers() |
|
483 | - { |
|
484 | - $this->_ensure_has_from_email_address(); |
|
485 | - $from = $this->_from; |
|
486 | - $headers = array( |
|
487 | - 'From:' . $from, |
|
488 | - 'Reply-To:' . $from, |
|
489 | - 'Content-Type:text/html; charset=utf-8', |
|
490 | - ); |
|
491 | - |
|
492 | - /** |
|
493 | - * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
494 | - * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
495 | - * type which they are no longer able to change. |
|
496 | - */ |
|
497 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
498 | - $headers[] = 'cc: ' . $this->_cc; |
|
499 | - } |
|
500 | - |
|
501 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
502 | - // header. |
|
503 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
504 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
505 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
511 | - * address for the from address to avoid problems with sending emails. |
|
512 | - */ |
|
513 | - protected function _ensure_has_from_email_address() |
|
514 | - { |
|
515 | - if (empty($this->_from)) { |
|
516 | - $this->_from = get_bloginfo('admin_email'); |
|
517 | - } |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
523 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
524 | - * be empty |
|
525 | - * |
|
526 | - * @since 4.3.1 |
|
527 | - * @return array |
|
528 | - */ |
|
529 | - private function _parse_from() |
|
530 | - { |
|
531 | - if (strpos($this->_from, '<') !== false) { |
|
532 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
533 | - $from_name = str_replace('"', '', $from_name); |
|
534 | - $from_name = trim($from_name); |
|
535 | - |
|
536 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
537 | - $from_email = str_replace('>', '', $from_email); |
|
538 | - $from_email = trim($from_email); |
|
539 | - } elseif (trim($this->_from) !== '') { |
|
540 | - $from_name = ''; |
|
541 | - $from_email = trim($this->_from); |
|
542 | - } else { |
|
543 | - $from_name = $from_email = ''; |
|
544 | - } |
|
545 | - return array($from_name, $from_email); |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Callback for the wp_mail_from filter. |
|
551 | - * |
|
552 | - * @since 4.3.1 |
|
553 | - * @param string $from_email What the original from_email is. |
|
554 | - * @return string |
|
555 | - */ |
|
556 | - public function set_from_address($from_email) |
|
557 | - { |
|
558 | - $parsed_from = $this->_parse_from(); |
|
559 | - //includes fallback if the parsing failed. |
|
560 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
561 | - ? $parsed_from[1] |
|
562 | - : get_bloginfo('admin_email'); |
|
563 | - return $from_email; |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * Callback fro the wp_mail_from_name filter. |
|
569 | - * |
|
570 | - * @since 4.3.1 |
|
571 | - * @param string $from_name The original from_name. |
|
572 | - * @return string |
|
573 | - */ |
|
574 | - public function set_from_name($from_name) |
|
575 | - { |
|
576 | - $parsed_from = $this->_parse_from(); |
|
577 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
578 | - $from_name = $parsed_from[0]; |
|
579 | - } |
|
580 | - |
|
581 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
582 | - //but realize the default name is HTML entity-encoded |
|
583 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
584 | - |
|
585 | - return $from_name; |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * setup body for email |
|
591 | - * |
|
592 | - * @param bool $preview will determine whether this is preview template or not. |
|
593 | - * @return string formatted body for email. |
|
594 | - * @throws EE_Error |
|
595 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
596 | - */ |
|
597 | - protected function _body($preview = false) |
|
598 | - { |
|
599 | - //setup template args! |
|
600 | - $this->_template_args = array( |
|
601 | - 'subject' => $this->_subject, |
|
602 | - 'from' => $this->_from, |
|
603 | - 'main_body' => wpautop($this->_content), |
|
604 | - ); |
|
605 | - $body = $this->_get_main_template($preview); |
|
606 | - |
|
607 | - /** |
|
608 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
609 | - * |
|
610 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
611 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
612 | - */ |
|
613 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
614 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
615 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
616 | - |
|
617 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
618 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
619 | - $style = file_get_contents( |
|
620 | - $this->get_variation( |
|
621 | - $this->_tmp_pack, |
|
622 | - $this->_incoming_message_type->name, |
|
623 | - false, |
|
624 | - 'main', |
|
625 | - $this->_variation |
|
626 | - ), |
|
627 | - true |
|
628 | - ); |
|
629 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
630 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
631 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
632 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
633 | - $body = ltrim($body, "<?"); |
|
634 | - } |
|
635 | - |
|
636 | - } |
|
637 | - return $body; |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * This just returns any existing test settings that might be saved in the database |
|
643 | - * |
|
644 | - * @access public |
|
645 | - * @return array |
|
646 | - */ |
|
647 | - public function get_existing_test_settings() |
|
648 | - { |
|
649 | - $settings = parent::get_existing_test_settings(); |
|
650 | - //override subject if present because we always want it to be fresh. |
|
651 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
652 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
653 | - } |
|
654 | - return $settings; |
|
655 | - } |
|
11 | + /** |
|
12 | + * To field for email |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $_to = ''; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * CC field for email. |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_cc = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * From field for email |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $_from = ''; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Subject field for email |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_subject = ''; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Content field for email |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_content = ''; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * constructor |
|
47 | + * |
|
48 | + * @access public |
|
49 | + */ |
|
50 | + public function __construct() |
|
51 | + { |
|
52 | + //set name and description properties |
|
53 | + $this->name = 'email'; |
|
54 | + $this->description = sprintf( |
|
55 | + esc_html__( |
|
56 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '<code>wp_mail</code>' |
|
60 | + ); |
|
61 | + $this->label = array( |
|
62 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
63 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
64 | + ); |
|
65 | + $this->activate_on_install = true; |
|
66 | + |
|
67 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
68 | + // properties |
|
69 | + parent::__construct(); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * see abstract declaration in parent class for details. |
|
75 | + */ |
|
76 | + protected function _set_admin_pages() |
|
77 | + { |
|
78 | + $this->admin_registered_pages = array( |
|
79 | + 'events_edit' => true, |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * see abstract declaration in parent class for details |
|
86 | + */ |
|
87 | + protected function _set_valid_shortcodes() |
|
88 | + { |
|
89 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
90 | + // message type. |
|
91 | + $this->_valid_shortcodes = array( |
|
92 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
94 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * see abstract declaration in parent class for details |
|
101 | + * |
|
102 | + * @access protected |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function _set_validator_config() |
|
106 | + { |
|
107 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
108 | + |
|
109 | + $this->_validator_config = array( |
|
110 | + 'to' => array( |
|
111 | + 'shortcodes' => $valid_shortcodes['to'], |
|
112 | + 'type' => 'email', |
|
113 | + ), |
|
114 | + 'cc' => array( |
|
115 | + 'shortcodes' => $valid_shortcodes['to'], |
|
116 | + 'type' => 'email', |
|
117 | + ), |
|
118 | + 'from' => array( |
|
119 | + 'shortcodes' => $valid_shortcodes['from'], |
|
120 | + 'type' => 'email', |
|
121 | + ), |
|
122 | + 'subject' => array( |
|
123 | + 'shortcodes' => array( |
|
124 | + 'organization', |
|
125 | + 'primary_registration_details', |
|
126 | + 'event_author', |
|
127 | + 'primary_registration_details', |
|
128 | + 'recipient_details', |
|
129 | + ), |
|
130 | + ), |
|
131 | + 'content' => array( |
|
132 | + 'shortcodes' => array( |
|
133 | + 'event_list', |
|
134 | + 'attendee_list', |
|
135 | + 'ticket_list', |
|
136 | + 'organization', |
|
137 | + 'primary_registration_details', |
|
138 | + 'primary_registration_list', |
|
139 | + 'event_author', |
|
140 | + 'recipient_details', |
|
141 | + 'recipient_list', |
|
142 | + 'transaction', |
|
143 | + 'messenger', |
|
144 | + ), |
|
145 | + ), |
|
146 | + 'attendee_list' => array( |
|
147 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
148 | + 'required' => array('[ATTENDEE_LIST]'), |
|
149 | + ), |
|
150 | + 'event_list' => array( |
|
151 | + 'shortcodes' => array( |
|
152 | + 'event', |
|
153 | + 'attendee_list', |
|
154 | + 'ticket_list', |
|
155 | + 'venue', |
|
156 | + 'datetime_list', |
|
157 | + 'attendee', |
|
158 | + 'primary_registration_details', |
|
159 | + 'primary_registration_list', |
|
160 | + 'event_author', |
|
161 | + 'recipient_details', |
|
162 | + 'recipient_list', |
|
163 | + ), |
|
164 | + 'required' => array('[EVENT_LIST]'), |
|
165 | + ), |
|
166 | + 'ticket_list' => array( |
|
167 | + 'shortcodes' => array( |
|
168 | + 'event_list', |
|
169 | + 'attendee_list', |
|
170 | + 'ticket', |
|
171 | + 'datetime_list', |
|
172 | + 'primary_registration_details', |
|
173 | + 'recipient_details', |
|
174 | + ), |
|
175 | + 'required' => array('[TICKET_LIST]'), |
|
176 | + ), |
|
177 | + 'datetime_list' => array( |
|
178 | + 'shortcodes' => array('datetime'), |
|
179 | + 'required' => array('[DATETIME_LIST]'), |
|
180 | + ), |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @see parent EE_messenger class for docs |
|
187 | + * @since 4.5.0 |
|
188 | + */ |
|
189 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
190 | + { |
|
191 | + if ($sending_messenger_name = 'html') { |
|
192 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + public function add_email_css( |
|
198 | + $variation_path, |
|
199 | + $messenger, |
|
200 | + $message_type, |
|
201 | + $type, |
|
202 | + $variation, |
|
203 | + $file_extension, |
|
204 | + $url, |
|
205 | + EE_Messages_Template_Pack $template_pack |
|
206 | + ) { |
|
207 | + //prevent recursion on this callback. |
|
208 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
209 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
210 | + |
|
211 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
212 | + return $variation; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * See parent for details |
|
218 | + * |
|
219 | + * @access protected |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + protected function _set_test_settings_fields() |
|
223 | + { |
|
224 | + $this->_test_settings_fields = array( |
|
225 | + 'to' => array( |
|
226 | + 'input' => 'text', |
|
227 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
228 | + 'type' => 'email', |
|
229 | + 'required' => true, |
|
230 | + 'validation' => true, |
|
231 | + 'css_class' => 'large-text', |
|
232 | + 'format' => '%s', |
|
233 | + 'default' => get_bloginfo('admin_email'), |
|
234 | + ), |
|
235 | + 'subject' => array( |
|
236 | + 'input' => 'hidden', |
|
237 | + 'label' => '', |
|
238 | + 'type' => 'string', |
|
239 | + 'required' => false, |
|
240 | + 'validation' => false, |
|
241 | + 'format' => '%s', |
|
242 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
243 | + 'default' => '', |
|
244 | + 'css_class' => '', |
|
245 | + ), |
|
246 | + ); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * _set_template_fields |
|
252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + protected function _set_template_fields() |
|
258 | + { |
|
259 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
260 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
261 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
262 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
263 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
264 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
265 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
266 | + // will not be displayed/parsed. |
|
267 | + $this->_template_fields = array( |
|
268 | + 'to' => array( |
|
269 | + 'input' => 'text', |
|
270 | + 'label' => esc_html_x( |
|
271 | + 'To', |
|
272 | + 'Label for the "To" field for email addresses', |
|
273 | + 'event_espresso' |
|
274 | + ), |
|
275 | + 'type' => 'string', |
|
276 | + 'required' => true, |
|
277 | + 'validation' => true, |
|
278 | + 'css_class' => 'large-text', |
|
279 | + 'format' => '%s', |
|
280 | + ), |
|
281 | + 'cc' => array( |
|
282 | + 'input' => 'text', |
|
283 | + 'label' => esc_html_x( |
|
284 | + 'CC', |
|
285 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
286 | + 'event_espresso' |
|
287 | + ), |
|
288 | + 'type' => 'string', |
|
289 | + 'required' => false, |
|
290 | + 'validation' => true, |
|
291 | + 'css_class' => 'large-text', |
|
292 | + 'format' => '%s', |
|
293 | + ), |
|
294 | + 'from' => array( |
|
295 | + 'input' => 'text', |
|
296 | + 'label' => esc_html_x( |
|
297 | + 'From', |
|
298 | + 'Label for the "From" field for email addresses.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + 'type' => 'string', |
|
302 | + 'required' => true, |
|
303 | + 'validation' => true, |
|
304 | + 'css_class' => 'large-text', |
|
305 | + 'format' => '%s', |
|
306 | + ), |
|
307 | + 'subject' => array( |
|
308 | + 'input' => 'text', |
|
309 | + 'label' => esc_html_x( |
|
310 | + 'Subject', |
|
311 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
312 | + 'event_espresso' |
|
313 | + ), |
|
314 | + 'type' => 'string', |
|
315 | + 'required' => true, |
|
316 | + 'validation' => true, |
|
317 | + 'css_class' => 'large-text', |
|
318 | + 'format' => '%s', |
|
319 | + ), |
|
320 | + 'content' => '', |
|
321 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
322 | + 'extra' => array( |
|
323 | + 'content' => array( |
|
324 | + 'main' => array( |
|
325 | + 'input' => 'wp_editor', |
|
326 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
327 | + 'type' => 'string', |
|
328 | + 'required' => true, |
|
329 | + 'validation' => true, |
|
330 | + 'format' => '%s', |
|
331 | + 'rows' => '15', |
|
332 | + ), |
|
333 | + 'event_list' => array( |
|
334 | + 'input' => 'wp_editor', |
|
335 | + 'label' => '[EVENT_LIST]', |
|
336 | + 'type' => 'string', |
|
337 | + 'required' => true, |
|
338 | + 'validation' => true, |
|
339 | + 'format' => '%s', |
|
340 | + 'rows' => '15', |
|
341 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
342 | + ), |
|
343 | + 'attendee_list' => array( |
|
344 | + 'input' => 'textarea', |
|
345 | + 'label' => '[ATTENDEE_LIST]', |
|
346 | + 'type' => 'string', |
|
347 | + 'required' => true, |
|
348 | + 'validation' => true, |
|
349 | + 'format' => '%s', |
|
350 | + 'css_class' => 'large-text', |
|
351 | + 'rows' => '5', |
|
352 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
353 | + ), |
|
354 | + 'ticket_list' => array( |
|
355 | + 'input' => 'textarea', |
|
356 | + 'label' => '[TICKET_LIST]', |
|
357 | + 'type' => 'string', |
|
358 | + 'required' => true, |
|
359 | + 'validation' => true, |
|
360 | + 'format' => '%s', |
|
361 | + 'css_class' => 'large-text', |
|
362 | + 'rows' => '10', |
|
363 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
364 | + ), |
|
365 | + 'datetime_list' => array( |
|
366 | + 'input' => 'textarea', |
|
367 | + 'label' => '[DATETIME_LIST]', |
|
368 | + 'type' => 'string', |
|
369 | + 'required' => true, |
|
370 | + 'validation' => true, |
|
371 | + 'format' => '%s', |
|
372 | + 'css_class' => 'large-text', |
|
373 | + 'rows' => '10', |
|
374 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
375 | + ), |
|
376 | + ), |
|
377 | + ), |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * See definition of this class in parent |
|
384 | + */ |
|
385 | + protected function _set_default_message_types() |
|
386 | + { |
|
387 | + $this->_default_message_types = array( |
|
388 | + 'payment', |
|
389 | + 'payment_refund', |
|
390 | + 'registration', |
|
391 | + 'not_approved_registration', |
|
392 | + 'pending_approval', |
|
393 | + ); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @see definition of this class in parent |
|
399 | + * @since 4.5.0 |
|
400 | + */ |
|
401 | + protected function _set_valid_message_types() |
|
402 | + { |
|
403 | + $this->_valid_message_types = array( |
|
404 | + 'payment', |
|
405 | + 'registration', |
|
406 | + 'not_approved_registration', |
|
407 | + 'declined_registration', |
|
408 | + 'cancelled_registration', |
|
409 | + 'pending_approval', |
|
410 | + 'registration_summary', |
|
411 | + 'payment_reminder', |
|
412 | + 'payment_declined', |
|
413 | + 'payment_refund', |
|
414 | + ); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * setting up admin_settings_fields for messenger. |
|
420 | + */ |
|
421 | + protected function _set_admin_settings_fields() |
|
422 | + { |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * We just deliver the messages don't kill us!! |
|
427 | + * |
|
428 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
429 | + * present. |
|
430 | + * @throws EE_Error |
|
431 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
432 | + */ |
|
433 | + protected function _send_message() |
|
434 | + { |
|
435 | + $success = wp_mail( |
|
436 | + $this->_to, |
|
437 | + //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
438 | + //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
439 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
440 | + $this->_body(), |
|
441 | + $this->_headers() |
|
442 | + ); |
|
443 | + if (! $success) { |
|
444 | + EE_Error::add_error( |
|
445 | + sprintf( |
|
446 | + esc_html__( |
|
447 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
448 | + 'event_espresso' |
|
449 | + ), |
|
450 | + $this->_to, |
|
451 | + $this->_from, |
|
452 | + '<br />' |
|
453 | + ), |
|
454 | + __FILE__, |
|
455 | + __FUNCTION__, |
|
456 | + __LINE__ |
|
457 | + ); |
|
458 | + } |
|
459 | + return $success; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * see parent for definition |
|
465 | + * |
|
466 | + * @return string html body of the message content and the related css. |
|
467 | + * @throws EE_Error |
|
468 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
469 | + */ |
|
470 | + protected function _preview() |
|
471 | + { |
|
472 | + return $this->_body(true); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Setup headers for email |
|
478 | + * |
|
479 | + * @access protected |
|
480 | + * @return string formatted header for email |
|
481 | + */ |
|
482 | + protected function _headers() |
|
483 | + { |
|
484 | + $this->_ensure_has_from_email_address(); |
|
485 | + $from = $this->_from; |
|
486 | + $headers = array( |
|
487 | + 'From:' . $from, |
|
488 | + 'Reply-To:' . $from, |
|
489 | + 'Content-Type:text/html; charset=utf-8', |
|
490 | + ); |
|
491 | + |
|
492 | + /** |
|
493 | + * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to |
|
494 | + * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
|
495 | + * type which they are no longer able to change. |
|
496 | + */ |
|
497 | + if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
498 | + $headers[] = 'cc: ' . $this->_cc; |
|
499 | + } |
|
500 | + |
|
501 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
502 | + // header. |
|
503 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
504 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
505 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
511 | + * address for the from address to avoid problems with sending emails. |
|
512 | + */ |
|
513 | + protected function _ensure_has_from_email_address() |
|
514 | + { |
|
515 | + if (empty($this->_from)) { |
|
516 | + $this->_from = get_bloginfo('admin_email'); |
|
517 | + } |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
523 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
524 | + * be empty |
|
525 | + * |
|
526 | + * @since 4.3.1 |
|
527 | + * @return array |
|
528 | + */ |
|
529 | + private function _parse_from() |
|
530 | + { |
|
531 | + if (strpos($this->_from, '<') !== false) { |
|
532 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
533 | + $from_name = str_replace('"', '', $from_name); |
|
534 | + $from_name = trim($from_name); |
|
535 | + |
|
536 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
537 | + $from_email = str_replace('>', '', $from_email); |
|
538 | + $from_email = trim($from_email); |
|
539 | + } elseif (trim($this->_from) !== '') { |
|
540 | + $from_name = ''; |
|
541 | + $from_email = trim($this->_from); |
|
542 | + } else { |
|
543 | + $from_name = $from_email = ''; |
|
544 | + } |
|
545 | + return array($from_name, $from_email); |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Callback for the wp_mail_from filter. |
|
551 | + * |
|
552 | + * @since 4.3.1 |
|
553 | + * @param string $from_email What the original from_email is. |
|
554 | + * @return string |
|
555 | + */ |
|
556 | + public function set_from_address($from_email) |
|
557 | + { |
|
558 | + $parsed_from = $this->_parse_from(); |
|
559 | + //includes fallback if the parsing failed. |
|
560 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
561 | + ? $parsed_from[1] |
|
562 | + : get_bloginfo('admin_email'); |
|
563 | + return $from_email; |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * Callback fro the wp_mail_from_name filter. |
|
569 | + * |
|
570 | + * @since 4.3.1 |
|
571 | + * @param string $from_name The original from_name. |
|
572 | + * @return string |
|
573 | + */ |
|
574 | + public function set_from_name($from_name) |
|
575 | + { |
|
576 | + $parsed_from = $this->_parse_from(); |
|
577 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
578 | + $from_name = $parsed_from[0]; |
|
579 | + } |
|
580 | + |
|
581 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
582 | + //but realize the default name is HTML entity-encoded |
|
583 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
584 | + |
|
585 | + return $from_name; |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * setup body for email |
|
591 | + * |
|
592 | + * @param bool $preview will determine whether this is preview template or not. |
|
593 | + * @return string formatted body for email. |
|
594 | + * @throws EE_Error |
|
595 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
596 | + */ |
|
597 | + protected function _body($preview = false) |
|
598 | + { |
|
599 | + //setup template args! |
|
600 | + $this->_template_args = array( |
|
601 | + 'subject' => $this->_subject, |
|
602 | + 'from' => $this->_from, |
|
603 | + 'main_body' => wpautop($this->_content), |
|
604 | + ); |
|
605 | + $body = $this->_get_main_template($preview); |
|
606 | + |
|
607 | + /** |
|
608 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
609 | + * |
|
610 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
611 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
612 | + */ |
|
613 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
614 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
615 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
616 | + |
|
617 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
618 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
619 | + $style = file_get_contents( |
|
620 | + $this->get_variation( |
|
621 | + $this->_tmp_pack, |
|
622 | + $this->_incoming_message_type->name, |
|
623 | + false, |
|
624 | + 'main', |
|
625 | + $this->_variation |
|
626 | + ), |
|
627 | + true |
|
628 | + ); |
|
629 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
630 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
631 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
632 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
633 | + $body = ltrim($body, "<?"); |
|
634 | + } |
|
635 | + |
|
636 | + } |
|
637 | + return $body; |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * This just returns any existing test settings that might be saved in the database |
|
643 | + * |
|
644 | + * @access public |
|
645 | + * @return array |
|
646 | + */ |
|
647 | + public function get_existing_test_settings() |
|
648 | + { |
|
649 | + $settings = parent::get_existing_test_settings(); |
|
650 | + //override subject if present because we always want it to be fresh. |
|
651 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
652 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
653 | + } |
|
654 | + return $settings; |
|
655 | + } |
|
656 | 656 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | ), |
59 | 59 | '<code>wp_mail</code>' |
60 | 60 | ); |
61 | - $this->label = array( |
|
61 | + $this->label = array( |
|
62 | 62 | 'singular' => esc_html__('email', 'event_espresso'), |
63 | 63 | 'plural' => esc_html__('emails', 'event_espresso'), |
64 | 64 | ); |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | $this->_body(), |
441 | 441 | $this->_headers() |
442 | 442 | ); |
443 | - if (! $success) { |
|
443 | + if ( ! $success) { |
|
444 | 444 | EE_Error::add_error( |
445 | 445 | sprintf( |
446 | 446 | esc_html__( |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | $this->_ensure_has_from_email_address(); |
485 | 485 | $from = $this->_from; |
486 | 486 | $headers = array( |
487 | - 'From:' . $from, |
|
488 | - 'Reply-To:' . $from, |
|
487 | + 'From:'.$from, |
|
488 | + 'Reply-To:'.$from, |
|
489 | 489 | 'Content-Type:text/html; charset=utf-8', |
490 | 490 | ); |
491 | 491 | |
@@ -494,8 +494,8 @@ discard block |
||
494 | 494 | * cover back compat where there may be users who have saved cc values in their db for the newsletter message |
495 | 495 | * type which they are no longer able to change. |
496 | 496 | */ |
497 | - if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
498 | - $headers[] = 'cc: ' . $this->_cc; |
|
497 | + if ( ! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { |
|
498 | + $headers[] = 'cc: '.$this->_cc; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | 'from' => $this->_from, |
603 | 603 | 'main_body' => wpautop($this->_content), |
604 | 604 | ); |
605 | - $body = $this->_get_main_template($preview); |
|
605 | + $body = $this->_get_main_template($preview); |
|
606 | 606 | |
607 | 607 | /** |
608 | 608 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
@@ -612,10 +612,10 @@ discard block |
||
612 | 612 | */ |
613 | 613 | if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
614 | 614 | //require CssToInlineStyles library and its dependencies via composer autoloader |
615 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
615 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php'; |
|
616 | 616 | |
617 | 617 | //now if this isn't a preview, let's setup the body so it has inline styles |
618 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
618 | + if ( ! $preview || ($preview && defined('DOING_AJAX'))) { |
|
619 | 619 | $style = file_get_contents( |
620 | 620 | $this->get_variation( |
621 | 621 | $this->_tmp_pack, |
@@ -300,20 +300,20 @@ |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * Allows a message type to specifically exclude template fields for the provided messenger. |
|
305 | - * Filtered so this can be programmatically altered as well. |
|
306 | - * @param string $messenger_name name of messenger |
|
307 | - * @return array |
|
308 | - */ |
|
303 | + /** |
|
304 | + * Allows a message type to specifically exclude template fields for the provided messenger. |
|
305 | + * Filtered so this can be programmatically altered as well. |
|
306 | + * @param string $messenger_name name of messenger |
|
307 | + * @return array |
|
308 | + */ |
|
309 | 309 | public function excludedFieldsForMessenger($messenger_name) |
310 | - { |
|
311 | - return apply_filters( |
|
312 | - 'FHEE__EE_Messages_Base__excludedFieldForMessenger', |
|
313 | - array(), |
|
314 | - $messenger_name, |
|
315 | - $this->name, |
|
316 | - $this |
|
317 | - ); |
|
318 | - } |
|
310 | + { |
|
311 | + return apply_filters( |
|
312 | + 'FHEE__EE_Messages_Base__excludedFieldForMessenger', |
|
313 | + array(), |
|
314 | + $messenger_name, |
|
315 | + $this->name, |
|
316 | + $this |
|
317 | + ); |
|
318 | + } |
|
319 | 319 | } |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | if ( ! empty( $sending_messenger ) ) { |
493 | 493 | $with_messengers = $message_type->with_messengers(); |
494 | 494 | if ( ! isset( $with_messengers[$message->messenger()] ) |
495 | - || ! in_array( $sending_messenger, $with_messengers[$message->messenger()] ) ) { |
|
495 | + || ! in_array( $sending_messenger, $with_messengers[$message->messenger()] ) ) { |
|
496 | 496 | throw new EE_Error( |
497 | 497 | sprintf( |
498 | 498 | __( |
@@ -1202,14 +1202,14 @@ discard block |
||
1202 | 1202 | return array(); |
1203 | 1203 | } |
1204 | 1204 | |
1205 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
1205 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
1206 | 1206 | |
1207 | 1207 | //okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
1208 | 1208 | foreach ( $message_type->get_contexts() as $context => $details ) { |
1209 | 1209 | foreach ( $messenger->get_template_fields() as $field => $value ) { |
1210 | - if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
1211 | - continue; |
|
1212 | - } |
|
1210 | + if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
1211 | + continue; |
|
1212 | + } |
|
1213 | 1213 | $template_fields[ $context ][ $field ] = $value; |
1214 | 1214 | } |
1215 | 1215 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | * was not a new generated template but just reactivated (which only happens for global templates that |
60 | 60 | * already exist in the database. |
61 | 61 | */ |
62 | - public static function generate_new_templates( $messenger, $message_types, $GRP_ID = 0, $global = false ) { |
|
62 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) { |
|
63 | 63 | //make sure message_type is an array. |
64 | 64 | $message_types = (array) $message_types; |
65 | 65 | $templates = array(); |
66 | 66 | |
67 | - if ( empty( $messenger ) ) { |
|
68 | - throw new EE_Error( __('We need a messenger to generate templates!', 'event_espresso') ); |
|
67 | + if (empty($messenger)) { |
|
68 | + throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | //if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
72 | - if ( empty( $message_types ) ) { |
|
73 | - throw new EE_Error( __('We need at least one message type to generate templates!', 'event_espresso') ); |
|
72 | + if (empty($message_types)) { |
|
73 | + throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | EEH_MSG_Template::_set_autoloader(); |
77 | - foreach ( $message_types as $message_type ) { |
|
77 | + foreach ($message_types as $message_type) { |
|
78 | 78 | //if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
79 | - if ( $global && empty( $GRP_ID ) ) { |
|
79 | + if ($global && empty($GRP_ID)) { |
|
80 | 80 | $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
81 | 81 | array( |
82 | 82 | array( |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // if this is global template generation. |
92 | 92 | // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
93 | 93 | // If we do then NO generation!! |
94 | - if ( $global && EEH_MSG_Template::already_generated( $messenger, $message_type, $GRP_ID ) ) { |
|
94 | + if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
95 | 95 | $templates[] = array( |
96 | 96 | 'GRP_ID' => $GRP_ID, |
97 | 97 | 'MTP_context' => '', |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | //we already have generated templates for this so let's go to the next message type. |
100 | 100 | continue; |
101 | 101 | } |
102 | - $new_message_template_group = EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $global ); |
|
102 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
103 | 103 | |
104 | - if ( ! $new_message_template_group ) { |
|
104 | + if ( ! $new_message_template_group) { |
|
105 | 105 | continue; |
106 | 106 | } |
107 | 107 | $templates[] = $new_message_template_group; |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
119 | 119 | * @return bool true = generated, false = hasn't been generated. |
120 | 120 | */ |
121 | - public static function already_generated( $messenger, $message_type, $GRP_ID = 0 ) { |
|
121 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0) { |
|
122 | 122 | EEH_MSG_Template::_set_autoloader(); |
123 | 123 | //what method we use depends on whether we have an GRP_ID or not |
124 | - $count = empty( $GRP_ID ) |
|
124 | + $count = empty($GRP_ID) |
|
125 | 125 | ? EEM_Message_Template::instance()->count( |
126 | 126 | array( |
127 | 127 | array( |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ) |
132 | 132 | ) |
133 | 133 | ) |
134 | - : EEM_Message_Template::instance()->count( array( array( 'GRP_ID' => $GRP_ID ) ) ); |
|
134 | + : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); |
|
135 | 135 | |
136 | 136 | return $count > 0; |
137 | 137 | } |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | * @param array $message_type_names Message type slug |
148 | 148 | * @return int count of updated records. |
149 | 149 | */ |
150 | - public static function update_to_active( $messenger_names, $message_type_names ) { |
|
151 | - $messenger_names = is_array( $messenger_names ) ? $messenger_names : array( $messenger_names ); |
|
152 | - $message_type_names = is_array( $message_type_names ) ? $message_type_names : array( $message_type_names ); |
|
150 | + public static function update_to_active($messenger_names, $message_type_names) { |
|
151 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names); |
|
152 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names); |
|
153 | 153 | return EEM_Message_Template_Group::instance()->update( |
154 | - array( 'MTP_is_active' => 1 ), |
|
154 | + array('MTP_is_active' => 1), |
|
155 | 155 | array( |
156 | 156 | array( |
157 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
158 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
157 | + 'MTP_messenger' => array('IN', $messenger_names), |
|
158 | + 'MTP_message_type' => array('IN', $message_type_names) |
|
159 | 159 | ) |
160 | 160 | ) |
161 | 161 | ); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return int count of updated records. |
178 | 178 | */ |
179 | - public static function update_to_inactive( $messenger_names = array(), $message_type_names = array() ) { |
|
179 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) { |
|
180 | 180 | return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
181 | 181 | $messenger_names, |
182 | 182 | $message_type_names |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | * @param string $type |
194 | 194 | * @return array array consisting of installed messenger objects and installed message type objects. |
195 | 195 | */ |
196 | - public static function get_installed_message_objects( $type = 'all' ) { |
|
196 | + public static function get_installed_message_objects($type = 'all') { |
|
197 | 197 | self::_set_autoloader(); |
198 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
198 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
199 | 199 | return array( |
200 | 200 | 'messenger' => $message_resource_manager->installed_messengers(), |
201 | 201 | 'message_type' => $message_resource_manager->installed_message_types() |
@@ -231,74 +231,74 @@ discard block |
||
231 | 231 | $context = 'admin', |
232 | 232 | $merged = false |
233 | 233 | ) { |
234 | - $messenger_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $messenger ) ) ); |
|
235 | - $mt_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $message_type ) ) ); |
|
234 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
235 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
236 | 236 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
237 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
237 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
238 | 238 | //convert slug to object |
239 | - $messenger = $message_resource_manager->get_messenger( $messenger ); |
|
239 | + $messenger = $message_resource_manager->get_messenger($messenger); |
|
240 | 240 | |
241 | 241 | //if messenger isn't a EE_messenger resource then bail. |
242 | - if ( ! $messenger instanceof EE_messenger ) { |
|
242 | + if ( ! $messenger instanceof EE_messenger) { |
|
243 | 243 | return array(); |
244 | 244 | } |
245 | 245 | |
246 | 246 | //validate class for getting our list of shortcodes |
247 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
248 | - if ( ! class_exists( $classname ) ) { |
|
249 | - $msg[] = __( 'The Validator class was unable to load', 'event_espresso' ); |
|
247 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
248 | + if ( ! class_exists($classname)) { |
|
249 | + $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
250 | 250 | $msg[] = sprintf( |
251 | - __( 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso' ), |
|
251 | + __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
252 | 252 | $classname |
253 | 253 | ); |
254 | - throw new EE_Error( implode( '||', $msg ) ); |
|
254 | + throw new EE_Error(implode('||', $msg)); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** @type EE_Messages_Validator $_VLD */ |
258 | - $_VLD = new $classname( array(), $context ); |
|
258 | + $_VLD = new $classname(array(), $context); |
|
259 | 259 | $valid_shortcodes = $_VLD->get_validators(); |
260 | 260 | |
261 | 261 | //let's make sure we're only getting the shortcode part of the validators |
262 | 262 | $shortcodes = array(); |
263 | - foreach ( $valid_shortcodes as $field => $validators ) { |
|
264 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
263 | + foreach ($valid_shortcodes as $field => $validators) { |
|
264 | + $shortcodes[$field] = $validators['shortcodes']; |
|
265 | 265 | } |
266 | 266 | $valid_shortcodes = $shortcodes; |
267 | 267 | |
268 | 268 | //if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
269 | - if ( ! empty( $fields ) ) { |
|
269 | + if ( ! empty($fields)) { |
|
270 | 270 | $specified_shortcodes = array(); |
271 | - foreach ( $fields as $field ) { |
|
272 | - if ( isset( $valid_shortcodes[ $field ] ) ) { |
|
273 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
271 | + foreach ($fields as $field) { |
|
272 | + if (isset($valid_shortcodes[$field])) { |
|
273 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | $valid_shortcodes = $specified_shortcodes; |
277 | 277 | } |
278 | 278 | |
279 | 279 | //if not merged then let's replace the fields with the localized fields |
280 | - if ( ! $merged ) { |
|
280 | + if ( ! $merged) { |
|
281 | 281 | //let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
282 | 282 | $field_settings = $messenger->get_template_fields(); |
283 | 283 | $localized = array(); |
284 | - foreach ( $valid_shortcodes as $field => $shortcodes ) { |
|
284 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
285 | 285 | //get localized field label |
286 | - if ( isset( $field_settings[ $field ] ) ) { |
|
286 | + if (isset($field_settings[$field])) { |
|
287 | 287 | //possible that this is used as a main field. |
288 | - if ( empty( $field_settings[ $field ] ) ) { |
|
289 | - if ( isset( $field_settings['extra'][ $field ] ) ) { |
|
290 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
288 | + if (empty($field_settings[$field])) { |
|
289 | + if (isset($field_settings['extra'][$field])) { |
|
290 | + $_field = $field_settings['extra'][$field]['main']['label']; |
|
291 | 291 | } else { |
292 | 292 | $_field = $field; |
293 | 293 | } |
294 | 294 | } else { |
295 | - $_field = $field_settings[ $field ]['label']; |
|
295 | + $_field = $field_settings[$field]['label']; |
|
296 | 296 | } |
297 | - } else if ( isset( $field_settings['extra'] ) ) { |
|
297 | + } else if (isset($field_settings['extra'])) { |
|
298 | 298 | //loop through extra "main fields" and see if any of their children have our field |
299 | - foreach ( $field_settings['extra'] as $main_field => $fields ) { |
|
300 | - if ( isset( $fields[ $field ] ) ) { |
|
301 | - $_field = $fields[ $field ]['label']; |
|
299 | + foreach ($field_settings['extra'] as $main_field => $fields) { |
|
300 | + if (isset($fields[$field])) { |
|
301 | + $_field = $fields[$field]['label']; |
|
302 | 302 | } else { |
303 | 303 | $_field = $field; |
304 | 304 | } |
@@ -306,22 +306,22 @@ discard block |
||
306 | 306 | } else { |
307 | 307 | $_field = $field; |
308 | 308 | } |
309 | - if ( isset( $_field ) ) { |
|
310 | - $localized[ $_field ] = $shortcodes; |
|
309 | + if (isset($_field)) { |
|
310 | + $localized[$_field] = $shortcodes; |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | $valid_shortcodes = $localized; |
314 | 314 | } |
315 | 315 | |
316 | 316 | //if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
317 | - if ( $merged ) { |
|
317 | + if ($merged) { |
|
318 | 318 | $merged_codes = array(); |
319 | - foreach ( $valid_shortcodes as $field => $shortcode ) { |
|
320 | - foreach ( $shortcode as $code => $label ) { |
|
321 | - if ( isset( $merged_codes[ $code ] ) ) { |
|
319 | + foreach ($valid_shortcodes as $field => $shortcode) { |
|
320 | + foreach ($shortcode as $code => $label) { |
|
321 | + if (isset($merged_codes[$code])) { |
|
322 | 322 | continue; |
323 | 323 | } else { |
324 | - $merged_codes[ $code ] = $label; |
|
324 | + $merged_codes[$code] = $label; |
|
325 | 325 | } |
326 | 326 | } |
327 | 327 | } |
@@ -341,10 +341,10 @@ discard block |
||
341 | 341 | * @throws \EE_Error |
342 | 342 | * @return EE_messenger |
343 | 343 | */ |
344 | - public static function messenger_obj( $messenger ) { |
|
344 | + public static function messenger_obj($messenger) { |
|
345 | 345 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
346 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
347 | - return $Message_Resource_Manager->get_messenger( $messenger ); |
|
346 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
347 | + return $Message_Resource_Manager->get_messenger($messenger); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @throws \EE_Error |
358 | 358 | * @return EE_message_type |
359 | 359 | */ |
360 | - public static function message_type_obj( $message_type ) { |
|
360 | + public static function message_type_obj($message_type) { |
|
361 | 361 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
362 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
363 | - return $Message_Resource_Manager->get_message_type( $message_type ); |
|
362 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
363 | + return $Message_Resource_Manager->get_message_type($message_type); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -374,11 +374,11 @@ discard block |
||
374 | 374 | * @param string $message_type message type to check for. |
375 | 375 | * @return boolean |
376 | 376 | */ |
377 | - public static function is_mt_active( $message_type ) { |
|
377 | + public static function is_mt_active($message_type) { |
|
378 | 378 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
379 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
379 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
380 | 380 | $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
381 | - return in_array( $message_type, $active_mts ); |
|
381 | + return in_array($message_type, $active_mts); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | |
@@ -391,10 +391,10 @@ discard block |
||
391 | 391 | * @param string $messenger slug for messenger to check. |
392 | 392 | * @return boolean |
393 | 393 | */ |
394 | - public static function is_messenger_active( $messenger ) { |
|
394 | + public static function is_messenger_active($messenger) { |
|
395 | 395 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
396 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
397 | - $active_messenger = $Message_Resource_Manager->get_active_messenger( $messenger ); |
|
396 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
397 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
398 | 398 | return $active_messenger instanceof EE_messenger ? true : false; |
399 | 399 | } |
400 | 400 | |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | public static function get_active_messengers_in_db() { |
413 | 413 | EE_Error::doing_it_wrong( |
414 | 414 | __METHOD__, |
415 | - __( 'Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso' ), |
|
415 | + __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
416 | 416 | '4.9.0' |
417 | 417 | ); |
418 | 418 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
419 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
419 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
420 | 420 | return $Message_Resource_Manager->get_active_messengers_option(); |
421 | 421 | } |
422 | 422 | |
@@ -433,15 +433,15 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @return bool FALSE if not updated, TRUE if updated. |
435 | 435 | */ |
436 | - public static function update_active_messengers_in_db( $data_to_save ) { |
|
436 | + public static function update_active_messengers_in_db($data_to_save) { |
|
437 | 437 | EE_Error::doing_it_wrong( |
438 | 438 | __METHOD__, |
439 | - __( 'Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso' ), |
|
439 | + __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
440 | 440 | '4.9.0' |
441 | 441 | ); |
442 | 442 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
443 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
444 | - return $Message_Resource_Manager->update_active_messengers_option( $data_to_save ); |
|
443 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
444 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | |
@@ -465,34 +465,34 @@ discard block |
||
465 | 465 | $sending_messenger = '' |
466 | 466 | ) { |
467 | 467 | //first determine if the url can be to the EE_Message object. |
468 | - if ( ! $message_type->always_generate() ) { |
|
469 | - return EEH_MSG_Template::generate_browser_trigger( $message ); |
|
468 | + if ( ! $message_type->always_generate()) { |
|
469 | + return EEH_MSG_Template::generate_browser_trigger($message); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | //if $registration object is not valid then exit early because there's nothing that can be generated. |
473 | - if ( ! $registration instanceof EE_Registration ) { |
|
473 | + if ( ! $registration instanceof EE_Registration) { |
|
474 | 474 | throw new EE_Error( |
475 | - __( 'Incoming value for registration is not a valid EE_Registration object.', 'event_espresso' ) |
|
475 | + __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
476 | 476 | ); |
477 | 477 | } |
478 | 478 | |
479 | 479 | //validate given context |
480 | 480 | $contexts = $message_type->get_contexts(); |
481 | - if ( $message->context() !== '' && ! isset( $contexts[$message->context()] ) ) { |
|
481 | + if ($message->context() !== '' && ! isset($contexts[$message->context()])) { |
|
482 | 482 | throw new EE_Error( |
483 | 483 | sprintf( |
484 | - __( 'The context %s is not a valid context for %s.', 'event_espresso' ), |
|
484 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
485 | 485 | $message->context(), |
486 | - get_class( $message_type ) |
|
486 | + get_class($message_type) |
|
487 | 487 | ) |
488 | 488 | ); |
489 | 489 | } |
490 | 490 | |
491 | 491 | //valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
492 | - if ( ! empty( $sending_messenger ) ) { |
|
492 | + if ( ! empty($sending_messenger)) { |
|
493 | 493 | $with_messengers = $message_type->with_messengers(); |
494 | - if ( ! isset( $with_messengers[$message->messenger()] ) |
|
495 | - || ! in_array( $sending_messenger, $with_messengers[$message->messenger()] ) ) { |
|
494 | + if ( ! isset($with_messengers[$message->messenger()]) |
|
495 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()])) { |
|
496 | 496 | throw new EE_Error( |
497 | 497 | sprintf( |
498 | 498 | __( |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | 'event_espresso' |
501 | 501 | ), |
502 | 502 | $sending_messenger, |
503 | - get_class( $message_type ) |
|
503 | + get_class($message_type) |
|
504 | 504 | ) |
505 | 505 | ); |
506 | 506 | } |
@@ -523,14 +523,14 @@ discard block |
||
523 | 523 | * @param EE_Message $message |
524 | 524 | * @return string. |
525 | 525 | */ |
526 | - public static function generate_browser_trigger( EE_Message $message ) { |
|
526 | + public static function generate_browser_trigger(EE_Message $message) { |
|
527 | 527 | $query_args = array( |
528 | 528 | 'ee' => 'msg_browser_trigger', |
529 | 529 | 'token' => $message->MSG_token() |
530 | 530 | ); |
531 | 531 | return apply_filters( |
532 | 532 | 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
533 | - add_query_arg( $query_args, site_url() ), |
|
533 | + add_query_arg($query_args, site_url()), |
|
534 | 534 | $message |
535 | 535 | ); |
536 | 536 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param EE_Message $message |
546 | 546 | * @return string |
547 | 547 | */ |
548 | - public static function generate_error_display_trigger( EE_Message $message ) { |
|
548 | + public static function generate_error_display_trigger(EE_Message $message) { |
|
549 | 549 | return apply_filters( |
550 | 550 | 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
551 | 551 | add_query_arg( |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | 'GRP_ID' => $message_template_group, |
596 | 596 | 'id' => $data_id |
597 | 597 | ); |
598 | - $url = add_query_arg( $query_args, get_home_url() ); |
|
598 | + $url = add_query_arg($query_args, get_home_url()); |
|
599 | 599 | |
600 | 600 | //made it here so now we can just get the url and filter it. Filtered globally and by message type. |
601 | 601 | $url = apply_filters( |
@@ -623,9 +623,9 @@ discard block |
||
623 | 623 | * @param string $type What action to return. |
624 | 624 | * @return string |
625 | 625 | */ |
626 | - public static function get_message_action_icon( $type ) { |
|
626 | + public static function get_message_action_icon($type) { |
|
627 | 627 | $action_icons = self::get_message_action_icons(); |
628 | - return isset( $action_icons[ $type ] ) ? $action_icons[ $type ] : ''; |
|
628 | + return isset($action_icons[$type]) ? $action_icons[$type] : ''; |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | |
@@ -637,34 +637,34 @@ discard block |
||
637 | 637 | * @return array |
638 | 638 | */ |
639 | 639 | public static function get_message_action_icons() { |
640 | - return apply_filters( 'FHEE__EEH_MSG_Template__message_action_icons', |
|
640 | + return apply_filters('FHEE__EEH_MSG_Template__message_action_icons', |
|
641 | 641 | array( |
642 | 642 | 'view' => array( |
643 | - 'label' => __( 'View Message', 'event_espresso' ), |
|
643 | + 'label' => __('View Message', 'event_espresso'), |
|
644 | 644 | 'css_class' => 'dashicons dashicons-welcome-view-site', |
645 | 645 | ), |
646 | 646 | 'error' => array( |
647 | - 'label' => __( 'View Error Message', 'event_espresso' ), |
|
647 | + 'label' => __('View Error Message', 'event_espresso'), |
|
648 | 648 | 'css_class' => 'dashicons dashicons-info', |
649 | 649 | ), |
650 | 650 | 'see_notifications_for' => array( |
651 | - 'label' => __( 'View Related Messages', 'event_espresso' ), |
|
651 | + 'label' => __('View Related Messages', 'event_espresso'), |
|
652 | 652 | 'css_class' => 'dashicons dashicons-megaphone', |
653 | 653 | ), |
654 | 654 | 'generate_now' => array( |
655 | - 'label' => __( 'Generate the message now.', 'event_espresso' ), |
|
655 | + 'label' => __('Generate the message now.', 'event_espresso'), |
|
656 | 656 | 'css_class' => 'dashicons dashicons-admin-tools', |
657 | 657 | ), |
658 | 658 | 'send_now' => array( |
659 | - 'label' => __( 'Send Immediately', 'event_espresso' ), |
|
659 | + 'label' => __('Send Immediately', 'event_espresso'), |
|
660 | 660 | 'css_class' => 'dashicons dashicons-controls-forward', |
661 | 661 | ), |
662 | 662 | 'queue_for_resending' => array( |
663 | - 'label' => __( 'Queue for Resending', 'event_espresso' ), |
|
663 | + 'label' => __('Queue for Resending', 'event_espresso'), |
|
664 | 664 | 'css_class' => 'dashicons dashicons-controls-repeat', |
665 | 665 | ), |
666 | 666 | 'view_transaction' => array( |
667 | - 'label' => __( 'View related Transaction', 'event_espresso' ), |
|
667 | + 'label' => __('View related Transaction', 'event_espresso'), |
|
668 | 668 | 'css_class' => 'dashicons dashicons-cart', |
669 | 669 | ) |
670 | 670 | ) |
@@ -683,9 +683,9 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | - public static function get_message_action_url( $type, EE_Message $message = null, $query_params = array() ) { |
|
687 | - $action_urls = self::get_message_action_urls( $message, $query_params ); |
|
688 | - return isset( $action_urls[ $type ] ) ? $action_urls[ $type ] : ''; |
|
686 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) { |
|
687 | + $action_urls = self::get_message_action_urls($message, $query_params); |
|
688 | + return isset($action_urls[$type]) ? $action_urls[$type] : ''; |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | |
@@ -700,15 +700,15 @@ discard block |
||
700 | 700 | * |
701 | 701 | * @return array |
702 | 702 | */ |
703 | - public static function get_message_action_urls( EE_Message $message = null, $query_params = array() ) { |
|
704 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
703 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) { |
|
704 | + EE_Registry::instance()->load_helper('URL'); |
|
705 | 705 | //if $message is not an instance of EE_Message then let's just do a dummy. |
706 | - $message = empty( $message ) ? EE_Message_Factory::create() : $message; |
|
707 | - $action_urls = apply_filters( |
|
706 | + $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
707 | + $action_urls = apply_filters( |
|
708 | 708 | 'FHEE__EEH_MSG_Template__get_message_action_url', |
709 | 709 | array( |
710 | - 'view' => EEH_MSG_Template::generate_browser_trigger( $message ), |
|
711 | - 'error' => EEH_MSG_Template::generate_error_display_trigger( $message ), |
|
710 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
711 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
712 | 712 | 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
713 | 713 | array_merge( |
714 | 714 | array( |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | ), |
719 | 719 | $query_params |
720 | 720 | ), |
721 | - admin_url( 'admin.php' ) |
|
721 | + admin_url('admin.php') |
|
722 | 722 | ), |
723 | 723 | 'generate_now' => EEH_URL::add_query_args_and_nonce( |
724 | 724 | array( |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | 'action' => 'generate_now', |
727 | 727 | 'MSG_ID' => $message->ID() |
728 | 728 | ), |
729 | - admin_url( 'admin.php' ) |
|
729 | + admin_url('admin.php') |
|
730 | 730 | ), |
731 | 731 | 'send_now' => EEH_URL::add_query_args_and_nonce( |
732 | 732 | array( |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | 'action' => 'send_now', |
735 | 735 | 'MSG_ID' => $message->ID() |
736 | 736 | ), |
737 | - admin_url( 'admin.php' ) |
|
737 | + admin_url('admin.php') |
|
738 | 738 | ), |
739 | 739 | 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
740 | 740 | array( |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | 'action' => 'queue_for_resending', |
743 | 743 | 'MSG_ID' => $message->ID() |
744 | 744 | ), |
745 | - admin_url( 'admin.php' ) |
|
745 | + admin_url('admin.php') |
|
746 | 746 | ), |
747 | 747 | ) |
748 | 748 | ); |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | 'action' => 'view_transaction', |
761 | 761 | 'TXN_ID' => $message->TXN_ID() |
762 | 762 | ), |
763 | - admin_url( 'admin.php' ) |
|
763 | + admin_url('admin.php') |
|
764 | 764 | ); |
765 | 765 | } else { |
766 | 766 | $action_urls['view_transaction'] = ''; |
@@ -781,26 +781,26 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @return string |
783 | 783 | */ |
784 | - public static function get_message_action_link( $type, EE_Message $message = null, $query_params = array() ) { |
|
785 | - $url = EEH_MSG_Template::get_message_action_url( $type, $message, $query_params ); |
|
786 | - $icon_css = EEH_MSG_Template::get_message_action_icon( $type ); |
|
787 | - $title = isset( $icon_css['label'] ) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
784 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) { |
|
785 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
786 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
787 | + $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : ''; |
|
788 | 788 | |
789 | - if ( empty( $url ) || empty( $icon_css ) || ! isset( $icon_css['css_class'] ) ) { |
|
789 | + if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
790 | 790 | return ''; |
791 | 791 | } |
792 | 792 | |
793 | 793 | $icon_css['css_class'] .= esc_attr( |
794 | 794 | apply_filters( |
795 | 795 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
796 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
796 | + ' js-ee-message-action-link ee-message-action-link-'.$type, |
|
797 | 797 | $type, |
798 | 798 | $message, |
799 | 799 | $query_params |
800 | 800 | ) |
801 | 801 | ); |
802 | 802 | |
803 | - return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr( $icon_css['css_class'] ) . '"></span></a>'; |
|
803 | + return '<a href="'.$url.'"'.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>'; |
|
804 | 804 | |
805 | 805 | } |
806 | 806 | |
@@ -838,9 +838,9 @@ discard block |
||
838 | 838 | * @param $reg_status |
839 | 839 | * @return string |
840 | 840 | */ |
841 | - public static function convert_reg_status_to_message_type( $reg_status ) { |
|
841 | + public static function convert_reg_status_to_message_type($reg_status) { |
|
842 | 842 | $reg_status_array = self::reg_status_to_message_type_array(); |
843 | - return isset( $reg_status_array[$reg_status] ) ? $reg_status_array[$reg_status] : ''; |
|
843 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : ''; |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | |
@@ -874,9 +874,9 @@ discard block |
||
874 | 874 | * @param $payment_status |
875 | 875 | * @return string |
876 | 876 | */ |
877 | - public static function convert_payment_status_to_message_type( $payment_status ) { |
|
877 | + public static function convert_payment_status_to_message_type($payment_status) { |
|
878 | 878 | $payment_status_array = self::payment_status_to_message_type_array(); |
879 | - return isset( $payment_status_array[$payment_status] ) ? $payment_status_array[$payment_status] : ''; |
|
879 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : ''; |
|
880 | 880 | } |
881 | 881 | |
882 | 882 | |
@@ -887,32 +887,32 @@ discard block |
||
887 | 887 | * |
888 | 888 | * @return EE_Messages_Template_Pack |
889 | 889 | */ |
890 | - public static function get_template_pack( $template_pack_name ) { |
|
891 | - if ( ! self::$_template_pack_collection instanceof EE_Object_Collection ) { |
|
890 | + public static function get_template_pack($template_pack_name) { |
|
891 | + if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
892 | 892 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
893 | 893 | } |
894 | 894 | |
895 | 895 | //first see if in collection already |
896 | - $template_pack = self::$_template_pack_collection->get_by_name( $template_pack_name ); |
|
896 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
897 | 897 | |
898 | - if ( $template_pack instanceof EE_Messages_Template_Pack ) { |
|
898 | + if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
899 | 899 | return $template_pack; |
900 | 900 | } |
901 | 901 | |
902 | 902 | //nope...let's get it. |
903 | 903 | //not set yet so let's attempt to get it. |
904 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
904 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
905 | 905 | ' ', |
906 | 906 | '_', |
907 | 907 | ucwords( |
908 | - str_replace( '_', ' ', $template_pack_name ) |
|
908 | + str_replace('_', ' ', $template_pack_name) |
|
909 | 909 | ) |
910 | 910 | ); |
911 | - if ( ! class_exists( $pack_class_name ) && $template_pack_name !== 'default' ) { |
|
912 | - return self::get_template_pack( 'default' ); |
|
911 | + if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
912 | + return self::get_template_pack('default'); |
|
913 | 913 | } else { |
914 | 914 | $template_pack = new $pack_class_name; |
915 | - self::$_template_pack_collection->add( $template_pack ); |
|
915 | + self::$_template_pack_collection->add($template_pack); |
|
916 | 916 | return $template_pack; |
917 | 917 | } |
918 | 918 | } |
@@ -930,26 +930,26 @@ discard block |
||
930 | 930 | */ |
931 | 931 | public static function get_template_pack_collection() { |
932 | 932 | $new_collection = false; |
933 | - if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection ) { |
|
933 | + if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
934 | 934 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
935 | 935 | $new_collection = true; |
936 | 936 | } |
937 | 937 | |
938 | 938 | //glob the defaults directory for messages |
939 | - $templates = glob( EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR ); |
|
940 | - foreach( $templates as $template_path ) { |
|
939 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR); |
|
940 | + foreach ($templates as $template_path) { |
|
941 | 941 | //grab folder name |
942 | - $template = basename( $template_path ); |
|
942 | + $template = basename($template_path); |
|
943 | 943 | |
944 | - if ( ! $new_collection ) { |
|
944 | + if ( ! $new_collection) { |
|
945 | 945 | //already have it? |
946 | - if ( self::$_template_pack_collection->get_by_name( $template ) instanceof EE_Messages_Template_Pack ) { |
|
946 | + if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
947 | 947 | continue; |
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | 951 | //setup classname. |
952 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
952 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
953 | 953 | ' ', |
954 | 954 | '_', |
955 | 955 | ucwords( |
@@ -960,20 +960,20 @@ discard block |
||
960 | 960 | ) |
961 | 961 | ) |
962 | 962 | ); |
963 | - if ( ! class_exists( $template_pack_class_name ) ) { |
|
963 | + if ( ! class_exists($template_pack_class_name)) { |
|
964 | 964 | continue; |
965 | 965 | } |
966 | - self::$_template_pack_collection->add( new $template_pack_class_name ); |
|
966 | + self::$_template_pack_collection->add(new $template_pack_class_name); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | /** |
970 | 970 | * Filter for plugins to add in any additional template packs |
971 | 971 | * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
972 | 972 | */ |
973 | - $additional_template_packs = apply_filters( 'FHEE__EED_Messages__get_template_packs__template_packs', array() ); |
|
974 | - foreach ( (array) $additional_template_packs as $template_pack ) { |
|
975 | - if ( ! self::$_template_pack_collection->contains($template_pack ) ) { |
|
976 | - self::$_template_pack_collection->add( $template_pack ); |
|
973 | + $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
974 | + foreach ((array) $additional_template_packs as $template_pack) { |
|
975 | + if ( ! self::$_template_pack_collection->contains($template_pack)) { |
|
976 | + self::$_template_pack_collection->add($template_pack); |
|
977 | 977 | } |
978 | 978 | } |
979 | 979 | return self::$_template_pack_collection; |
@@ -991,16 +991,16 @@ discard block |
||
991 | 991 | * @return array |
992 | 992 | * @throws \EE_Error |
993 | 993 | */ |
994 | - public static function create_new_templates( $messenger_name, $message_type_name, $GRP_ID = 0, $global = false ) { |
|
994 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) { |
|
995 | 995 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
996 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
997 | - $messenger = $Message_Resource_Manager->valid_messenger( $messenger_name ); |
|
998 | - $message_type = $Message_Resource_Manager->valid_message_type( $message_type_name ); |
|
999 | - if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger( $messenger, $message_type, $global ) ) { |
|
996 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
997 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
998 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
999 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
1000 | 1000 | return array(); |
1001 | 1001 | } |
1002 | 1002 | //whew made it this far! Okay, let's go ahead and create the templates then |
1003 | - return EEH_MSG_Template::_create_new_templates( $messenger, $message_type, $GRP_ID, $global ); |
|
1003 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | |
@@ -1012,15 +1012,15 @@ discard block |
||
1012 | 1012 | * @param $global |
1013 | 1013 | * @return array|mixed |
1014 | 1014 | */ |
1015 | - protected static function _create_new_templates( EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global ) { |
|
1015 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) { |
|
1016 | 1016 | //if we're creating a custom template then we don't need to use the defaults class |
1017 | - if ( ! $global ) { |
|
1018 | - return EEH_MSG_Template::_create_custom_template_group( $messenger, $message_type, $GRP_ID ); |
|
1017 | + if ( ! $global) { |
|
1018 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
1019 | 1019 | } |
1020 | 1020 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
1021 | 1021 | $Message_Template_Defaults = EE_Registry::factory( |
1022 | 1022 | 'EE_Messages_Template_Defaults', |
1023 | - array( $messenger, $message_type, $GRP_ID ) |
|
1023 | + array($messenger, $message_type, $GRP_ID) |
|
1024 | 1024 | ); |
1025 | 1025 | //generate templates |
1026 | 1026 | $success = $Message_Template_Defaults->create_new_templates(); |
@@ -1028,10 +1028,10 @@ discard block |
||
1028 | 1028 | //if creating the template failed. Then we should deactivate the related message_type for the messenger because |
1029 | 1029 | //its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
1030 | 1030 | //attempts. |
1031 | - if ( ! $success ) { |
|
1031 | + if ( ! $success) { |
|
1032 | 1032 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
1033 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
1034 | - $message_resource_manager->deactivate_message_type_for_messenger( $message_type->name, $messenger->name ); |
|
1033 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1034 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | /** |
@@ -1059,11 +1059,11 @@ discard block |
||
1059 | 1059 | * ) |
1060 | 1060 | * @access private |
1061 | 1061 | */ |
1062 | - private static function _create_custom_template_group( EE_messenger $messenger, EE_message_type $message_type, $GRP_ID ) { |
|
1062 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) { |
|
1063 | 1063 | //defaults |
1064 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
1064 | + $success = array('GRP_ID' => null, 'MTP_context' => ''); |
|
1065 | 1065 | //get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
1066 | - $Message_Template_Group = empty( $GRP_ID ) |
|
1066 | + $Message_Template_Group = empty($GRP_ID) |
|
1067 | 1067 | ? EEM_Message_Template_Group::instance()->get_one( |
1068 | 1068 | array( |
1069 | 1069 | array( |
@@ -1073,9 +1073,9 @@ discard block |
||
1073 | 1073 | ) |
1074 | 1074 | ) |
1075 | 1075 | ) |
1076 | - : EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
1076 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
1077 | 1077 | //if we don't have a mtg at this point then we need to bail. |
1078 | - if ( ! $Message_Template_Group instanceof EE_Message_Template_Group ) { |
|
1078 | + if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
1079 | 1079 | EE_Error::add_error( |
1080 | 1080 | sprintf( |
1081 | 1081 | __( |
@@ -1094,42 +1094,42 @@ discard block |
||
1094 | 1094 | $message_templates = $Message_Template_Group->message_templates(); |
1095 | 1095 | //now we have what we need to setup the new template |
1096 | 1096 | $new_mtg = clone $Message_Template_Group; |
1097 | - $new_mtg->set( 'GRP_ID', 0 ); |
|
1098 | - $new_mtg->set( 'MTP_is_global', false ); |
|
1099 | - $template_name = defined( 'DOING_AJAX' ) && ! empty( $_POST[ 'templateName' ] ) |
|
1100 | - ? $_POST[ 'templateName' ] |
|
1097 | + $new_mtg->set('GRP_ID', 0); |
|
1098 | + $new_mtg->set('MTP_is_global', false); |
|
1099 | + $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName']) |
|
1100 | + ? $_POST['templateName'] |
|
1101 | 1101 | : __( |
1102 | 1102 | 'New Custom Template', |
1103 | 1103 | 'event_espresso' |
1104 | 1104 | ); |
1105 | - $template_description = defined( "DOING_AJAX" ) && ! empty( $_POST[ 'templateDescription' ] ) |
|
1106 | - ? $_POST[ 'templateDescription' ] |
|
1105 | + $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription']) |
|
1106 | + ? $_POST['templateDescription'] |
|
1107 | 1107 | : sprintf( |
1108 | 1108 | __( |
1109 | 1109 | 'This is a custom template that was created for the %s messenger and %s message type.', |
1110 | 1110 | 'event_espresso' |
1111 | 1111 | ), |
1112 | - $new_mtg->messenger_obj()->label[ 'singular' ], |
|
1113 | - $new_mtg->message_type_obj()->label[ 'singular' ] |
|
1112 | + $new_mtg->messenger_obj()->label['singular'], |
|
1113 | + $new_mtg->message_type_obj()->label['singular'] |
|
1114 | 1114 | ); |
1115 | - $new_mtg->set( 'MTP_name', $template_name ); |
|
1116 | - $new_mtg->set( 'MTP_description', $template_description ); |
|
1115 | + $new_mtg->set('MTP_name', $template_name); |
|
1116 | + $new_mtg->set('MTP_description', $template_description); |
|
1117 | 1117 | //remove ALL relations on this template group so they don't get saved! |
1118 | - $new_mtg->_remove_relations( 'Message_Template' ); |
|
1118 | + $new_mtg->_remove_relations('Message_Template'); |
|
1119 | 1119 | $new_mtg->save(); |
1120 | - $success[ 'GRP_ID' ] = $new_mtg->ID(); |
|
1121 | - $success[ 'template_name' ] = $template_name; |
|
1120 | + $success['GRP_ID'] = $new_mtg->ID(); |
|
1121 | + $success['template_name'] = $template_name; |
|
1122 | 1122 | //add new message templates and add relation to. |
1123 | - foreach ( $message_templates as $message_template ) { |
|
1124 | - if ( ! $message_template instanceof EE_Message_Template ) { |
|
1123 | + foreach ($message_templates as $message_template) { |
|
1124 | + if ( ! $message_template instanceof EE_Message_Template) { |
|
1125 | 1125 | continue; |
1126 | 1126 | } |
1127 | 1127 | $new_message_template = clone $message_template; |
1128 | - $new_message_template->set( 'MTP_ID', 0 ); |
|
1129 | - $new_message_template->set( 'GRP_ID', $new_mtg->ID() ); //relation |
|
1128 | + $new_message_template->set('MTP_ID', 0); |
|
1129 | + $new_message_template->set('GRP_ID', $new_mtg->ID()); //relation |
|
1130 | 1130 | $new_message_template->save(); |
1131 | - if ( empty( $success[ 'MTP_context' ] ) ) { |
|
1132 | - $success[ 'MTP_context' ] = $new_message_template->get( 'MTP_context' ); |
|
1131 | + if (empty($success['MTP_context'])) { |
|
1132 | + $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | return $success; |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | $global = false |
1152 | 1152 | ) { |
1153 | 1153 | //is given message_type valid for given messenger (if this is not a global save) |
1154 | - if ( $global ) { |
|
1154 | + if ($global) { |
|
1155 | 1155 | return true; |
1156 | 1156 | } |
1157 | 1157 | $active_templates = EEM_Message_Template_Group::instance()->count( |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | ) |
1164 | 1164 | ) |
1165 | 1165 | ); |
1166 | - if ( $active_templates > 0 ) { |
|
1166 | + if ($active_templates > 0) { |
|
1167 | 1167 | return true; |
1168 | 1168 | } |
1169 | 1169 | EE_Error::add_error( |
@@ -1192,30 +1192,30 @@ discard block |
||
1192 | 1192 | * @param string $message_type_name name of EE_message_type |
1193 | 1193 | * @return array |
1194 | 1194 | */ |
1195 | - public static function get_fields( $messenger_name, $message_type_name ) { |
|
1195 | + public static function get_fields($messenger_name, $message_type_name) { |
|
1196 | 1196 | $template_fields = array(); |
1197 | 1197 | /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
1198 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
1199 | - $messenger = $Message_Resource_Manager->valid_messenger( $messenger_name ); |
|
1200 | - $message_type = $Message_Resource_Manager->valid_message_type( $message_type_name ); |
|
1201 | - if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger( $messenger, $message_type ) ) { |
|
1198 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1199 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
1200 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
1201 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
1202 | 1202 | return array(); |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
1206 | 1206 | |
1207 | 1207 | //okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
1208 | - foreach ( $message_type->get_contexts() as $context => $details ) { |
|
1209 | - foreach ( $messenger->get_template_fields() as $field => $value ) { |
|
1208 | + foreach ($message_type->get_contexts() as $context => $details) { |
|
1209 | + foreach ($messenger->get_template_fields() as $field => $value) { |
|
1210 | 1210 | if (in_array($field, $excluded_fields_for_messenger, true)) { |
1211 | 1211 | continue; |
1212 | 1212 | } |
1213 | - $template_fields[ $context ][ $field ] = $value; |
|
1213 | + $template_fields[$context][$field] = $value; |
|
1214 | 1214 | } |
1215 | 1215 | } |
1216 | - if ( empty( $template_fields ) ) { |
|
1216 | + if (empty($template_fields)) { |
|
1217 | 1217 | EE_Error::add_error( |
1218 | - __( 'Something went wrong and we couldn\'t get any templates assembled', 'event_espresso' ), |
|
1218 | + __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
1219 | 1219 | __FILE__, |
1220 | 1220 | __FUNCTION__, |
1221 | 1221 | __LINE__ |
@@ -52,234 +52,234 @@ |
||
52 | 52 | class BootstrapCore |
53 | 53 | { |
54 | 54 | |
55 | - /** |
|
56 | - * @type LoaderInterface $loader |
|
57 | - */ |
|
58 | - private $loader; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var RequestInterface $request |
|
62 | - */ |
|
63 | - protected $request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var ResponseInterface $response |
|
67 | - */ |
|
68 | - protected $response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var RequestStackBuilder $request_stack_builder |
|
72 | - */ |
|
73 | - protected $request_stack_builder; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var RequestStack $request_stack |
|
77 | - */ |
|
78 | - protected $request_stack; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * BootstrapCore constructor. |
|
83 | - */ |
|
84 | - public function __construct() |
|
85 | - { |
|
86 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
87 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @throws InvalidRequestStackMiddlewareException |
|
93 | - * @throws InvalidClassException |
|
94 | - * @throws DomainException |
|
95 | - * @throws EE_Error |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws ReflectionException |
|
100 | - */ |
|
101 | - public function initialize() |
|
102 | - { |
|
103 | - $this->bootstrapDependencyInjectionContainer(); |
|
104 | - $this->bootstrapDomain(); |
|
105 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
106 | - add_action( |
|
107 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
108 | - array($bootstrap_request, 'setupLegacyRequest') |
|
109 | - ); |
|
110 | - $this->runRequestStack(); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @throws ReflectionException |
|
116 | - * @throws EE_Error |
|
117 | - * @throws InvalidArgumentException |
|
118 | - * @throws InvalidDataTypeException |
|
119 | - * @throws InvalidInterfaceException |
|
120 | - */ |
|
121 | - private function bootstrapDependencyInjectionContainer() |
|
122 | - { |
|
123 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
124 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
125 | - $bootstrap_di->buildLoader(); |
|
126 | - $registry = $bootstrap_di->getRegistry(); |
|
127 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
128 | - $dependency_map->initialize(); |
|
129 | - $registry->initialize(); |
|
130 | - $this->loader = $bootstrap_di->getLoader(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * configures the Domain object for core |
|
136 | - * |
|
137 | - * @return void |
|
138 | - * @throws DomainException |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidClassException |
|
142 | - * @throws InvalidFilePathException |
|
143 | - * @throws InvalidInterfaceException |
|
144 | - */ |
|
145 | - private function bootstrapDomain() |
|
146 | - { |
|
147 | - DomainFactory::getShared( |
|
148 | - new FullyQualifiedName( |
|
149 | - 'EventEspresso\core\domain\Domain' |
|
150 | - ), |
|
151 | - array( |
|
152 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
153 | - Version::fromString(espresso_version()) |
|
154 | - ) |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * sets up the request and response objects |
|
161 | - * |
|
162 | - * @return BootstrapRequestResponseObjects |
|
163 | - * @throws InvalidArgumentException |
|
164 | - */ |
|
165 | - private function bootstrapRequestResponseObjects() |
|
166 | - { |
|
167 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
168 | - $bootstrap_request = $this->loader->getShared( |
|
169 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
170 | - array($this->loader) |
|
171 | - ); |
|
172 | - $bootstrap_request->buildRequestResponse(); |
|
173 | - $bootstrap_request->shareRequestResponse(); |
|
174 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
175 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
176 | - return $bootstrap_request; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * run_request_stack |
|
182 | - * construct request stack and run middleware apps |
|
183 | - * |
|
184 | - * @throws InvalidRequestStackMiddlewareException |
|
185 | - * @throws InvalidInterfaceException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public function runRequestStack() |
|
190 | - { |
|
191 | - $this->loadAutoloader(); |
|
192 | - $this->setAutoloadersForRequiredFiles(); |
|
193 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
194 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
195 | - new RequestStackCoreApp() |
|
196 | - ); |
|
197 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
198 | - $this->request_stack->handleResponse(); |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * load_autoloader |
|
204 | - * |
|
205 | - * @throws EE_Error |
|
206 | - */ |
|
207 | - protected function loadAutoloader() |
|
208 | - { |
|
209 | - // load interfaces |
|
210 | - espresso_load_required( |
|
211 | - 'EEH_Autoloader', |
|
212 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
213 | - ); |
|
214 | - EEH_Autoloader::instance(); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * load_required_files |
|
221 | - * |
|
222 | - * @throws EE_Error |
|
223 | - */ |
|
224 | - protected function setAutoloadersForRequiredFiles() |
|
225 | - { |
|
226 | - // load interfaces |
|
227 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
228 | - // load helpers |
|
229 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
230 | - // load request stack |
|
231 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
232 | - // load middleware |
|
233 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * build_request_stack |
|
240 | - * |
|
241 | - * @return RequestStackBuilder |
|
242 | - */ |
|
243 | - public function buildRequestStack() |
|
244 | - { |
|
245 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
246 | - /** |
|
247 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
248 | - * so items at the beginning of the final middleware stack will run last. |
|
249 | - * First parameter is the middleware classname, second is an array of arguments |
|
250 | - */ |
|
251 | - $stack_apps = apply_filters( |
|
252 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
253 | - array( |
|
254 | - // first in last out |
|
255 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
256 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
257 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
258 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
259 | - // last in first out |
|
260 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
261 | - ) |
|
262 | - ); |
|
263 | - // legacy filter for backwards compatibility |
|
264 | - $stack_apps = apply_filters( |
|
265 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
266 | - $stack_apps |
|
267 | - ); |
|
268 | - // load middleware onto stack : FILO (First In Last Out) |
|
269 | - // items at the beginning of the $stack_apps array will run last |
|
270 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
271 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
272 | - } |
|
273 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
274 | - // and we also need it to always run first because the rest of the system relies on it |
|
275 | - $request_stack_builder->push( |
|
276 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
277 | - ); |
|
278 | - return apply_filters( |
|
279 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
280 | - $request_stack_builder |
|
281 | - ); |
|
282 | - } |
|
55 | + /** |
|
56 | + * @type LoaderInterface $loader |
|
57 | + */ |
|
58 | + private $loader; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var RequestInterface $request |
|
62 | + */ |
|
63 | + protected $request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var ResponseInterface $response |
|
67 | + */ |
|
68 | + protected $response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var RequestStackBuilder $request_stack_builder |
|
72 | + */ |
|
73 | + protected $request_stack_builder; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var RequestStack $request_stack |
|
77 | + */ |
|
78 | + protected $request_stack; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * BootstrapCore constructor. |
|
83 | + */ |
|
84 | + public function __construct() |
|
85 | + { |
|
86 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
87 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @throws InvalidRequestStackMiddlewareException |
|
93 | + * @throws InvalidClassException |
|
94 | + * @throws DomainException |
|
95 | + * @throws EE_Error |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws ReflectionException |
|
100 | + */ |
|
101 | + public function initialize() |
|
102 | + { |
|
103 | + $this->bootstrapDependencyInjectionContainer(); |
|
104 | + $this->bootstrapDomain(); |
|
105 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
106 | + add_action( |
|
107 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
108 | + array($bootstrap_request, 'setupLegacyRequest') |
|
109 | + ); |
|
110 | + $this->runRequestStack(); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @throws ReflectionException |
|
116 | + * @throws EE_Error |
|
117 | + * @throws InvalidArgumentException |
|
118 | + * @throws InvalidDataTypeException |
|
119 | + * @throws InvalidInterfaceException |
|
120 | + */ |
|
121 | + private function bootstrapDependencyInjectionContainer() |
|
122 | + { |
|
123 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
124 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
125 | + $bootstrap_di->buildLoader(); |
|
126 | + $registry = $bootstrap_di->getRegistry(); |
|
127 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
128 | + $dependency_map->initialize(); |
|
129 | + $registry->initialize(); |
|
130 | + $this->loader = $bootstrap_di->getLoader(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * configures the Domain object for core |
|
136 | + * |
|
137 | + * @return void |
|
138 | + * @throws DomainException |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidClassException |
|
142 | + * @throws InvalidFilePathException |
|
143 | + * @throws InvalidInterfaceException |
|
144 | + */ |
|
145 | + private function bootstrapDomain() |
|
146 | + { |
|
147 | + DomainFactory::getShared( |
|
148 | + new FullyQualifiedName( |
|
149 | + 'EventEspresso\core\domain\Domain' |
|
150 | + ), |
|
151 | + array( |
|
152 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
153 | + Version::fromString(espresso_version()) |
|
154 | + ) |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * sets up the request and response objects |
|
161 | + * |
|
162 | + * @return BootstrapRequestResponseObjects |
|
163 | + * @throws InvalidArgumentException |
|
164 | + */ |
|
165 | + private function bootstrapRequestResponseObjects() |
|
166 | + { |
|
167 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
168 | + $bootstrap_request = $this->loader->getShared( |
|
169 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
170 | + array($this->loader) |
|
171 | + ); |
|
172 | + $bootstrap_request->buildRequestResponse(); |
|
173 | + $bootstrap_request->shareRequestResponse(); |
|
174 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
175 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
176 | + return $bootstrap_request; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * run_request_stack |
|
182 | + * construct request stack and run middleware apps |
|
183 | + * |
|
184 | + * @throws InvalidRequestStackMiddlewareException |
|
185 | + * @throws InvalidInterfaceException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public function runRequestStack() |
|
190 | + { |
|
191 | + $this->loadAutoloader(); |
|
192 | + $this->setAutoloadersForRequiredFiles(); |
|
193 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
194 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
195 | + new RequestStackCoreApp() |
|
196 | + ); |
|
197 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
198 | + $this->request_stack->handleResponse(); |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * load_autoloader |
|
204 | + * |
|
205 | + * @throws EE_Error |
|
206 | + */ |
|
207 | + protected function loadAutoloader() |
|
208 | + { |
|
209 | + // load interfaces |
|
210 | + espresso_load_required( |
|
211 | + 'EEH_Autoloader', |
|
212 | + EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
213 | + ); |
|
214 | + EEH_Autoloader::instance(); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * load_required_files |
|
221 | + * |
|
222 | + * @throws EE_Error |
|
223 | + */ |
|
224 | + protected function setAutoloadersForRequiredFiles() |
|
225 | + { |
|
226 | + // load interfaces |
|
227 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
228 | + // load helpers |
|
229 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
230 | + // load request stack |
|
231 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
232 | + // load middleware |
|
233 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * build_request_stack |
|
240 | + * |
|
241 | + * @return RequestStackBuilder |
|
242 | + */ |
|
243 | + public function buildRequestStack() |
|
244 | + { |
|
245 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
246 | + /** |
|
247 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
248 | + * so items at the beginning of the final middleware stack will run last. |
|
249 | + * First parameter is the middleware classname, second is an array of arguments |
|
250 | + */ |
|
251 | + $stack_apps = apply_filters( |
|
252 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
253 | + array( |
|
254 | + // first in last out |
|
255 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
256 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
257 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
258 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
259 | + // last in first out |
|
260 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
261 | + ) |
|
262 | + ); |
|
263 | + // legacy filter for backwards compatibility |
|
264 | + $stack_apps = apply_filters( |
|
265 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
266 | + $stack_apps |
|
267 | + ); |
|
268 | + // load middleware onto stack : FILO (First In Last Out) |
|
269 | + // items at the beginning of the $stack_apps array will run last |
|
270 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
271 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
272 | + } |
|
273 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
274 | + // and we also need it to always run first because the rest of the system relies on it |
|
275 | + $request_stack_builder->push( |
|
276 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
277 | + ); |
|
278 | + return apply_filters( |
|
279 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
280 | + $request_stack_builder |
|
281 | + ); |
|
282 | + } |
|
283 | 283 | |
284 | 284 | |
285 | 285 | } |
@@ -13,72 +13,72 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Messages_Email_Newsletter_Validator extends EE_Messages_Validator |
15 | 15 | { |
16 | - /** |
|
17 | - * EE_Messages_Email_Newsletter_Validator constructor. |
|
18 | - * |
|
19 | - * @param array $fields |
|
20 | - * @param string $context |
|
21 | - * @throws EE_Error |
|
22 | - * @throws ReflectionException |
|
23 | - */ |
|
24 | - public function __construct(array $fields, $context) |
|
25 | - { |
|
26 | - $this->_m_name = 'email'; |
|
27 | - $this->_mt_name = 'newsletter'; |
|
16 | + /** |
|
17 | + * EE_Messages_Email_Newsletter_Validator constructor. |
|
18 | + * |
|
19 | + * @param array $fields |
|
20 | + * @param string $context |
|
21 | + * @throws EE_Error |
|
22 | + * @throws ReflectionException |
|
23 | + */ |
|
24 | + public function __construct(array $fields, $context) |
|
25 | + { |
|
26 | + $this->_m_name = 'email'; |
|
27 | + $this->_mt_name = 'newsletter'; |
|
28 | 28 | |
29 | - parent::__construct($fields, $context); |
|
30 | - } |
|
29 | + parent::__construct($fields, $context); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * custom validator (restricting what was originally set by the messenger) |
|
34 | - */ |
|
35 | - protected function _modify_validator() |
|
36 | - { |
|
37 | - if ($this->_context === 'attendee') { |
|
38 | - $this->_valid_shortcodes_modifier[$this->_context]['from'] = array( |
|
39 | - 'recipient_details', |
|
40 | - 'email', |
|
41 | - 'organization', |
|
42 | - ); |
|
43 | - } |
|
32 | + /** |
|
33 | + * custom validator (restricting what was originally set by the messenger) |
|
34 | + */ |
|
35 | + protected function _modify_validator() |
|
36 | + { |
|
37 | + if ($this->_context === 'attendee') { |
|
38 | + $this->_valid_shortcodes_modifier[$this->_context]['from'] = array( |
|
39 | + 'recipient_details', |
|
40 | + 'email', |
|
41 | + 'organization', |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | - //excluded shortcodes |
|
46 | - $fields = array('to', 'from', 'subject', 'content', 'newsletter_content'); |
|
47 | - foreach ($fields as $field) { |
|
48 | - $this->_specific_shortcode_excludes[$field] = array( |
|
49 | - '[RECIPIENT_REGISTRATION_CODE]', |
|
50 | - '[EVENT_AUTHOR_FORMATTED_EMAIL]', |
|
51 | - '[EVENT_AUTHOR_EMAIL]', |
|
52 | - ); |
|
53 | - } |
|
54 | - $add_excludes = array( |
|
55 | - '[RECIPIENT_FNAME]', |
|
56 | - '[RECIPIENT_LNAME]', |
|
57 | - '[RECIPIENT_EMAIL]', |
|
58 | - '[COMPANY]', |
|
59 | - '[CO_ADD1]', |
|
60 | - '[CO_ADD2]', |
|
61 | - '[CO_CITY]', |
|
62 | - '[CO_STATE]', |
|
63 | - '[CO_ZIP]', |
|
64 | - '[CO_LOGO]', |
|
65 | - '[CO_PHONE]', |
|
66 | - '[CO_LOGO_URL]', |
|
67 | - '[CO_FACEBOOK_URL]', |
|
68 | - '[CO_TWITTER_URL]', |
|
69 | - '[CO_PINTEREST_URL]', |
|
70 | - '[CO_GOOGLE_URL]', |
|
71 | - '[CO_LINKEDIN_URL]', |
|
72 | - '[CO_INSTAGRAM_URL]', |
|
73 | - ); |
|
74 | - $this->_specific_shortcode_excludes['from'] = |
|
75 | - array_merge( |
|
76 | - $this->_specific_shortcode_excludes['from'], |
|
77 | - $add_excludes |
|
78 | - ); |
|
79 | - $this->_specific_shortcode_excludes['content'] = array_merge( |
|
80 | - $this->_specific_shortcode_excludes['content'], |
|
81 | - array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') |
|
82 | - ); |
|
83 | - } |
|
45 | + //excluded shortcodes |
|
46 | + $fields = array('to', 'from', 'subject', 'content', 'newsletter_content'); |
|
47 | + foreach ($fields as $field) { |
|
48 | + $this->_specific_shortcode_excludes[$field] = array( |
|
49 | + '[RECIPIENT_REGISTRATION_CODE]', |
|
50 | + '[EVENT_AUTHOR_FORMATTED_EMAIL]', |
|
51 | + '[EVENT_AUTHOR_EMAIL]', |
|
52 | + ); |
|
53 | + } |
|
54 | + $add_excludes = array( |
|
55 | + '[RECIPIENT_FNAME]', |
|
56 | + '[RECIPIENT_LNAME]', |
|
57 | + '[RECIPIENT_EMAIL]', |
|
58 | + '[COMPANY]', |
|
59 | + '[CO_ADD1]', |
|
60 | + '[CO_ADD2]', |
|
61 | + '[CO_CITY]', |
|
62 | + '[CO_STATE]', |
|
63 | + '[CO_ZIP]', |
|
64 | + '[CO_LOGO]', |
|
65 | + '[CO_PHONE]', |
|
66 | + '[CO_LOGO_URL]', |
|
67 | + '[CO_FACEBOOK_URL]', |
|
68 | + '[CO_TWITTER_URL]', |
|
69 | + '[CO_PINTEREST_URL]', |
|
70 | + '[CO_GOOGLE_URL]', |
|
71 | + '[CO_LINKEDIN_URL]', |
|
72 | + '[CO_INSTAGRAM_URL]', |
|
73 | + ); |
|
74 | + $this->_specific_shortcode_excludes['from'] = |
|
75 | + array_merge( |
|
76 | + $this->_specific_shortcode_excludes['from'], |
|
77 | + $add_excludes |
|
78 | + ); |
|
79 | + $this->_specific_shortcode_excludes['content'] = array_merge( |
|
80 | + $this->_specific_shortcode_excludes['content'], |
|
81 | + array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -14,196 +14,196 @@ |
||
14 | 14 | class EE_Newsletter_message_type extends EE_message_type |
15 | 15 | { |
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->name = 'newsletter'; |
|
20 | - $this->description = esc_html__( |
|
21 | - 'Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', |
|
22 | - 'event_espresso' |
|
23 | - ); |
|
24 | - $this->label = array( |
|
25 | - 'singular' => esc_html__('batch', 'event_espresso'), |
|
26 | - 'plural' => esc_html__('batches', 'event_espresso'), |
|
27 | - ); |
|
28 | - $this->_master_templates = array( |
|
29 | - 'email' => 'registration', |
|
30 | - ); |
|
31 | - |
|
32 | - parent::__construct(); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Sets admin_registered_pages property |
|
38 | - */ |
|
39 | - protected function _set_admin_pages() |
|
40 | - { |
|
41 | - $this->admin_registered_pages = array(); //no admin pages to register this with. |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Sets property related to data handler. |
|
47 | - */ |
|
48 | - protected function _set_data_handler() |
|
49 | - { |
|
50 | - $this->_data_handler = 'Registrations'; |
|
51 | - $this->_single_message = $this->_data instanceof EE_Registration; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns the data for the given context for this message type. |
|
57 | - * @param string $context |
|
58 | - * @param EE_Registration $registration |
|
59 | - * @param int $id |
|
60 | - * @return array|mixed |
|
61 | - */ |
|
62 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
63 | - { |
|
64 | - //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
|
65 | - return array($registration); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Sets the admin settings fields property for this message type. |
|
71 | - */ |
|
72 | - protected function _set_admin_settings_fields() |
|
73 | - { |
|
74 | - $this->_admin_settings_fields = array(); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Sets the contexts for this message type. |
|
80 | - */ |
|
81 | - protected function _set_contexts() |
|
82 | - { |
|
83 | - $this->_context_label = array( |
|
84 | - 'label' => esc_html__('recipient', 'event_espresso'), |
|
85 | - 'plural' => esc_html__('recipients', 'event_espresso'), |
|
86 | - 'description' => esc_html__('Recipient\'s are who will receive the message.', 'event_espresso'), |
|
87 | - ); |
|
88 | - |
|
89 | - $this->_contexts = array( |
|
90 | - 'attendee' => array( |
|
91 | - 'label' => esc_html__('Registrant', 'event_espresso'), |
|
92 | - 'description' => esc_html__('This template goes to selected registrants.', 'event_espresso'), |
|
93 | - ), |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * used to set the valid shortcodes. |
|
100 | - * For the newsletter message type we only have two valid shortcode libraries in use, recipient details and |
|
101 | - * organization. That's it! |
|
102 | - * |
|
103 | - * @since 4.3.0 |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function _set_valid_shortcodes() |
|
107 | - { |
|
108 | - parent::_set_valid_shortcodes(); |
|
109 | - |
|
110 | - $included_shortcodes = array( |
|
111 | - 'recipient_details', |
|
112 | - 'organization', |
|
113 | - 'newsletter', |
|
114 | - ); |
|
115 | - |
|
116 | - foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
117 | - foreach ($shortcodes as $key => $shortcode) { |
|
118 | - if (! in_array($shortcode, $included_shortcodes, true)) { |
|
119 | - unset($this->_valid_shortcodes[$context][$key]); |
|
120 | - } |
|
121 | - } |
|
122 | - $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Override default _attendee_addressees in EE_message_type because we want to loop through the registrations |
|
129 | - * for EE_message_type. |
|
130 | - * |
|
131 | - * @return array |
|
132 | - * @throws EE_Error |
|
133 | - * @throws InvalidArgumentException |
|
134 | - * @throws ReflectionException |
|
135 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
136 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
137 | - */ |
|
138 | - protected function _attendee_addressees() |
|
139 | - { |
|
140 | - $addressee = array(); |
|
141 | - |
|
142 | - //looping through registrations |
|
143 | - foreach ($this->_data->registrations as $reg_id => $details) { |
|
144 | - //set $attendee array to blank on each loop |
|
145 | - $aee = array(); |
|
146 | - |
|
147 | - //need to get the attendee from this registration. |
|
148 | - $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
149 | - ? $details['att_obj'] |
|
150 | - : null; |
|
151 | - |
|
152 | - if (! $attendee instanceof EE_Attendee) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - |
|
156 | - //set $aee from attendee object |
|
157 | - $aee['att_obj'] = $attendee; |
|
158 | - $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
159 | - ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
160 | - : array(); |
|
161 | - $aee['attendee_email'] = $attendee->email(); |
|
162 | - $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
163 | - ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
164 | - : array(); |
|
165 | - |
|
166 | - if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
167 | - $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
168 | - $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
169 | - } else { |
|
170 | - $aee['evt_objs'] = $aee['events'] = array(); |
|
171 | - } |
|
172 | - |
|
173 | - $aee['reg_obj'] = isset($details['reg_obj']) |
|
174 | - ? $details['reg_obj'] |
|
175 | - : null; |
|
176 | - $aee['attendees'] = $this->_data->attendees; |
|
177 | - |
|
178 | - //merge in the primary attendee data |
|
179 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
180 | - |
|
181 | - //make sure txn is set |
|
182 | - if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
183 | - $aee['txn'] = $aee['reg_obj']->transaction(); |
|
184 | - } |
|
185 | - |
|
186 | - $addressee[] = new EE_Messages_Addressee($aee); |
|
187 | - } |
|
188 | - return $addressee; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Allows a message type to specifically exclude template fields for the provided messenger. |
|
193 | - * Filtered so this can be programmatically altered as well. |
|
194 | - * |
|
195 | - * @param string $messenger_name name of messenger |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function excludedFieldsForMessenger($messenger_name) |
|
199 | - { |
|
200 | - $excluded_fields = array( |
|
201 | - 'email' => array('cc') |
|
202 | - ); |
|
203 | - return isset($excluded_fields[$messenger_name]) |
|
204 | - ? $excluded_fields[$messenger_name] |
|
205 | - : parent::excludedFieldsForMessenger($messenger_name); |
|
206 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->name = 'newsletter'; |
|
20 | + $this->description = esc_html__( |
|
21 | + 'Batch message type messages are triggered manually by the admin for sending notifications to a selected group of recipients. This should only be used for more general notification type messages that contain information specific for the recipients. For "newsletter" type messages we recommend using an email list service like MailChimp, because sending non-related mail-outs to contacts increases the risk of your site domain getting added to spam lists, which will prevent messages getting to users.', |
|
22 | + 'event_espresso' |
|
23 | + ); |
|
24 | + $this->label = array( |
|
25 | + 'singular' => esc_html__('batch', 'event_espresso'), |
|
26 | + 'plural' => esc_html__('batches', 'event_espresso'), |
|
27 | + ); |
|
28 | + $this->_master_templates = array( |
|
29 | + 'email' => 'registration', |
|
30 | + ); |
|
31 | + |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Sets admin_registered_pages property |
|
38 | + */ |
|
39 | + protected function _set_admin_pages() |
|
40 | + { |
|
41 | + $this->admin_registered_pages = array(); //no admin pages to register this with. |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Sets property related to data handler. |
|
47 | + */ |
|
48 | + protected function _set_data_handler() |
|
49 | + { |
|
50 | + $this->_data_handler = 'Registrations'; |
|
51 | + $this->_single_message = $this->_data instanceof EE_Registration; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns the data for the given context for this message type. |
|
57 | + * @param string $context |
|
58 | + * @param EE_Registration $registration |
|
59 | + * @param int $id |
|
60 | + * @return array|mixed |
|
61 | + */ |
|
62 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
63 | + { |
|
64 | + //newsletter message type data handler is 'Registrations' and it expects an array of EE_Registration objects. |
|
65 | + return array($registration); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Sets the admin settings fields property for this message type. |
|
71 | + */ |
|
72 | + protected function _set_admin_settings_fields() |
|
73 | + { |
|
74 | + $this->_admin_settings_fields = array(); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Sets the contexts for this message type. |
|
80 | + */ |
|
81 | + protected function _set_contexts() |
|
82 | + { |
|
83 | + $this->_context_label = array( |
|
84 | + 'label' => esc_html__('recipient', 'event_espresso'), |
|
85 | + 'plural' => esc_html__('recipients', 'event_espresso'), |
|
86 | + 'description' => esc_html__('Recipient\'s are who will receive the message.', 'event_espresso'), |
|
87 | + ); |
|
88 | + |
|
89 | + $this->_contexts = array( |
|
90 | + 'attendee' => array( |
|
91 | + 'label' => esc_html__('Registrant', 'event_espresso'), |
|
92 | + 'description' => esc_html__('This template goes to selected registrants.', 'event_espresso'), |
|
93 | + ), |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * used to set the valid shortcodes. |
|
100 | + * For the newsletter message type we only have two valid shortcode libraries in use, recipient details and |
|
101 | + * organization. That's it! |
|
102 | + * |
|
103 | + * @since 4.3.0 |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function _set_valid_shortcodes() |
|
107 | + { |
|
108 | + parent::_set_valid_shortcodes(); |
|
109 | + |
|
110 | + $included_shortcodes = array( |
|
111 | + 'recipient_details', |
|
112 | + 'organization', |
|
113 | + 'newsletter', |
|
114 | + ); |
|
115 | + |
|
116 | + foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
|
117 | + foreach ($shortcodes as $key => $shortcode) { |
|
118 | + if (! in_array($shortcode, $included_shortcodes, true)) { |
|
119 | + unset($this->_valid_shortcodes[$context][$key]); |
|
120 | + } |
|
121 | + } |
|
122 | + $this->_valid_shortcodes[$context][] = 'newsletter'; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Override default _attendee_addressees in EE_message_type because we want to loop through the registrations |
|
129 | + * for EE_message_type. |
|
130 | + * |
|
131 | + * @return array |
|
132 | + * @throws EE_Error |
|
133 | + * @throws InvalidArgumentException |
|
134 | + * @throws ReflectionException |
|
135 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
136 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
137 | + */ |
|
138 | + protected function _attendee_addressees() |
|
139 | + { |
|
140 | + $addressee = array(); |
|
141 | + |
|
142 | + //looping through registrations |
|
143 | + foreach ($this->_data->registrations as $reg_id => $details) { |
|
144 | + //set $attendee array to blank on each loop |
|
145 | + $aee = array(); |
|
146 | + |
|
147 | + //need to get the attendee from this registration. |
|
148 | + $attendee = isset($details['att_obj']) && $details['att_obj'] instanceof EE_Attendee |
|
149 | + ? $details['att_obj'] |
|
150 | + : null; |
|
151 | + |
|
152 | + if (! $attendee instanceof EE_Attendee) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + |
|
156 | + //set $aee from attendee object |
|
157 | + $aee['att_obj'] = $attendee; |
|
158 | + $aee['reg_objs'] = isset($this->_data->attendees[$attendee->ID()]['reg_objs']) |
|
159 | + ? $this->_data->attendees[$attendee->ID()]['reg_objs'] |
|
160 | + : array(); |
|
161 | + $aee['attendee_email'] = $attendee->email(); |
|
162 | + $aee['tkt_objs'] = isset($this->_data->attendees[$attendee->ID()]['tkt_objs']) |
|
163 | + ? $this->_data->attendees[$attendee->ID()]['tkt_objs'] |
|
164 | + : array(); |
|
165 | + |
|
166 | + if (isset($this->_data->attendees[$attendee->ID()]['evt_objs'])) { |
|
167 | + $aee['evt_objs'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
168 | + $aee['events'] = $this->_data->attendees[$attendee->ID()]['evt_objs']; |
|
169 | + } else { |
|
170 | + $aee['evt_objs'] = $aee['events'] = array(); |
|
171 | + } |
|
172 | + |
|
173 | + $aee['reg_obj'] = isset($details['reg_obj']) |
|
174 | + ? $details['reg_obj'] |
|
175 | + : null; |
|
176 | + $aee['attendees'] = $this->_data->attendees; |
|
177 | + |
|
178 | + //merge in the primary attendee data |
|
179 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
180 | + |
|
181 | + //make sure txn is set |
|
182 | + if (empty($aee['txn']) && $aee['reg_obj'] instanceof EE_Registration) { |
|
183 | + $aee['txn'] = $aee['reg_obj']->transaction(); |
|
184 | + } |
|
185 | + |
|
186 | + $addressee[] = new EE_Messages_Addressee($aee); |
|
187 | + } |
|
188 | + return $addressee; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Allows a message type to specifically exclude template fields for the provided messenger. |
|
193 | + * Filtered so this can be programmatically altered as well. |
|
194 | + * |
|
195 | + * @param string $messenger_name name of messenger |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function excludedFieldsForMessenger($messenger_name) |
|
199 | + { |
|
200 | + $excluded_fields = array( |
|
201 | + 'email' => array('cc') |
|
202 | + ); |
|
203 | + return isset($excluded_fields[$messenger_name]) |
|
204 | + ? $excluded_fields[$messenger_name] |
|
205 | + : parent::excludedFieldsForMessenger($messenger_name); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | 209 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | foreach ($this->_valid_shortcodes as $context => $shortcodes) { |
117 | 117 | foreach ($shortcodes as $key => $shortcode) { |
118 | - if (! in_array($shortcode, $included_shortcodes, true)) { |
|
118 | + if ( ! in_array($shortcode, $included_shortcodes, true)) { |
|
119 | 119 | unset($this->_valid_shortcodes[$context][$key]); |
120 | 120 | } |
121 | 121 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ? $details['att_obj'] |
150 | 150 | : null; |
151 | 151 | |
152 | - if (! $attendee instanceof EE_Attendee) { |
|
152 | + if ( ! $attendee instanceof EE_Attendee) { |
|
153 | 153 | continue; |
154 | 154 | } |
155 | 155 |
@@ -24,1057 +24,1057 @@ |
||
24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
25 | 25 | { |
26 | 26 | |
27 | - const debug = false; // true false |
|
28 | - |
|
29 | - /** |
|
30 | - * an array of raw ticket data from EED_Ticket_Selector |
|
31 | - * |
|
32 | - * @var array $ticket_selections |
|
33 | - */ |
|
34 | - protected $ticket_selections = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
38 | - * according to how they are displayed in the actual Ticket_Selector |
|
39 | - * this tracks the current row being processed |
|
40 | - * |
|
41 | - * @var int $current_row |
|
42 | - */ |
|
43 | - protected $current_row = 0; |
|
44 | - |
|
45 | - /** |
|
46 | - * an array for tracking names of tickets that have sold out |
|
47 | - * |
|
48 | - * @var array $sold_out_tickets |
|
49 | - */ |
|
50 | - protected $sold_out_tickets = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * an array for tracking names of tickets that have had their quantities reduced |
|
54 | - * |
|
55 | - * @var array $decremented_tickets |
|
56 | - */ |
|
57 | - protected $decremented_tickets = array(); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public static function set_hooks() |
|
67 | - { |
|
68 | - // release tickets for expired carts |
|
69 | - add_action( |
|
70 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
71 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
72 | - 1 |
|
73 | - ); |
|
74 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
75 | - add_filter( |
|
76 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
77 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
78 | - 20, |
|
79 | - 3 |
|
80 | - ); |
|
81 | - // add notices for sold out tickets |
|
82 | - add_action( |
|
83 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
84 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
85 | - 10 |
|
86 | - ); |
|
87 | - // handle ticket quantities adjusted in cart |
|
88 | - //add_action( |
|
89 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
90 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
91 | - // 10, 2 |
|
92 | - //); |
|
93 | - // handle tickets deleted from cart |
|
94 | - add_action( |
|
95 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
96 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
97 | - 10, |
|
98 | - 2 |
|
99 | - ); |
|
100 | - // handle emptied carts |
|
101 | - add_action( |
|
102 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
103 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
104 | - 10, |
|
105 | - 1 |
|
106 | - ); |
|
107 | - add_action( |
|
108 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
109 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
110 | - 10, |
|
111 | - 1 |
|
112 | - ); |
|
113 | - // handle cancelled registrations |
|
114 | - add_action( |
|
115 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
116 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
117 | - 10, |
|
118 | - 1 |
|
119 | - ); |
|
120 | - // cron tasks |
|
121 | - add_action( |
|
122 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
123 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
124 | - 10, |
|
125 | - 1 |
|
126 | - ); |
|
127 | - add_action( |
|
128 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
129 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
130 | - 10, |
|
131 | - 1 |
|
132 | - ); |
|
133 | - add_action( |
|
134 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
135 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
136 | - 10, |
|
137 | - 1 |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
145 | - * |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public static function set_hooks_admin() |
|
149 | - { |
|
150 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
157 | - */ |
|
158 | - public static function instance() |
|
159 | - { |
|
160 | - return parent::get_instance(__CLASS__); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param WP_Query $WP_Query |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function run($WP_Query) |
|
170 | - { |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves grand totals from the line items that have no TXN ID |
|
181 | - * and timestamps less than the current time minus the session lifespan. |
|
182 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
183 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
184 | - * |
|
185 | - * @return void |
|
186 | - * @throws DomainException |
|
187 | - * @throws EE_Error |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidInterfaceException |
|
191 | - * @throws UnexpectedEntityException |
|
192 | - */ |
|
193 | - public static function release_tickets_for_expired_carts() |
|
194 | - { |
|
195 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
196 | - $expired_ticket_IDs = array(); |
|
197 | - $valid_ticket_line_items = array(); |
|
198 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
199 | - if (empty($total_line_items)) { |
|
200 | - do_action( |
|
201 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
202 | - $total_line_items, |
|
203 | - $valid_ticket_line_items, |
|
204 | - $expired_ticket_IDs |
|
205 | - ); |
|
206 | - return; |
|
207 | - } |
|
208 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
209 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
210 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
211 | - ); |
|
212 | - foreach ($total_line_items as $total_line_item) { |
|
213 | - /** @var EE_Line_Item $total_line_item */ |
|
214 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
215 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
216 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
217 | - continue; |
|
218 | - } |
|
219 | - if ($total_line_item->timestamp(true) <= $session_lifespan->expiration()) { |
|
220 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
221 | - } else { |
|
222 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
223 | - } |
|
224 | - } |
|
225 | - } |
|
226 | - if (! empty($expired_ticket_IDs)) { |
|
227 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
228 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
229 | - $valid_ticket_line_items, |
|
230 | - __FUNCTION__ |
|
231 | - ); |
|
232 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
233 | - add_action( |
|
234 | - 'shutdown', |
|
235 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
236 | - 999 |
|
237 | - ); |
|
238 | - } |
|
239 | - do_action( |
|
240 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
241 | - $total_line_items, |
|
242 | - $valid_ticket_line_items, |
|
243 | - $expired_ticket_IDs |
|
244 | - ); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
255 | - * |
|
256 | - * @param int $qty |
|
257 | - * @param EE_Ticket $ticket |
|
258 | - * @return bool |
|
259 | - * @throws UnexpectedEntityException |
|
260 | - * @throws EE_Error |
|
261 | - */ |
|
262 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
263 | - { |
|
264 | - $qty = absint($qty); |
|
265 | - if ($qty > 0) { |
|
266 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
267 | - } |
|
268 | - if (self::debug) { |
|
269 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
270 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
271 | - } |
|
272 | - return $qty; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
279 | - * |
|
280 | - * @param EE_Ticket $ticket |
|
281 | - * @param int $qty |
|
282 | - * @return int |
|
283 | - * @throws UnexpectedEntityException |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
287 | - { |
|
288 | - if (self::debug) { |
|
289 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
290 | - } |
|
291 | - if (! $ticket instanceof EE_Ticket) { |
|
292 | - return 0; |
|
293 | - } |
|
294 | - if (self::debug) { |
|
295 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
296 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
297 | - } |
|
298 | - $ticket->refresh_from_db(); |
|
299 | - // first let's determine the ticket availability based on sales |
|
300 | - $available = $ticket->qty('saleable'); |
|
301 | - if (self::debug) { |
|
302 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
303 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
304 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
305 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
306 | - echo '<br /> . . . available: ' . $available; |
|
307 | - } |
|
308 | - if ($available < 1) { |
|
309 | - $this->_ticket_sold_out($ticket); |
|
310 | - return 0; |
|
311 | - } |
|
312 | - if (self::debug) { |
|
313 | - echo '<br /> . . . qty: ' . $qty; |
|
314 | - } |
|
315 | - if ($available < $qty) { |
|
316 | - $qty = $available; |
|
317 | - if (self::debug) { |
|
318 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
319 | - } |
|
320 | - $this->_ticket_quantity_decremented($ticket); |
|
321 | - } |
|
322 | - $this->_reserve_ticket($ticket, $qty); |
|
323 | - return $qty; |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * increments ticket reserved based on quantity passed |
|
330 | - * |
|
331 | - * @param EE_Ticket $ticket |
|
332 | - * @param int $quantity |
|
333 | - * @return bool |
|
334 | - * @throws EE_Error |
|
335 | - */ |
|
336 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
337 | - { |
|
338 | - if (self::debug) { |
|
339 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
340 | - } |
|
341 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
342 | - return $ticket->save(); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @param EE_Ticket $ticket |
|
349 | - * @param int $quantity |
|
350 | - * @return bool |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
354 | - { |
|
355 | - if (self::debug) { |
|
356 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
357 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
358 | - } |
|
359 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
360 | - if (self::debug) { |
|
361 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
362 | - } |
|
363 | - return $ticket->save() ? 1 : 0; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * removes quantities within the ticket selector based on zero ticket availability |
|
370 | - * |
|
371 | - * @param EE_Ticket $ticket |
|
372 | - * @return void |
|
373 | - * @throws UnexpectedEntityException |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
377 | - { |
|
378 | - if (self::debug) { |
|
379 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
380 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
381 | - } |
|
382 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
389 | - * |
|
390 | - * @param EE_Ticket $ticket |
|
391 | - * @return void |
|
392 | - * @throws UnexpectedEntityException |
|
393 | - * @throws EE_Error |
|
394 | - */ |
|
395 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
396 | - { |
|
397 | - if (self::debug) { |
|
398 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
399 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
400 | - } |
|
401 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * builds string out of ticket and event name |
|
408 | - * |
|
409 | - * @param EE_Ticket $ticket |
|
410 | - * @return string |
|
411 | - * @throws UnexpectedEntityException |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
415 | - { |
|
416 | - $event = $ticket->get_related_event(); |
|
417 | - if ($event instanceof EE_Event) { |
|
418 | - $ticket_name = sprintf( |
|
419 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
420 | - $ticket->name(), |
|
421 | - $event->name() |
|
422 | - ); |
|
423 | - } else { |
|
424 | - $ticket_name = $ticket->name(); |
|
425 | - } |
|
426 | - return $ticket_name; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /********************************** EVENT CART **********************************/ |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * releases or reserves ticket(s) based on quantity passed |
|
437 | - * |
|
438 | - * @param EE_Line_Item $line_item |
|
439 | - * @param int $quantity |
|
440 | - * @return void |
|
441 | - * @throws EE_Error |
|
442 | - * @throws InvalidArgumentException |
|
443 | - * @throws InvalidDataTypeException |
|
444 | - * @throws InvalidInterfaceException |
|
445 | - */ |
|
446 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
447 | - { |
|
448 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
449 | - if ($ticket instanceof EE_Ticket) { |
|
450 | - $ticket->add_extra_meta( |
|
451 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
452 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
453 | - ); |
|
454 | - if ($quantity > 0) { |
|
455 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
456 | - } else { |
|
457 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
458 | - } |
|
459 | - } |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * releases reserved ticket(s) based on quantity passed |
|
466 | - * |
|
467 | - * @param EE_Ticket $ticket |
|
468 | - * @param int $quantity |
|
469 | - * @return void |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
473 | - { |
|
474 | - $ticket->add_extra_meta( |
|
475 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
476 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
477 | - ); |
|
478 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /********************************** POST_NOTICES **********************************/ |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @return void |
|
489 | - * @throws EE_Error |
|
490 | - * @throws InvalidArgumentException |
|
491 | - * @throws ReflectionException |
|
492 | - * @throws InvalidDataTypeException |
|
493 | - * @throws InvalidInterfaceException |
|
494 | - */ |
|
495 | - public static function post_notices() |
|
496 | - { |
|
497 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * @return void |
|
504 | - * @throws EE_Error |
|
505 | - * @throws InvalidArgumentException |
|
506 | - * @throws ReflectionException |
|
507 | - * @throws InvalidDataTypeException |
|
508 | - * @throws InvalidInterfaceException |
|
509 | - */ |
|
510 | - protected function _post_notices() |
|
511 | - { |
|
512 | - if (self::debug) { |
|
513 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
514 | - } |
|
515 | - $refresh_msg = ''; |
|
516 | - $none_added_msg = ''; |
|
517 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
518 | - $refresh_msg = __( |
|
519 | - 'Please refresh the page to view updated ticket quantities.', |
|
520 | - 'event_espresso' |
|
521 | - ); |
|
522 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
523 | - } |
|
524 | - if (! empty($this->sold_out_tickets)) { |
|
525 | - EE_Error::add_attention( |
|
526 | - sprintf( |
|
527 | - apply_filters( |
|
528 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
529 | - __( |
|
530 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
531 | - 'event_espresso' |
|
532 | - ) |
|
533 | - ), |
|
534 | - '<br />', |
|
535 | - implode('<br />', $this->sold_out_tickets), |
|
536 | - $none_added_msg, |
|
537 | - $refresh_msg |
|
538 | - ) |
|
539 | - ); |
|
540 | - // alter code flow in the Ticket Selector for better UX |
|
541 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
542 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
543 | - $this->sold_out_tickets = array(); |
|
544 | - // and reset the cart |
|
545 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
546 | - } |
|
547 | - if (! empty($this->decremented_tickets)) { |
|
548 | - EE_Error::add_attention( |
|
549 | - sprintf( |
|
550 | - apply_filters( |
|
551 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
552 | - __( |
|
553 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
554 | - 'event_espresso' |
|
555 | - ) |
|
556 | - ), |
|
557 | - '<br />', |
|
558 | - implode('<br />', $this->decremented_tickets), |
|
559 | - $none_added_msg, |
|
560 | - $refresh_msg |
|
561 | - ) |
|
562 | - ); |
|
563 | - $this->decremented_tickets = array(); |
|
564 | - } |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
575 | - * by default, will NOT release tickets for finalized transactions |
|
576 | - * |
|
577 | - * @param EE_Transaction $transaction |
|
578 | - * @return int |
|
579 | - * @throws EE_Error |
|
580 | - * @throws InvalidSessionDataException |
|
581 | - */ |
|
582 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
583 | - { |
|
584 | - if (self::debug) { |
|
585 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
586 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
587 | - echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
588 | - } |
|
589 | - // check if 'finalize_registration' step has been completed... |
|
590 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
591 | - if (self::debug) { |
|
592 | - // DEBUG LOG |
|
593 | - EEH_Debug_Tools::log( |
|
594 | - __CLASS__, |
|
595 | - __FUNCTION__, |
|
596 | - __LINE__, |
|
597 | - array('finalized' => $finalized), |
|
598 | - false, |
|
599 | - 'EE_Transaction: ' . $transaction->ID() |
|
600 | - ); |
|
601 | - } |
|
602 | - // how many tickets were released |
|
603 | - $count = 0; |
|
604 | - if (self::debug) { |
|
605 | - echo '<br /> . . . TXN finalized: ' . $finalized; |
|
606 | - } |
|
607 | - $release_tickets_with_TXN_status = array( |
|
608 | - EEM_Transaction::failed_status_code, |
|
609 | - EEM_Transaction::abandoned_status_code, |
|
610 | - EEM_Transaction::incomplete_status_code, |
|
611 | - ); |
|
612 | - $events = array(); |
|
613 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
614 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
615 | - // cancel any reserved tickets for registrations that were not approved |
|
616 | - $registrations = $transaction->registrations(); |
|
617 | - if (self::debug) { |
|
618 | - echo '<br /> . . . # registrations: ' . count($registrations); |
|
619 | - $reg = reset($registrations); |
|
620 | - $ticket = $reg->ticket(); |
|
621 | - if ($ticket instanceof EE_Ticket) { |
|
622 | - $ticket->add_extra_meta( |
|
623 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
624 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
625 | - ); |
|
626 | - } |
|
627 | - } |
|
628 | - if (! empty($registrations)) { |
|
629 | - foreach ($registrations as $registration) { |
|
630 | - if ( |
|
631 | - $registration instanceof EE_Registration |
|
632 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
633 | - ) { |
|
634 | - $count++; |
|
635 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
636 | - } |
|
637 | - } |
|
638 | - } |
|
639 | - } |
|
640 | - if ($events !== array()) { |
|
641 | - foreach ($events as $event) { |
|
642 | - /** @var EE_Event $event */ |
|
643 | - $event->perform_sold_out_status_check(); |
|
644 | - } |
|
645 | - } |
|
646 | - return $count; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * releases reserved tickets for an EE_Registration |
|
653 | - * by default, will NOT release tickets for APPROVED registrations |
|
654 | - * |
|
655 | - * @param EE_Registration $registration |
|
656 | - * @param EE_Transaction $transaction |
|
657 | - * @return int |
|
658 | - * @throws EE_Error |
|
659 | - */ |
|
660 | - protected function _release_reserved_ticket_for_registration( |
|
661 | - EE_Registration $registration, |
|
662 | - EE_Transaction $transaction |
|
663 | - ) { |
|
664 | - $STS_ID = $transaction->status_ID(); |
|
665 | - if (self::debug) { |
|
666 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
667 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
668 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
669 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
670 | - } |
|
671 | - if ( |
|
672 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
673 | - $STS_ID === EEM_Transaction::failed_status_code |
|
674 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
675 | - || ( |
|
676 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
677 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
678 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
679 | - ) |
|
680 | - ) { |
|
681 | - if (self::debug) { |
|
682 | - echo '<br /><br /> . . RELEASE RESERVED TICKET'; |
|
683 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
684 | - echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
685 | - var_dump($rsrvd); |
|
686 | - } |
|
687 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
688 | - return 1; |
|
689 | - } |
|
690 | - return 0; |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - |
|
695 | - /********************************** SESSION_CART_RESET **********************************/ |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
701 | - * |
|
702 | - * @param EE_Session $session |
|
703 | - * @return void |
|
704 | - * @throws EE_Error |
|
705 | - * @throws InvalidArgumentException |
|
706 | - * @throws ReflectionException |
|
707 | - * @throws InvalidDataTypeException |
|
708 | - * @throws InvalidInterfaceException |
|
709 | - */ |
|
710 | - public static function session_cart_reset(EE_Session $session) |
|
711 | - { |
|
712 | - if (self::debug) { |
|
713 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
714 | - } |
|
715 | - // first check of the session has a valid Checkout object |
|
716 | - $checkout = $session->checkout(); |
|
717 | - if ($checkout instanceof EE_Checkout) { |
|
718 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
719 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
720 | - return; |
|
721 | - } |
|
722 | - $cart = $session->cart(); |
|
723 | - if ($cart instanceof EE_Cart) { |
|
724 | - if (self::debug) { |
|
725 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
726 | - } |
|
727 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
728 | - } else { |
|
729 | - if (self::debug) { |
|
730 | - echo '<br /><br /> invalid EE_Cart: '; |
|
731 | - var_export($cart, true); |
|
732 | - } |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * releases reserved tickets in the EE_Cart |
|
740 | - * |
|
741 | - * @param EE_Cart $cart |
|
742 | - * @return void |
|
743 | - * @throws EE_Error |
|
744 | - * @throws InvalidArgumentException |
|
745 | - * @throws ReflectionException |
|
746 | - * @throws InvalidDataTypeException |
|
747 | - * @throws InvalidInterfaceException |
|
748 | - */ |
|
749 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
750 | - { |
|
751 | - if (self::debug) { |
|
752 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
753 | - } |
|
754 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
755 | - $ticket_line_items = $cart->get_tickets(); |
|
756 | - if (empty($ticket_line_items)) { |
|
757 | - return; |
|
758 | - } |
|
759 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
760 | - if (self::debug) { |
|
761 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
762 | - } |
|
763 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
764 | - if (self::debug) { |
|
765 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
766 | - } |
|
767 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
768 | - if ($ticket instanceof EE_Ticket) { |
|
769 | - if (self::debug) { |
|
770 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
771 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
772 | - } |
|
773 | - $ticket->add_extra_meta( |
|
774 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
775 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
776 | - ); |
|
777 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
778 | - } |
|
779 | - } |
|
780 | - } |
|
781 | - if (self::debug) { |
|
782 | - echo '<br /><br /> RESET COMPLETED '; |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
794 | - * |
|
795 | - * @param EE_Session $session |
|
796 | - * @return void |
|
797 | - * @throws EE_Error |
|
798 | - * @throws InvalidSessionDataException |
|
799 | - */ |
|
800 | - public static function session_checkout_reset(EE_Session $session) |
|
801 | - { |
|
802 | - $checkout = $session->checkout(); |
|
803 | - if ($checkout instanceof EE_Checkout) { |
|
804 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
805 | - } |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * releases reserved tickets for the EE_Checkout->transaction |
|
812 | - * |
|
813 | - * @param EE_Checkout $checkout |
|
814 | - * @return void |
|
815 | - * @throws EE_Error |
|
816 | - * @throws InvalidSessionDataException |
|
817 | - */ |
|
818 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
819 | - { |
|
820 | - if (self::debug) { |
|
821 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
822 | - } |
|
823 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
824 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
825 | - return; |
|
826 | - } |
|
827 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - |
|
832 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
833 | - |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * @param EE_Session $session |
|
838 | - * @return void |
|
839 | - */ |
|
840 | - public static function session_expired_reset(EE_Session $session) |
|
841 | - { |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - |
|
846 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
847 | - |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
852 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
853 | - * |
|
854 | - * @param EE_Transaction $transaction |
|
855 | - * @return void |
|
856 | - * @throws EE_Error |
|
857 | - * @throws InvalidSessionDataException |
|
858 | - */ |
|
859 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
860 | - { |
|
861 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
862 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
863 | - if (self::debug) { |
|
864 | - // DEBUG LOG |
|
865 | - EEH_Debug_Tools::log( |
|
866 | - __CLASS__, |
|
867 | - __FUNCTION__, |
|
868 | - __LINE__, |
|
869 | - array($transaction), |
|
870 | - false, |
|
871 | - 'EE_Transaction: ' . $transaction->ID() |
|
872 | - ); |
|
873 | - } |
|
874 | - return; |
|
875 | - } |
|
876 | - // have their been any successful payments made ? |
|
877 | - $payments = $transaction->payments(); |
|
878 | - foreach ($payments as $payment) { |
|
879 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
880 | - if (self::debug) { |
|
881 | - // DEBUG LOG |
|
882 | - EEH_Debug_Tools::log( |
|
883 | - __CLASS__, |
|
884 | - __FUNCTION__, |
|
885 | - __LINE__, |
|
886 | - array($payment), |
|
887 | - false, |
|
888 | - 'EE_Transaction: ' . $transaction->ID() |
|
889 | - ); |
|
890 | - } |
|
891 | - return; |
|
892 | - } |
|
893 | - } |
|
894 | - // since you haven't even attempted to pay for your ticket... |
|
895 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
901 | - |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
906 | - * |
|
907 | - * @param EE_Transaction $transaction |
|
908 | - * @return void |
|
909 | - * @throws EE_Error |
|
910 | - * @throws InvalidSessionDataException |
|
911 | - */ |
|
912 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
913 | - { |
|
914 | - // since you haven't even attempted to pay for your ticket... |
|
915 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - |
|
920 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * Resets all ticket and datetime reserved counts to zero |
|
926 | - * Tickets that are currently associated with a Transaction that is in progress |
|
927 | - * |
|
928 | - * @throws EE_Error |
|
929 | - * @throws DomainException |
|
930 | - * @throws InvalidDataTypeException |
|
931 | - * @throws InvalidInterfaceException |
|
932 | - * @throws InvalidArgumentException |
|
933 | - * @throws UnexpectedEntityException |
|
934 | - */ |
|
935 | - public static function reset_reservation_counts() |
|
936 | - { |
|
937 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
938 | - $valid_reserved_tickets = array(); |
|
939 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
940 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
941 | - foreach ($transactions_not_in_progress as $transaction) { |
|
942 | - // if this TXN has been fully completed, then skip it |
|
943 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
944 | - continue; |
|
945 | - } |
|
946 | - $total_line_item = $transaction->total_line_item(); |
|
947 | - // $transaction_in_progress->line |
|
948 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
949 | - throw new DomainException( |
|
950 | - esc_html__( |
|
951 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
952 | - 'event_espresso' |
|
953 | - ) |
|
954 | - ); |
|
955 | - } |
|
956 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
957 | - $total_line_item |
|
958 | - ); |
|
959 | - } |
|
960 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
961 | - foreach ($total_line_items as $total_line_item) { |
|
962 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
963 | - $total_line_item |
|
964 | - ); |
|
965 | - } |
|
966 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
967 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
968 | - $tickets_with_reservations, |
|
969 | - $valid_reserved_tickets, |
|
970 | - __FUNCTION__ |
|
971 | - ); |
|
972 | - } |
|
973 | - |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * @param EE_Line_Item $total_line_item |
|
978 | - * @return EE_Line_Item[] |
|
979 | - */ |
|
980 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
981 | - { |
|
982 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
983 | - $valid_reserved_tickets = array(); |
|
984 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
985 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
986 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
987 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
988 | - } |
|
989 | - } |
|
990 | - return $valid_reserved_tickets; |
|
991 | - } |
|
992 | - |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * @param EE_Ticket[] $tickets_with_reservations |
|
997 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
998 | - * @return int |
|
999 | - * @throws UnexpectedEntityException |
|
1000 | - * @throws DomainException |
|
1001 | - * @throws EE_Error |
|
1002 | - */ |
|
1003 | - private static function release_reservations_for_tickets( |
|
1004 | - array $tickets_with_reservations, |
|
1005 | - array $valid_reserved_ticket_line_items = array(), |
|
1006 | - $source |
|
1007 | - ) { |
|
1008 | - $total_tickets_released = 0; |
|
1009 | - $sold_out_events = array(); |
|
1010 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1011 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1012 | - continue; |
|
1013 | - } |
|
1014 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
1015 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1016 | - if ( |
|
1017 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1018 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1019 | - ) { |
|
1020 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - if ($reserved_qty > 0) { |
|
1024 | - $ticket_with_reservations->add_extra_meta( |
|
1025 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1026 | - __LINE__ . ') ' . $source . '()' |
|
1027 | - ); |
|
1028 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
1029 | - $ticket_with_reservations->save(); |
|
1030 | - $total_tickets_released += $reserved_qty; |
|
1031 | - $event = $ticket_with_reservations->get_related_event(); |
|
1032 | - // track sold out events |
|
1033 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1034 | - $sold_out_events[] = $event; |
|
1035 | - } |
|
1036 | - } |
|
1037 | - } |
|
1038 | - // double check whether sold out events should remain sold out after releasing tickets |
|
1039 | - if($sold_out_events !== array()){ |
|
1040 | - foreach ($sold_out_events as $sold_out_event) { |
|
1041 | - /** @var EE_Event $sold_out_event */ |
|
1042 | - $sold_out_event->perform_sold_out_status_check(); |
|
1043 | - } |
|
1044 | - } |
|
1045 | - return $total_tickets_released; |
|
1046 | - } |
|
1047 | - |
|
1048 | - |
|
1049 | - |
|
1050 | - /********************************** SHUTDOWN **********************************/ |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @return false|int |
|
1056 | - * @throws EE_Error |
|
1057 | - * @throws InvalidArgumentException |
|
1058 | - * @throws InvalidDataTypeException |
|
1059 | - * @throws InvalidInterfaceException |
|
1060 | - */ |
|
1061 | - public static function clear_expired_line_items_with_no_transaction() |
|
1062 | - { |
|
1063 | - /** @type WPDB $wpdb */ |
|
1064 | - global $wpdb; |
|
1065 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1066 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1067 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1068 | - ); |
|
1069 | - return $wpdb->query( |
|
1070 | - $wpdb->prepare( |
|
1071 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
27 | + const debug = false; // true false |
|
28 | + |
|
29 | + /** |
|
30 | + * an array of raw ticket data from EED_Ticket_Selector |
|
31 | + * |
|
32 | + * @var array $ticket_selections |
|
33 | + */ |
|
34 | + protected $ticket_selections = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
38 | + * according to how they are displayed in the actual Ticket_Selector |
|
39 | + * this tracks the current row being processed |
|
40 | + * |
|
41 | + * @var int $current_row |
|
42 | + */ |
|
43 | + protected $current_row = 0; |
|
44 | + |
|
45 | + /** |
|
46 | + * an array for tracking names of tickets that have sold out |
|
47 | + * |
|
48 | + * @var array $sold_out_tickets |
|
49 | + */ |
|
50 | + protected $sold_out_tickets = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * an array for tracking names of tickets that have had their quantities reduced |
|
54 | + * |
|
55 | + * @var array $decremented_tickets |
|
56 | + */ |
|
57 | + protected $decremented_tickets = array(); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public static function set_hooks() |
|
67 | + { |
|
68 | + // release tickets for expired carts |
|
69 | + add_action( |
|
70 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
71 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
72 | + 1 |
|
73 | + ); |
|
74 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
75 | + add_filter( |
|
76 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
77 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
78 | + 20, |
|
79 | + 3 |
|
80 | + ); |
|
81 | + // add notices for sold out tickets |
|
82 | + add_action( |
|
83 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
84 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
85 | + 10 |
|
86 | + ); |
|
87 | + // handle ticket quantities adjusted in cart |
|
88 | + //add_action( |
|
89 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
90 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
91 | + // 10, 2 |
|
92 | + //); |
|
93 | + // handle tickets deleted from cart |
|
94 | + add_action( |
|
95 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
96 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
97 | + 10, |
|
98 | + 2 |
|
99 | + ); |
|
100 | + // handle emptied carts |
|
101 | + add_action( |
|
102 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
103 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
104 | + 10, |
|
105 | + 1 |
|
106 | + ); |
|
107 | + add_action( |
|
108 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
109 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
110 | + 10, |
|
111 | + 1 |
|
112 | + ); |
|
113 | + // handle cancelled registrations |
|
114 | + add_action( |
|
115 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
116 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
117 | + 10, |
|
118 | + 1 |
|
119 | + ); |
|
120 | + // cron tasks |
|
121 | + add_action( |
|
122 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
123 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
124 | + 10, |
|
125 | + 1 |
|
126 | + ); |
|
127 | + add_action( |
|
128 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
129 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
130 | + 10, |
|
131 | + 1 |
|
132 | + ); |
|
133 | + add_action( |
|
134 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
135 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
136 | + 10, |
|
137 | + 1 |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
145 | + * |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public static function set_hooks_admin() |
|
149 | + { |
|
150 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
157 | + */ |
|
158 | + public static function instance() |
|
159 | + { |
|
160 | + return parent::get_instance(__CLASS__); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param WP_Query $WP_Query |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function run($WP_Query) |
|
170 | + { |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves grand totals from the line items that have no TXN ID |
|
181 | + * and timestamps less than the current time minus the session lifespan. |
|
182 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
183 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
184 | + * |
|
185 | + * @return void |
|
186 | + * @throws DomainException |
|
187 | + * @throws EE_Error |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidInterfaceException |
|
191 | + * @throws UnexpectedEntityException |
|
192 | + */ |
|
193 | + public static function release_tickets_for_expired_carts() |
|
194 | + { |
|
195 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
196 | + $expired_ticket_IDs = array(); |
|
197 | + $valid_ticket_line_items = array(); |
|
198 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
199 | + if (empty($total_line_items)) { |
|
200 | + do_action( |
|
201 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
202 | + $total_line_items, |
|
203 | + $valid_ticket_line_items, |
|
204 | + $expired_ticket_IDs |
|
205 | + ); |
|
206 | + return; |
|
207 | + } |
|
208 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
209 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
210 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
211 | + ); |
|
212 | + foreach ($total_line_items as $total_line_item) { |
|
213 | + /** @var EE_Line_Item $total_line_item */ |
|
214 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
215 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
216 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
217 | + continue; |
|
218 | + } |
|
219 | + if ($total_line_item->timestamp(true) <= $session_lifespan->expiration()) { |
|
220 | + $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
221 | + } else { |
|
222 | + $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
223 | + } |
|
224 | + } |
|
225 | + } |
|
226 | + if (! empty($expired_ticket_IDs)) { |
|
227 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
228 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
229 | + $valid_ticket_line_items, |
|
230 | + __FUNCTION__ |
|
231 | + ); |
|
232 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
233 | + add_action( |
|
234 | + 'shutdown', |
|
235 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
236 | + 999 |
|
237 | + ); |
|
238 | + } |
|
239 | + do_action( |
|
240 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
241 | + $total_line_items, |
|
242 | + $valid_ticket_line_items, |
|
243 | + $expired_ticket_IDs |
|
244 | + ); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
255 | + * |
|
256 | + * @param int $qty |
|
257 | + * @param EE_Ticket $ticket |
|
258 | + * @return bool |
|
259 | + * @throws UnexpectedEntityException |
|
260 | + * @throws EE_Error |
|
261 | + */ |
|
262 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
263 | + { |
|
264 | + $qty = absint($qty); |
|
265 | + if ($qty > 0) { |
|
266 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
267 | + } |
|
268 | + if (self::debug) { |
|
269 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
270 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
271 | + } |
|
272 | + return $qty; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
279 | + * |
|
280 | + * @param EE_Ticket $ticket |
|
281 | + * @param int $qty |
|
282 | + * @return int |
|
283 | + * @throws UnexpectedEntityException |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
287 | + { |
|
288 | + if (self::debug) { |
|
289 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
290 | + } |
|
291 | + if (! $ticket instanceof EE_Ticket) { |
|
292 | + return 0; |
|
293 | + } |
|
294 | + if (self::debug) { |
|
295 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
296 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
297 | + } |
|
298 | + $ticket->refresh_from_db(); |
|
299 | + // first let's determine the ticket availability based on sales |
|
300 | + $available = $ticket->qty('saleable'); |
|
301 | + if (self::debug) { |
|
302 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
303 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
304 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
305 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
306 | + echo '<br /> . . . available: ' . $available; |
|
307 | + } |
|
308 | + if ($available < 1) { |
|
309 | + $this->_ticket_sold_out($ticket); |
|
310 | + return 0; |
|
311 | + } |
|
312 | + if (self::debug) { |
|
313 | + echo '<br /> . . . qty: ' . $qty; |
|
314 | + } |
|
315 | + if ($available < $qty) { |
|
316 | + $qty = $available; |
|
317 | + if (self::debug) { |
|
318 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
319 | + } |
|
320 | + $this->_ticket_quantity_decremented($ticket); |
|
321 | + } |
|
322 | + $this->_reserve_ticket($ticket, $qty); |
|
323 | + return $qty; |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * increments ticket reserved based on quantity passed |
|
330 | + * |
|
331 | + * @param EE_Ticket $ticket |
|
332 | + * @param int $quantity |
|
333 | + * @return bool |
|
334 | + * @throws EE_Error |
|
335 | + */ |
|
336 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
337 | + { |
|
338 | + if (self::debug) { |
|
339 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
340 | + } |
|
341 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
342 | + return $ticket->save(); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @param EE_Ticket $ticket |
|
349 | + * @param int $quantity |
|
350 | + * @return bool |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
354 | + { |
|
355 | + if (self::debug) { |
|
356 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
357 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
358 | + } |
|
359 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
360 | + if (self::debug) { |
|
361 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
362 | + } |
|
363 | + return $ticket->save() ? 1 : 0; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * removes quantities within the ticket selector based on zero ticket availability |
|
370 | + * |
|
371 | + * @param EE_Ticket $ticket |
|
372 | + * @return void |
|
373 | + * @throws UnexpectedEntityException |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
377 | + { |
|
378 | + if (self::debug) { |
|
379 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
380 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
381 | + } |
|
382 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
389 | + * |
|
390 | + * @param EE_Ticket $ticket |
|
391 | + * @return void |
|
392 | + * @throws UnexpectedEntityException |
|
393 | + * @throws EE_Error |
|
394 | + */ |
|
395 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
396 | + { |
|
397 | + if (self::debug) { |
|
398 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
399 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
400 | + } |
|
401 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * builds string out of ticket and event name |
|
408 | + * |
|
409 | + * @param EE_Ticket $ticket |
|
410 | + * @return string |
|
411 | + * @throws UnexpectedEntityException |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
415 | + { |
|
416 | + $event = $ticket->get_related_event(); |
|
417 | + if ($event instanceof EE_Event) { |
|
418 | + $ticket_name = sprintf( |
|
419 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
420 | + $ticket->name(), |
|
421 | + $event->name() |
|
422 | + ); |
|
423 | + } else { |
|
424 | + $ticket_name = $ticket->name(); |
|
425 | + } |
|
426 | + return $ticket_name; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /********************************** EVENT CART **********************************/ |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * releases or reserves ticket(s) based on quantity passed |
|
437 | + * |
|
438 | + * @param EE_Line_Item $line_item |
|
439 | + * @param int $quantity |
|
440 | + * @return void |
|
441 | + * @throws EE_Error |
|
442 | + * @throws InvalidArgumentException |
|
443 | + * @throws InvalidDataTypeException |
|
444 | + * @throws InvalidInterfaceException |
|
445 | + */ |
|
446 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
447 | + { |
|
448 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
449 | + if ($ticket instanceof EE_Ticket) { |
|
450 | + $ticket->add_extra_meta( |
|
451 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
452 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
453 | + ); |
|
454 | + if ($quantity > 0) { |
|
455 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
456 | + } else { |
|
457 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
458 | + } |
|
459 | + } |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * releases reserved ticket(s) based on quantity passed |
|
466 | + * |
|
467 | + * @param EE_Ticket $ticket |
|
468 | + * @param int $quantity |
|
469 | + * @return void |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
473 | + { |
|
474 | + $ticket->add_extra_meta( |
|
475 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
476 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
477 | + ); |
|
478 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /********************************** POST_NOTICES **********************************/ |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @return void |
|
489 | + * @throws EE_Error |
|
490 | + * @throws InvalidArgumentException |
|
491 | + * @throws ReflectionException |
|
492 | + * @throws InvalidDataTypeException |
|
493 | + * @throws InvalidInterfaceException |
|
494 | + */ |
|
495 | + public static function post_notices() |
|
496 | + { |
|
497 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * @return void |
|
504 | + * @throws EE_Error |
|
505 | + * @throws InvalidArgumentException |
|
506 | + * @throws ReflectionException |
|
507 | + * @throws InvalidDataTypeException |
|
508 | + * @throws InvalidInterfaceException |
|
509 | + */ |
|
510 | + protected function _post_notices() |
|
511 | + { |
|
512 | + if (self::debug) { |
|
513 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
514 | + } |
|
515 | + $refresh_msg = ''; |
|
516 | + $none_added_msg = ''; |
|
517 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
518 | + $refresh_msg = __( |
|
519 | + 'Please refresh the page to view updated ticket quantities.', |
|
520 | + 'event_espresso' |
|
521 | + ); |
|
522 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
523 | + } |
|
524 | + if (! empty($this->sold_out_tickets)) { |
|
525 | + EE_Error::add_attention( |
|
526 | + sprintf( |
|
527 | + apply_filters( |
|
528 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
529 | + __( |
|
530 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
531 | + 'event_espresso' |
|
532 | + ) |
|
533 | + ), |
|
534 | + '<br />', |
|
535 | + implode('<br />', $this->sold_out_tickets), |
|
536 | + $none_added_msg, |
|
537 | + $refresh_msg |
|
538 | + ) |
|
539 | + ); |
|
540 | + // alter code flow in the Ticket Selector for better UX |
|
541 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
542 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
543 | + $this->sold_out_tickets = array(); |
|
544 | + // and reset the cart |
|
545 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
546 | + } |
|
547 | + if (! empty($this->decremented_tickets)) { |
|
548 | + EE_Error::add_attention( |
|
549 | + sprintf( |
|
550 | + apply_filters( |
|
551 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
552 | + __( |
|
553 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
554 | + 'event_espresso' |
|
555 | + ) |
|
556 | + ), |
|
557 | + '<br />', |
|
558 | + implode('<br />', $this->decremented_tickets), |
|
559 | + $none_added_msg, |
|
560 | + $refresh_msg |
|
561 | + ) |
|
562 | + ); |
|
563 | + $this->decremented_tickets = array(); |
|
564 | + } |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
575 | + * by default, will NOT release tickets for finalized transactions |
|
576 | + * |
|
577 | + * @param EE_Transaction $transaction |
|
578 | + * @return int |
|
579 | + * @throws EE_Error |
|
580 | + * @throws InvalidSessionDataException |
|
581 | + */ |
|
582 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
583 | + { |
|
584 | + if (self::debug) { |
|
585 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
586 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
587 | + echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
588 | + } |
|
589 | + // check if 'finalize_registration' step has been completed... |
|
590 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
591 | + if (self::debug) { |
|
592 | + // DEBUG LOG |
|
593 | + EEH_Debug_Tools::log( |
|
594 | + __CLASS__, |
|
595 | + __FUNCTION__, |
|
596 | + __LINE__, |
|
597 | + array('finalized' => $finalized), |
|
598 | + false, |
|
599 | + 'EE_Transaction: ' . $transaction->ID() |
|
600 | + ); |
|
601 | + } |
|
602 | + // how many tickets were released |
|
603 | + $count = 0; |
|
604 | + if (self::debug) { |
|
605 | + echo '<br /> . . . TXN finalized: ' . $finalized; |
|
606 | + } |
|
607 | + $release_tickets_with_TXN_status = array( |
|
608 | + EEM_Transaction::failed_status_code, |
|
609 | + EEM_Transaction::abandoned_status_code, |
|
610 | + EEM_Transaction::incomplete_status_code, |
|
611 | + ); |
|
612 | + $events = array(); |
|
613 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
614 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
615 | + // cancel any reserved tickets for registrations that were not approved |
|
616 | + $registrations = $transaction->registrations(); |
|
617 | + if (self::debug) { |
|
618 | + echo '<br /> . . . # registrations: ' . count($registrations); |
|
619 | + $reg = reset($registrations); |
|
620 | + $ticket = $reg->ticket(); |
|
621 | + if ($ticket instanceof EE_Ticket) { |
|
622 | + $ticket->add_extra_meta( |
|
623 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
624 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
625 | + ); |
|
626 | + } |
|
627 | + } |
|
628 | + if (! empty($registrations)) { |
|
629 | + foreach ($registrations as $registration) { |
|
630 | + if ( |
|
631 | + $registration instanceof EE_Registration |
|
632 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
633 | + ) { |
|
634 | + $count++; |
|
635 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
636 | + } |
|
637 | + } |
|
638 | + } |
|
639 | + } |
|
640 | + if ($events !== array()) { |
|
641 | + foreach ($events as $event) { |
|
642 | + /** @var EE_Event $event */ |
|
643 | + $event->perform_sold_out_status_check(); |
|
644 | + } |
|
645 | + } |
|
646 | + return $count; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * releases reserved tickets for an EE_Registration |
|
653 | + * by default, will NOT release tickets for APPROVED registrations |
|
654 | + * |
|
655 | + * @param EE_Registration $registration |
|
656 | + * @param EE_Transaction $transaction |
|
657 | + * @return int |
|
658 | + * @throws EE_Error |
|
659 | + */ |
|
660 | + protected function _release_reserved_ticket_for_registration( |
|
661 | + EE_Registration $registration, |
|
662 | + EE_Transaction $transaction |
|
663 | + ) { |
|
664 | + $STS_ID = $transaction->status_ID(); |
|
665 | + if (self::debug) { |
|
666 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
667 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
668 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
669 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
670 | + } |
|
671 | + if ( |
|
672 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
673 | + $STS_ID === EEM_Transaction::failed_status_code |
|
674 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
675 | + || ( |
|
676 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
677 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
678 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
679 | + ) |
|
680 | + ) { |
|
681 | + if (self::debug) { |
|
682 | + echo '<br /><br /> . . RELEASE RESERVED TICKET'; |
|
683 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
684 | + echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
685 | + var_dump($rsrvd); |
|
686 | + } |
|
687 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
688 | + return 1; |
|
689 | + } |
|
690 | + return 0; |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + |
|
695 | + /********************************** SESSION_CART_RESET **********************************/ |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
701 | + * |
|
702 | + * @param EE_Session $session |
|
703 | + * @return void |
|
704 | + * @throws EE_Error |
|
705 | + * @throws InvalidArgumentException |
|
706 | + * @throws ReflectionException |
|
707 | + * @throws InvalidDataTypeException |
|
708 | + * @throws InvalidInterfaceException |
|
709 | + */ |
|
710 | + public static function session_cart_reset(EE_Session $session) |
|
711 | + { |
|
712 | + if (self::debug) { |
|
713 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
714 | + } |
|
715 | + // first check of the session has a valid Checkout object |
|
716 | + $checkout = $session->checkout(); |
|
717 | + if ($checkout instanceof EE_Checkout) { |
|
718 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
719 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
720 | + return; |
|
721 | + } |
|
722 | + $cart = $session->cart(); |
|
723 | + if ($cart instanceof EE_Cart) { |
|
724 | + if (self::debug) { |
|
725 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
726 | + } |
|
727 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
728 | + } else { |
|
729 | + if (self::debug) { |
|
730 | + echo '<br /><br /> invalid EE_Cart: '; |
|
731 | + var_export($cart, true); |
|
732 | + } |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * releases reserved tickets in the EE_Cart |
|
740 | + * |
|
741 | + * @param EE_Cart $cart |
|
742 | + * @return void |
|
743 | + * @throws EE_Error |
|
744 | + * @throws InvalidArgumentException |
|
745 | + * @throws ReflectionException |
|
746 | + * @throws InvalidDataTypeException |
|
747 | + * @throws InvalidInterfaceException |
|
748 | + */ |
|
749 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
750 | + { |
|
751 | + if (self::debug) { |
|
752 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
753 | + } |
|
754 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
755 | + $ticket_line_items = $cart->get_tickets(); |
|
756 | + if (empty($ticket_line_items)) { |
|
757 | + return; |
|
758 | + } |
|
759 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
760 | + if (self::debug) { |
|
761 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
762 | + } |
|
763 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
764 | + if (self::debug) { |
|
765 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
766 | + } |
|
767 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
768 | + if ($ticket instanceof EE_Ticket) { |
|
769 | + if (self::debug) { |
|
770 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
771 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
772 | + } |
|
773 | + $ticket->add_extra_meta( |
|
774 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
775 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
776 | + ); |
|
777 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
778 | + } |
|
779 | + } |
|
780 | + } |
|
781 | + if (self::debug) { |
|
782 | + echo '<br /><br /> RESET COMPLETED '; |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
794 | + * |
|
795 | + * @param EE_Session $session |
|
796 | + * @return void |
|
797 | + * @throws EE_Error |
|
798 | + * @throws InvalidSessionDataException |
|
799 | + */ |
|
800 | + public static function session_checkout_reset(EE_Session $session) |
|
801 | + { |
|
802 | + $checkout = $session->checkout(); |
|
803 | + if ($checkout instanceof EE_Checkout) { |
|
804 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
805 | + } |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * releases reserved tickets for the EE_Checkout->transaction |
|
812 | + * |
|
813 | + * @param EE_Checkout $checkout |
|
814 | + * @return void |
|
815 | + * @throws EE_Error |
|
816 | + * @throws InvalidSessionDataException |
|
817 | + */ |
|
818 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
819 | + { |
|
820 | + if (self::debug) { |
|
821 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
822 | + } |
|
823 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
824 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
825 | + return; |
|
826 | + } |
|
827 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + |
|
832 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
833 | + |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * @param EE_Session $session |
|
838 | + * @return void |
|
839 | + */ |
|
840 | + public static function session_expired_reset(EE_Session $session) |
|
841 | + { |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + |
|
846 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
847 | + |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
852 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
853 | + * |
|
854 | + * @param EE_Transaction $transaction |
|
855 | + * @return void |
|
856 | + * @throws EE_Error |
|
857 | + * @throws InvalidSessionDataException |
|
858 | + */ |
|
859 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
860 | + { |
|
861 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
862 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
863 | + if (self::debug) { |
|
864 | + // DEBUG LOG |
|
865 | + EEH_Debug_Tools::log( |
|
866 | + __CLASS__, |
|
867 | + __FUNCTION__, |
|
868 | + __LINE__, |
|
869 | + array($transaction), |
|
870 | + false, |
|
871 | + 'EE_Transaction: ' . $transaction->ID() |
|
872 | + ); |
|
873 | + } |
|
874 | + return; |
|
875 | + } |
|
876 | + // have their been any successful payments made ? |
|
877 | + $payments = $transaction->payments(); |
|
878 | + foreach ($payments as $payment) { |
|
879 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
880 | + if (self::debug) { |
|
881 | + // DEBUG LOG |
|
882 | + EEH_Debug_Tools::log( |
|
883 | + __CLASS__, |
|
884 | + __FUNCTION__, |
|
885 | + __LINE__, |
|
886 | + array($payment), |
|
887 | + false, |
|
888 | + 'EE_Transaction: ' . $transaction->ID() |
|
889 | + ); |
|
890 | + } |
|
891 | + return; |
|
892 | + } |
|
893 | + } |
|
894 | + // since you haven't even attempted to pay for your ticket... |
|
895 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
901 | + |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
906 | + * |
|
907 | + * @param EE_Transaction $transaction |
|
908 | + * @return void |
|
909 | + * @throws EE_Error |
|
910 | + * @throws InvalidSessionDataException |
|
911 | + */ |
|
912 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
913 | + { |
|
914 | + // since you haven't even attempted to pay for your ticket... |
|
915 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + |
|
920 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * Resets all ticket and datetime reserved counts to zero |
|
926 | + * Tickets that are currently associated with a Transaction that is in progress |
|
927 | + * |
|
928 | + * @throws EE_Error |
|
929 | + * @throws DomainException |
|
930 | + * @throws InvalidDataTypeException |
|
931 | + * @throws InvalidInterfaceException |
|
932 | + * @throws InvalidArgumentException |
|
933 | + * @throws UnexpectedEntityException |
|
934 | + */ |
|
935 | + public static function reset_reservation_counts() |
|
936 | + { |
|
937 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
938 | + $valid_reserved_tickets = array(); |
|
939 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
940 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
941 | + foreach ($transactions_not_in_progress as $transaction) { |
|
942 | + // if this TXN has been fully completed, then skip it |
|
943 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
944 | + continue; |
|
945 | + } |
|
946 | + $total_line_item = $transaction->total_line_item(); |
|
947 | + // $transaction_in_progress->line |
|
948 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
949 | + throw new DomainException( |
|
950 | + esc_html__( |
|
951 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
952 | + 'event_espresso' |
|
953 | + ) |
|
954 | + ); |
|
955 | + } |
|
956 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
957 | + $total_line_item |
|
958 | + ); |
|
959 | + } |
|
960 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
961 | + foreach ($total_line_items as $total_line_item) { |
|
962 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
963 | + $total_line_item |
|
964 | + ); |
|
965 | + } |
|
966 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
967 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
968 | + $tickets_with_reservations, |
|
969 | + $valid_reserved_tickets, |
|
970 | + __FUNCTION__ |
|
971 | + ); |
|
972 | + } |
|
973 | + |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * @param EE_Line_Item $total_line_item |
|
978 | + * @return EE_Line_Item[] |
|
979 | + */ |
|
980 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
981 | + { |
|
982 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
983 | + $valid_reserved_tickets = array(); |
|
984 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
985 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
986 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
987 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
988 | + } |
|
989 | + } |
|
990 | + return $valid_reserved_tickets; |
|
991 | + } |
|
992 | + |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * @param EE_Ticket[] $tickets_with_reservations |
|
997 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
998 | + * @return int |
|
999 | + * @throws UnexpectedEntityException |
|
1000 | + * @throws DomainException |
|
1001 | + * @throws EE_Error |
|
1002 | + */ |
|
1003 | + private static function release_reservations_for_tickets( |
|
1004 | + array $tickets_with_reservations, |
|
1005 | + array $valid_reserved_ticket_line_items = array(), |
|
1006 | + $source |
|
1007 | + ) { |
|
1008 | + $total_tickets_released = 0; |
|
1009 | + $sold_out_events = array(); |
|
1010 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1011 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1012 | + continue; |
|
1013 | + } |
|
1014 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
1015 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1016 | + if ( |
|
1017 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1018 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1019 | + ) { |
|
1020 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + if ($reserved_qty > 0) { |
|
1024 | + $ticket_with_reservations->add_extra_meta( |
|
1025 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1026 | + __LINE__ . ') ' . $source . '()' |
|
1027 | + ); |
|
1028 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
1029 | + $ticket_with_reservations->save(); |
|
1030 | + $total_tickets_released += $reserved_qty; |
|
1031 | + $event = $ticket_with_reservations->get_related_event(); |
|
1032 | + // track sold out events |
|
1033 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1034 | + $sold_out_events[] = $event; |
|
1035 | + } |
|
1036 | + } |
|
1037 | + } |
|
1038 | + // double check whether sold out events should remain sold out after releasing tickets |
|
1039 | + if($sold_out_events !== array()){ |
|
1040 | + foreach ($sold_out_events as $sold_out_event) { |
|
1041 | + /** @var EE_Event $sold_out_event */ |
|
1042 | + $sold_out_event->perform_sold_out_status_check(); |
|
1043 | + } |
|
1044 | + } |
|
1045 | + return $total_tickets_released; |
|
1046 | + } |
|
1047 | + |
|
1048 | + |
|
1049 | + |
|
1050 | + /********************************** SHUTDOWN **********************************/ |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @return false|int |
|
1056 | + * @throws EE_Error |
|
1057 | + * @throws InvalidArgumentException |
|
1058 | + * @throws InvalidDataTypeException |
|
1059 | + * @throws InvalidInterfaceException |
|
1060 | + */ |
|
1061 | + public static function clear_expired_line_items_with_no_transaction() |
|
1062 | + { |
|
1063 | + /** @type WPDB $wpdb */ |
|
1064 | + global $wpdb; |
|
1065 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1066 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1067 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1068 | + ); |
|
1069 | + return $wpdb->query( |
|
1070 | + $wpdb->prepare( |
|
1071 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1072 | 1072 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1073 | - // use GMT time because that's what LIN_timestamps are in |
|
1074 | - date('Y-m-d H:i:s', $session_lifespan->expiration()) |
|
1075 | - ) |
|
1076 | - ); |
|
1077 | - } |
|
1073 | + // use GMT time because that's what LIN_timestamps are in |
|
1074 | + date('Y-m-d H:i:s', $session_lifespan->expiration()) |
|
1075 | + ) |
|
1076 | + ); |
|
1077 | + } |
|
1078 | 1078 | |
1079 | 1079 | } |
1080 | 1080 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | class EED_Ticket_Sales_Monitor extends EED_Module |
25 | 25 | { |
26 | 26 | |
27 | - const debug = false; // true false |
|
27 | + const debug = false; // true false |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | /** @var EE_Line_Item $total_line_item */ |
214 | 214 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
215 | 215 | foreach ($ticket_line_items as $ticket_line_item) { |
216 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
216 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
217 | 217 | continue; |
218 | 218 | } |
219 | 219 | if ($total_line_item->timestamp(true) <= $session_lifespan->expiration()) { |
220 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
220 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
221 | 221 | } else { |
222 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
222 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | } |
226 | - if (! empty($expired_ticket_IDs)) { |
|
226 | + if ( ! empty($expired_ticket_IDs)) { |
|
227 | 227 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
228 | 228 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
229 | 229 | $valid_ticket_line_items, |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
267 | 267 | } |
268 | 268 | if (self::debug) { |
269 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
270 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
269 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
270 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
271 | 271 | } |
272 | 272 | return $qty; |
273 | 273 | } |
@@ -286,36 +286,36 @@ discard block |
||
286 | 286 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
287 | 287 | { |
288 | 288 | if (self::debug) { |
289 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
289 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
290 | 290 | } |
291 | - if (! $ticket instanceof EE_Ticket) { |
|
291 | + if ( ! $ticket instanceof EE_Ticket) { |
|
292 | 292 | return 0; |
293 | 293 | } |
294 | 294 | if (self::debug) { |
295 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
296 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
295 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
296 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
297 | 297 | } |
298 | 298 | $ticket->refresh_from_db(); |
299 | 299 | // first let's determine the ticket availability based on sales |
300 | 300 | $available = $ticket->qty('saleable'); |
301 | 301 | if (self::debug) { |
302 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
303 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
304 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
305 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
306 | - echo '<br /> . . . available: ' . $available; |
|
302 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
303 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
304 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
305 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
306 | + echo '<br /> . . . available: '.$available; |
|
307 | 307 | } |
308 | 308 | if ($available < 1) { |
309 | 309 | $this->_ticket_sold_out($ticket); |
310 | 310 | return 0; |
311 | 311 | } |
312 | 312 | if (self::debug) { |
313 | - echo '<br /> . . . qty: ' . $qty; |
|
313 | + echo '<br /> . . . qty: '.$qty; |
|
314 | 314 | } |
315 | 315 | if ($available < $qty) { |
316 | 316 | $qty = $available; |
317 | 317 | if (self::debug) { |
318 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
318 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
319 | 319 | } |
320 | 320 | $this->_ticket_quantity_decremented($ticket); |
321 | 321 | } |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
337 | 337 | { |
338 | 338 | if (self::debug) { |
339 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
339 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
340 | 340 | } |
341 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
341 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
342 | 342 | return $ticket->save(); |
343 | 343 | } |
344 | 344 | |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
354 | 354 | { |
355 | 355 | if (self::debug) { |
356 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
357 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
356 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
357 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
358 | 358 | } |
359 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
359 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
360 | 360 | if (self::debug) { |
361 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
361 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
362 | 362 | } |
363 | 363 | return $ticket->save() ? 1 : 0; |
364 | 364 | } |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | protected function _ticket_sold_out(EE_Ticket $ticket) |
377 | 377 | { |
378 | 378 | if (self::debug) { |
379 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
380 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
379 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
380 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
381 | 381 | } |
382 | 382 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
383 | 383 | } |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
396 | 396 | { |
397 | 397 | if (self::debug) { |
398 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
399 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
398 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
399 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
400 | 400 | } |
401 | 401 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
402 | 402 | } |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | if ($ticket instanceof EE_Ticket) { |
450 | 450 | $ticket->add_extra_meta( |
451 | 451 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
452 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
452 | + __LINE__.') '.__METHOD__.'()' |
|
453 | 453 | ); |
454 | 454 | if ($quantity > 0) { |
455 | 455 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | { |
474 | 474 | $ticket->add_extra_meta( |
475 | 475 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
476 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
476 | + __LINE__.') '.__METHOD__.'()' |
|
477 | 477 | ); |
478 | 478 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
479 | 479 | } |
@@ -510,18 +510,18 @@ discard block |
||
510 | 510 | protected function _post_notices() |
511 | 511 | { |
512 | 512 | if (self::debug) { |
513 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
513 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
514 | 514 | } |
515 | 515 | $refresh_msg = ''; |
516 | 516 | $none_added_msg = ''; |
517 | 517 | if (defined('DOING_AJAX') && DOING_AJAX) { |
518 | - $refresh_msg = __( |
|
518 | + $refresh_msg = __( |
|
519 | 519 | 'Please refresh the page to view updated ticket quantities.', |
520 | 520 | 'event_espresso' |
521 | 521 | ); |
522 | 522 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
523 | 523 | } |
524 | - if (! empty($this->sold_out_tickets)) { |
|
524 | + if ( ! empty($this->sold_out_tickets)) { |
|
525 | 525 | EE_Error::add_attention( |
526 | 526 | sprintf( |
527 | 527 | apply_filters( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | // and reset the cart |
545 | 545 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
546 | 546 | } |
547 | - if (! empty($this->decremented_tickets)) { |
|
547 | + if ( ! empty($this->decremented_tickets)) { |
|
548 | 548 | EE_Error::add_attention( |
549 | 549 | sprintf( |
550 | 550 | apply_filters( |
@@ -582,9 +582,9 @@ discard block |
||
582 | 582 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
583 | 583 | { |
584 | 584 | if (self::debug) { |
585 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
586 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
587 | - echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
585 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
586 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
587 | + echo '<br /> . TXN status_ID: '.$transaction->status_ID(); |
|
588 | 588 | } |
589 | 589 | // check if 'finalize_registration' step has been completed... |
590 | 590 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -596,13 +596,13 @@ discard block |
||
596 | 596 | __LINE__, |
597 | 597 | array('finalized' => $finalized), |
598 | 598 | false, |
599 | - 'EE_Transaction: ' . $transaction->ID() |
|
599 | + 'EE_Transaction: '.$transaction->ID() |
|
600 | 600 | ); |
601 | 601 | } |
602 | 602 | // how many tickets were released |
603 | 603 | $count = 0; |
604 | 604 | if (self::debug) { |
605 | - echo '<br /> . . . TXN finalized: ' . $finalized; |
|
605 | + echo '<br /> . . . TXN finalized: '.$finalized; |
|
606 | 606 | } |
607 | 607 | $release_tickets_with_TXN_status = array( |
608 | 608 | EEM_Transaction::failed_status_code, |
@@ -611,28 +611,28 @@ discard block |
||
611 | 611 | ); |
612 | 612 | $events = array(); |
613 | 613 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
614 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
614 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
615 | 615 | // cancel any reserved tickets for registrations that were not approved |
616 | 616 | $registrations = $transaction->registrations(); |
617 | 617 | if (self::debug) { |
618 | - echo '<br /> . . . # registrations: ' . count($registrations); |
|
618 | + echo '<br /> . . . # registrations: '.count($registrations); |
|
619 | 619 | $reg = reset($registrations); |
620 | 620 | $ticket = $reg->ticket(); |
621 | 621 | if ($ticket instanceof EE_Ticket) { |
622 | 622 | $ticket->add_extra_meta( |
623 | 623 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
624 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
624 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
625 | 625 | ); |
626 | 626 | } |
627 | 627 | } |
628 | - if (! empty($registrations)) { |
|
628 | + if ( ! empty($registrations)) { |
|
629 | 629 | foreach ($registrations as $registration) { |
630 | 630 | if ( |
631 | 631 | $registration instanceof EE_Registration |
632 | 632 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
633 | 633 | ) { |
634 | 634 | $count++; |
635 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
635 | + $events[$registration->event_ID()] = $registration->event(); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | } |
@@ -663,10 +663,10 @@ discard block |
||
663 | 663 | ) { |
664 | 664 | $STS_ID = $transaction->status_ID(); |
665 | 665 | if (self::debug) { |
666 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
667 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
668 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
669 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
666 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
667 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
668 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
669 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
670 | 670 | } |
671 | 671 | if ( |
672 | 672 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
685 | 685 | var_dump($rsrvd); |
686 | 686 | } |
687 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
687 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
688 | 688 | return 1; |
689 | 689 | } |
690 | 690 | return 0; |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | public static function session_cart_reset(EE_Session $session) |
711 | 711 | { |
712 | 712 | if (self::debug) { |
713 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
713 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
714 | 714 | } |
715 | 715 | // first check of the session has a valid Checkout object |
716 | 716 | $checkout = $session->checkout(); |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
750 | 750 | { |
751 | 751 | if (self::debug) { |
752 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
752 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
753 | 753 | } |
754 | 754 | EE_Registry::instance()->load_helper('Line_Item'); |
755 | 755 | $ticket_line_items = $cart->get_tickets(); |
@@ -758,21 +758,21 @@ discard block |
||
758 | 758 | } |
759 | 759 | foreach ($ticket_line_items as $ticket_line_item) { |
760 | 760 | if (self::debug) { |
761 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
761 | + echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
762 | 762 | } |
763 | 763 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
764 | 764 | if (self::debug) { |
765 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
765 | + echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
766 | 766 | } |
767 | 767 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
768 | 768 | if ($ticket instanceof EE_Ticket) { |
769 | 769 | if (self::debug) { |
770 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
771 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
770 | + echo '<br /> . . ticket->ID(): '.$ticket->ID(); |
|
771 | + echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
772 | 772 | } |
773 | 773 | $ticket->add_extra_meta( |
774 | 774 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
775 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
775 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
776 | 776 | ); |
777 | 777 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
778 | 778 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | protected function _session_checkout_reset(EE_Checkout $checkout) |
819 | 819 | { |
820 | 820 | if (self::debug) { |
821 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
821 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
822 | 822 | } |
823 | 823 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
824 | 824 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | __LINE__, |
869 | 869 | array($transaction), |
870 | 870 | false, |
871 | - 'EE_Transaction: ' . $transaction->ID() |
|
871 | + 'EE_Transaction: '.$transaction->ID() |
|
872 | 872 | ); |
873 | 873 | } |
874 | 874 | return; |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | __LINE__, |
886 | 886 | array($payment), |
887 | 887 | false, |
888 | - 'EE_Transaction: ' . $transaction->ID() |
|
888 | + 'EE_Transaction: '.$transaction->ID() |
|
889 | 889 | ); |
890 | 890 | } |
891 | 891 | return; |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | } |
946 | 946 | $total_line_item = $transaction->total_line_item(); |
947 | 947 | // $transaction_in_progress->line |
948 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
948 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
949 | 949 | throw new DomainException( |
950 | 950 | esc_html__( |
951 | 951 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | $total_tickets_released = 0; |
1009 | 1009 | $sold_out_events = array(); |
1010 | 1010 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
1011 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1011 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
1012 | 1012 | continue; |
1013 | 1013 | } |
1014 | 1014 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | if ($reserved_qty > 0) { |
1024 | 1024 | $ticket_with_reservations->add_extra_meta( |
1025 | 1025 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
1026 | - __LINE__ . ') ' . $source . '()' |
|
1026 | + __LINE__.') '.$source.'()' |
|
1027 | 1027 | ); |
1028 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
1028 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__); |
|
1029 | 1029 | $ticket_with_reservations->save(); |
1030 | 1030 | $total_tickets_released += $reserved_qty; |
1031 | 1031 | $event = $ticket_with_reservations->get_related_event(); |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | // double check whether sold out events should remain sold out after releasing tickets |
1039 | - if($sold_out_events !== array()){ |
|
1039 | + if ($sold_out_events !== array()) { |
|
1040 | 1040 | foreach ($sold_out_events as $sold_out_event) { |
1041 | 1041 | /** @var EE_Event $sold_out_event */ |
1042 | 1042 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | ); |
1069 | 1069 | return $wpdb->query( |
1070 | 1070 | $wpdb->prepare( |
1071 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1071 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
1072 | 1072 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1073 | 1073 | // use GMT time because that's what LIN_timestamps are in |
1074 | 1074 | date('Y-m-d H:i:s', $session_lifespan->expiration()) |
@@ -17,121 +17,121 @@ discard block |
||
17 | 17 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var SessionLifespan $session_lifespan |
|
22 | - */ |
|
23 | - private $session_lifespan; |
|
24 | - |
|
25 | - private $_status; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param \Transactions_Admin_Page $admin_page |
|
30 | - * @param SessionLifespan $lifespan |
|
31 | - */ |
|
32 | - public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
33 | - { |
|
34 | - parent::__construct($admin_page); |
|
35 | - $this->session_lifespan = $lifespan; |
|
36 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - *_setup_data |
|
42 | - */ |
|
43 | - protected function _setup_data() |
|
44 | - { |
|
45 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
46 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
47 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - *_set_properties |
|
53 | - */ |
|
54 | - protected function _set_properties() |
|
55 | - { |
|
56 | - $this->_wp_list_args = array( |
|
57 | - 'singular' => __('transaction', 'event_espresso'), |
|
58 | - 'plural' => __('transactions', 'event_espresso'), |
|
59 | - 'ajax' => true, |
|
60 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
61 | - ); |
|
62 | - $ID_column_name = __('ID', 'event_espresso'); |
|
63 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
64 | - $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
65 | - $ID_column_name .= '</span> '; |
|
66 | - $this->_columns = array( |
|
67 | - 'TXN_ID' => $ID_column_name, |
|
68 | - 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
69 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
70 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
71 | - 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
72 | - 'event_name' => __('Event', 'event_espresso'), |
|
73 | - 'actions' => __('Actions', 'event_espresso'), |
|
74 | - ); |
|
75 | - |
|
76 | - $this->_sortable_columns = array( |
|
77 | - 'TXN_ID' => array('TXN_ID' => false), |
|
78 | - 'event_name' => array('event_name' => false), |
|
79 | - 'ATT_fname' => array('ATT_fname' => false), |
|
80 | - 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
81 | - ); |
|
82 | - |
|
83 | - $this->_primary_column = 'TXN_ID'; |
|
84 | - |
|
85 | - $this->_hidden_columns = array(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * This simply sets up the row class for the table rows. |
|
91 | - * Allows for easier overriding of child methods for setting up sorting. |
|
92 | - * |
|
93 | - * @param EE_Transaction $transaction the current item |
|
94 | - * @return string |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
97 | - protected function _get_row_class($transaction) |
|
98 | - { |
|
99 | - $class = parent::_get_row_class($transaction); |
|
100 | - //add status class |
|
101 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
102 | - if ($this->_has_checkbox_column) { |
|
103 | - $class .= ' has-checkbox-column'; |
|
104 | - } |
|
105 | - return $class; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * _get_table_filters |
|
111 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
112 | - * get's shown in the table. |
|
113 | - * |
|
114 | - * @abstract |
|
115 | - * @access protected |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - protected function _get_table_filters() |
|
119 | - { |
|
120 | - $filters = array(); |
|
121 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
122 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
123 | - : date( |
|
124 | - 'm/d/Y', |
|
125 | - strtotime('-10 year') |
|
126 | - ); |
|
127 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
128 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
129 | - : date( |
|
130 | - 'm/d/Y', |
|
131 | - current_time('timestamp') |
|
132 | - ); |
|
133 | - ob_start(); |
|
134 | - ?> |
|
20 | + /** |
|
21 | + * @var SessionLifespan $session_lifespan |
|
22 | + */ |
|
23 | + private $session_lifespan; |
|
24 | + |
|
25 | + private $_status; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param \Transactions_Admin_Page $admin_page |
|
30 | + * @param SessionLifespan $lifespan |
|
31 | + */ |
|
32 | + public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan) |
|
33 | + { |
|
34 | + parent::__construct($admin_page); |
|
35 | + $this->session_lifespan = $lifespan; |
|
36 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + *_setup_data |
|
42 | + */ |
|
43 | + protected function _setup_data() |
|
44 | + { |
|
45 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
46 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
47 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + *_set_properties |
|
53 | + */ |
|
54 | + protected function _set_properties() |
|
55 | + { |
|
56 | + $this->_wp_list_args = array( |
|
57 | + 'singular' => __('transaction', 'event_espresso'), |
|
58 | + 'plural' => __('transactions', 'event_espresso'), |
|
59 | + 'ajax' => true, |
|
60 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
61 | + ); |
|
62 | + $ID_column_name = __('ID', 'event_espresso'); |
|
63 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
64 | + $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
65 | + $ID_column_name .= '</span> '; |
|
66 | + $this->_columns = array( |
|
67 | + 'TXN_ID' => $ID_column_name, |
|
68 | + 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
69 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
70 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
71 | + 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
72 | + 'event_name' => __('Event', 'event_espresso'), |
|
73 | + 'actions' => __('Actions', 'event_espresso'), |
|
74 | + ); |
|
75 | + |
|
76 | + $this->_sortable_columns = array( |
|
77 | + 'TXN_ID' => array('TXN_ID' => false), |
|
78 | + 'event_name' => array('event_name' => false), |
|
79 | + 'ATT_fname' => array('ATT_fname' => false), |
|
80 | + 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
81 | + ); |
|
82 | + |
|
83 | + $this->_primary_column = 'TXN_ID'; |
|
84 | + |
|
85 | + $this->_hidden_columns = array(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * This simply sets up the row class for the table rows. |
|
91 | + * Allows for easier overriding of child methods for setting up sorting. |
|
92 | + * |
|
93 | + * @param EE_Transaction $transaction the current item |
|
94 | + * @return string |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | + protected function _get_row_class($transaction) |
|
98 | + { |
|
99 | + $class = parent::_get_row_class($transaction); |
|
100 | + //add status class |
|
101 | + $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
102 | + if ($this->_has_checkbox_column) { |
|
103 | + $class .= ' has-checkbox-column'; |
|
104 | + } |
|
105 | + return $class; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * _get_table_filters |
|
111 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
112 | + * get's shown in the table. |
|
113 | + * |
|
114 | + * @abstract |
|
115 | + * @access protected |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + protected function _get_table_filters() |
|
119 | + { |
|
120 | + $filters = array(); |
|
121 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
122 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
123 | + : date( |
|
124 | + 'm/d/Y', |
|
125 | + strtotime('-10 year') |
|
126 | + ); |
|
127 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
128 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
129 | + : date( |
|
130 | + 'm/d/Y', |
|
131 | + current_time('timestamp') |
|
132 | + ); |
|
133 | + ob_start(); |
|
134 | + ?> |
|
135 | 135 | <label for="txn-filter-start-date">Display Transactions from </label> |
136 | 136 | <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" |
137 | 137 | name="txn-filter-start-date" size="15"/> |
@@ -139,551 +139,551 @@ discard block |
||
139 | 139 | <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" |
140 | 140 | name="txn-filter-end-date" size="15"/> |
141 | 141 | <?php |
142 | - $filters[] = ob_get_contents(); |
|
143 | - ob_end_clean(); |
|
144 | - return $filters; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - *_add_view_counts |
|
150 | - */ |
|
151 | - protected function _add_view_counts() |
|
152 | - { |
|
153 | - $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
154 | - $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
155 | - $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * column TXN_ID |
|
161 | - * |
|
162 | - * @param \EE_Transaction $transaction |
|
163 | - * @return string |
|
164 | - * @throws \EE_Error |
|
165 | - */ |
|
166 | - public function column_TXN_ID(EE_Transaction $transaction) |
|
167 | - { |
|
168 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
169 | - 'action' => 'view_transaction', |
|
170 | - 'TXN_ID' => $transaction->ID(), |
|
171 | - ), TXN_ADMIN_URL); |
|
172 | - $content = '<a href="' . $view_lnk_url . '"' |
|
173 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
174 | - . $transaction->ID() |
|
175 | - . '</a>'; |
|
176 | - |
|
177 | - //txn timestamp |
|
178 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
179 | - return $content; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param \EE_Transaction $transaction |
|
185 | - * @return string |
|
186 | - * @throws EE_Error |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - */ |
|
191 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
192 | - { |
|
193 | - // is TXN less than 2 hours old ? |
|
194 | - if (($transaction->failed() || $transaction->is_abandoned()) |
|
195 | - && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
196 | - ) { |
|
197 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
198 | - } else { |
|
199 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
200 | - } |
|
201 | - return $timestamp; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * column_cb |
|
207 | - * |
|
208 | - * @param \EE_Transaction $transaction |
|
209 | - * @return string |
|
210 | - * @throws \EE_Error |
|
211 | - */ |
|
212 | - public function column_cb($transaction) |
|
213 | - { |
|
214 | - return sprintf( |
|
215 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
216 | - $this->_wp_list_args['singular'], |
|
217 | - $transaction->ID() |
|
218 | - ); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * column_TXN_timestamp |
|
224 | - * |
|
225 | - * @param \EE_Transaction $transaction |
|
226 | - * @return string |
|
227 | - * @throws \EE_Error |
|
228 | - */ |
|
229 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
230 | - { |
|
231 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
232 | - 'action' => 'view_transaction', |
|
233 | - 'TXN_ID' => $transaction->ID(), |
|
234 | - ), TXN_ADMIN_URL); |
|
235 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
236 | - . ' title="' |
|
237 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
238 | - . $this->_get_txn_timestamp($transaction) |
|
239 | - . '</a>'; |
|
240 | - //status |
|
241 | - $txn_date .= '<br><span class="ee-status-text-small">' |
|
242 | - . EEH_Template::pretty_status( |
|
243 | - $transaction->status_ID(), |
|
244 | - false, |
|
245 | - 'sentence' |
|
246 | - ) |
|
247 | - . '</span>'; |
|
248 | - return $txn_date; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * column_TXN_total |
|
254 | - * |
|
255 | - * @param \EE_Transaction $transaction |
|
256 | - * @return string |
|
257 | - * @throws \EE_Error |
|
258 | - */ |
|
259 | - public function column_TXN_total(EE_Transaction $transaction) |
|
260 | - { |
|
261 | - if ($transaction->get('TXN_total') > 0) { |
|
262 | - return '<span class="txn-pad-rght">' |
|
263 | - . apply_filters( |
|
264 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
265 | - $transaction->get_pretty('TXN_total'), |
|
266 | - $transaction |
|
267 | - ) |
|
268 | - . '</span>'; |
|
269 | - } else { |
|
270 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * column_TXN_paid |
|
277 | - * |
|
278 | - * @param \EE_Transaction $transaction |
|
279 | - * @return mixed|string |
|
280 | - * @throws \EE_Error |
|
281 | - */ |
|
282 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
283 | - { |
|
284 | - $transaction_total = $transaction->get('TXN_total'); |
|
285 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
286 | - |
|
287 | - if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
288 | - // monies owing |
|
289 | - $span_class = 'txn-overview-part-payment-spn'; |
|
290 | - if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
291 | - // paid in full |
|
292 | - $span_class = 'txn-overview-full-payment-spn'; |
|
293 | - } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
294 | - // no payments made |
|
295 | - $span_class = 'txn-overview-no-payment-spn'; |
|
296 | - } |
|
297 | - } else { |
|
298 | - $span_class = 'txn-overview-free-event-spn'; |
|
299 | - $transaction_paid = 0; |
|
300 | - } |
|
301 | - |
|
302 | - $payment_method = $transaction->payment_method(); |
|
303 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
304 | - ? $payment_method->admin_name() |
|
305 | - : esc_html__('Unknown', 'event_espresso'); |
|
306 | - $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
307 | - |
|
308 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
309 | - . $transaction_paid_content |
|
310 | - . '</span>'; |
|
311 | - if ($transaction_paid > 0) { |
|
312 | - $content .= '<br><span class="ee-status-text-small">' |
|
313 | - . sprintf( |
|
314 | - esc_html__('...via %s', 'event_espresso'), |
|
315 | - $payment_method_name |
|
316 | - ) |
|
317 | - . '</span>'; |
|
318 | - } |
|
319 | - return $content; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * column_ATT_fname |
|
325 | - * |
|
326 | - * @param \EE_Transaction $transaction |
|
327 | - * @return string |
|
328 | - * @throws EE_Error |
|
329 | - * @throws InvalidArgumentException |
|
330 | - * @throws InvalidDataTypeException |
|
331 | - * @throws InvalidInterfaceException |
|
332 | - */ |
|
333 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
334 | - { |
|
335 | - $primary_reg = $transaction->primary_registration(); |
|
336 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
337 | - if ($attendee instanceof EE_Attendee) { |
|
338 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
339 | - 'action' => 'view_registration', |
|
340 | - '_REG_ID' => $primary_reg->ID(), |
|
341 | - ), REG_ADMIN_URL); |
|
342 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
343 | - 'ee_read_registration', |
|
344 | - 'espresso_registrations_view_registration', |
|
345 | - $primary_reg->ID() |
|
346 | - ) |
|
347 | - ? '<a href="' . $edit_lnk_url . '"' |
|
348 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
349 | - . $attendee->full_name() |
|
350 | - . '</a>' |
|
351 | - : $attendee->full_name(); |
|
352 | - $content .= '<br>' . $attendee->email(); |
|
353 | - return $content; |
|
354 | - } |
|
355 | - return $transaction->failed() || $transaction->is_abandoned() |
|
356 | - ? esc_html__('no contact record.', 'event_espresso') |
|
357 | - : esc_html__( |
|
358 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
359 | - 'event_espresso' |
|
360 | - ); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * column_ATT_email |
|
366 | - * |
|
367 | - * @param \EE_Transaction $transaction |
|
368 | - * @return string |
|
369 | - * @throws \EE_Error |
|
370 | - */ |
|
371 | - public function column_ATT_email(EE_Transaction $transaction) |
|
372 | - { |
|
373 | - $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
374 | - if (! empty($attendee)) { |
|
375 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
376 | - . $attendee->get('ATT_email') |
|
377 | - . '</a>'; |
|
378 | - } else { |
|
379 | - return $transaction->failed() || $transaction->is_abandoned() |
|
380 | - ? esc_html__('no contact record.', 'event_espresso') |
|
381 | - : esc_html__( |
|
382 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
383 | - 'event_espresso' |
|
384 | - ); |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * column_event_name |
|
391 | - * |
|
392 | - * @param \EE_Transaction $transaction |
|
393 | - * @return string |
|
394 | - * @throws EE_Error |
|
395 | - * @throws InvalidArgumentException |
|
396 | - * @throws InvalidDataTypeException |
|
397 | - * @throws InvalidInterfaceException |
|
398 | - */ |
|
399 | - public function column_event_name(EE_Transaction $transaction) |
|
400 | - { |
|
401 | - $actions = array(); |
|
402 | - $event = $transaction->primary_registration()->get_first_related('Event'); |
|
403 | - if (! empty($event)) { |
|
404 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
405 | - array('action' => 'edit', 'post' => $event->ID()), |
|
406 | - EVENTS_ADMIN_URL |
|
407 | - ); |
|
408 | - $event_name = $event->get('EVT_name'); |
|
409 | - |
|
410 | - //filter this view by transactions for this event |
|
411 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
412 | - 'action' => 'default', |
|
413 | - 'EVT_ID' => $event->ID(), |
|
414 | - )); |
|
415 | - if (empty($this->_req_data['EVT_ID']) |
|
416 | - && EE_Registry::instance()->CAP->current_user_can( |
|
417 | - 'ee_edit_event', |
|
418 | - 'espresso_events_edit', |
|
419 | - $event->ID() |
|
420 | - ) |
|
421 | - ) { |
|
422 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
423 | - . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
424 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
425 | - . '</a>'; |
|
426 | - } |
|
427 | - |
|
428 | - return sprintf( |
|
429 | - '%1$s %2$s', |
|
430 | - EE_Registry::instance()->CAP->current_user_can( |
|
431 | - 'ee_edit_event', |
|
432 | - 'espresso_events_edit', |
|
433 | - $event->ID() |
|
434 | - ) |
|
435 | - ? '<a href="' . $edit_event_url . '"' |
|
436 | - . ' title="' |
|
437 | - . sprintf( |
|
438 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
439 | - $event->get('EVT_name') |
|
440 | - ) |
|
441 | - . '">' |
|
442 | - . wp_trim_words( |
|
443 | - $event_name, |
|
444 | - 30, |
|
445 | - '...' |
|
446 | - ) |
|
447 | - . '</a>' |
|
448 | - : wp_trim_words($event_name, 30, '...'), |
|
449 | - $this->row_actions($actions) |
|
450 | - ); |
|
451 | - } else { |
|
452 | - return esc_html__( |
|
453 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
454 | - 'event_espresso' |
|
455 | - ); |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * column_actions |
|
462 | - * |
|
463 | - * @param \EE_Transaction $transaction |
|
464 | - * @return string |
|
465 | - * @throws \EE_Error |
|
466 | - */ |
|
467 | - public function column_actions(EE_Transaction $transaction) |
|
468 | - { |
|
469 | - return $this->_action_string( |
|
470 | - $this->get_transaction_details_link($transaction) |
|
471 | - . $this->get_invoice_link($transaction) |
|
472 | - . $this->get_receipt_link($transaction) |
|
473 | - . $this->get_primary_registration_details_link($transaction) |
|
474 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
475 | - . $this->get_payment_overview_link($transaction) |
|
476 | - . $this->get_related_messages_link($transaction), |
|
477 | - $transaction, |
|
478 | - 'ul', |
|
479 | - 'txn-overview-actions-ul' |
|
480 | - ); |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * Get the transaction details link. |
|
486 | - * @param EE_Transaction $transaction |
|
487 | - * @return string |
|
488 | - * @throws EE_Error |
|
489 | - */ |
|
490 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
491 | - { |
|
492 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
493 | - 'action' => 'view_transaction', |
|
494 | - 'TXN_ID' => $transaction->ID(), |
|
495 | - ), TXN_ADMIN_URL); |
|
496 | - return ' |
|
142 | + $filters[] = ob_get_contents(); |
|
143 | + ob_end_clean(); |
|
144 | + return $filters; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + *_add_view_counts |
|
150 | + */ |
|
151 | + protected function _add_view_counts() |
|
152 | + { |
|
153 | + $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
154 | + $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
155 | + $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * column TXN_ID |
|
161 | + * |
|
162 | + * @param \EE_Transaction $transaction |
|
163 | + * @return string |
|
164 | + * @throws \EE_Error |
|
165 | + */ |
|
166 | + public function column_TXN_ID(EE_Transaction $transaction) |
|
167 | + { |
|
168 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
169 | + 'action' => 'view_transaction', |
|
170 | + 'TXN_ID' => $transaction->ID(), |
|
171 | + ), TXN_ADMIN_URL); |
|
172 | + $content = '<a href="' . $view_lnk_url . '"' |
|
173 | + . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
174 | + . $transaction->ID() |
|
175 | + . '</a>'; |
|
176 | + |
|
177 | + //txn timestamp |
|
178 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
179 | + return $content; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param \EE_Transaction $transaction |
|
185 | + * @return string |
|
186 | + * @throws EE_Error |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + */ |
|
191 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
192 | + { |
|
193 | + // is TXN less than 2 hours old ? |
|
194 | + if (($transaction->failed() || $transaction->is_abandoned()) |
|
195 | + && $this->session_lifespan->expiration() < $transaction->datetime(false, true) |
|
196 | + ) { |
|
197 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
198 | + } else { |
|
199 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
200 | + } |
|
201 | + return $timestamp; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * column_cb |
|
207 | + * |
|
208 | + * @param \EE_Transaction $transaction |
|
209 | + * @return string |
|
210 | + * @throws \EE_Error |
|
211 | + */ |
|
212 | + public function column_cb($transaction) |
|
213 | + { |
|
214 | + return sprintf( |
|
215 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
216 | + $this->_wp_list_args['singular'], |
|
217 | + $transaction->ID() |
|
218 | + ); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * column_TXN_timestamp |
|
224 | + * |
|
225 | + * @param \EE_Transaction $transaction |
|
226 | + * @return string |
|
227 | + * @throws \EE_Error |
|
228 | + */ |
|
229 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
230 | + { |
|
231 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
232 | + 'action' => 'view_transaction', |
|
233 | + 'TXN_ID' => $transaction->ID(), |
|
234 | + ), TXN_ADMIN_URL); |
|
235 | + $txn_date = '<a href="' . $view_lnk_url . '"' |
|
236 | + . ' title="' |
|
237 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
238 | + . $this->_get_txn_timestamp($transaction) |
|
239 | + . '</a>'; |
|
240 | + //status |
|
241 | + $txn_date .= '<br><span class="ee-status-text-small">' |
|
242 | + . EEH_Template::pretty_status( |
|
243 | + $transaction->status_ID(), |
|
244 | + false, |
|
245 | + 'sentence' |
|
246 | + ) |
|
247 | + . '</span>'; |
|
248 | + return $txn_date; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * column_TXN_total |
|
254 | + * |
|
255 | + * @param \EE_Transaction $transaction |
|
256 | + * @return string |
|
257 | + * @throws \EE_Error |
|
258 | + */ |
|
259 | + public function column_TXN_total(EE_Transaction $transaction) |
|
260 | + { |
|
261 | + if ($transaction->get('TXN_total') > 0) { |
|
262 | + return '<span class="txn-pad-rght">' |
|
263 | + . apply_filters( |
|
264 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
265 | + $transaction->get_pretty('TXN_total'), |
|
266 | + $transaction |
|
267 | + ) |
|
268 | + . '</span>'; |
|
269 | + } else { |
|
270 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * column_TXN_paid |
|
277 | + * |
|
278 | + * @param \EE_Transaction $transaction |
|
279 | + * @return mixed|string |
|
280 | + * @throws \EE_Error |
|
281 | + */ |
|
282 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
283 | + { |
|
284 | + $transaction_total = $transaction->get('TXN_total'); |
|
285 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
286 | + |
|
287 | + if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
288 | + // monies owing |
|
289 | + $span_class = 'txn-overview-part-payment-spn'; |
|
290 | + if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
291 | + // paid in full |
|
292 | + $span_class = 'txn-overview-full-payment-spn'; |
|
293 | + } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
294 | + // no payments made |
|
295 | + $span_class = 'txn-overview-no-payment-spn'; |
|
296 | + } |
|
297 | + } else { |
|
298 | + $span_class = 'txn-overview-free-event-spn'; |
|
299 | + $transaction_paid = 0; |
|
300 | + } |
|
301 | + |
|
302 | + $payment_method = $transaction->payment_method(); |
|
303 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
304 | + ? $payment_method->admin_name() |
|
305 | + : esc_html__('Unknown', 'event_espresso'); |
|
306 | + $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
307 | + |
|
308 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
309 | + . $transaction_paid_content |
|
310 | + . '</span>'; |
|
311 | + if ($transaction_paid > 0) { |
|
312 | + $content .= '<br><span class="ee-status-text-small">' |
|
313 | + . sprintf( |
|
314 | + esc_html__('...via %s', 'event_espresso'), |
|
315 | + $payment_method_name |
|
316 | + ) |
|
317 | + . '</span>'; |
|
318 | + } |
|
319 | + return $content; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * column_ATT_fname |
|
325 | + * |
|
326 | + * @param \EE_Transaction $transaction |
|
327 | + * @return string |
|
328 | + * @throws EE_Error |
|
329 | + * @throws InvalidArgumentException |
|
330 | + * @throws InvalidDataTypeException |
|
331 | + * @throws InvalidInterfaceException |
|
332 | + */ |
|
333 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
334 | + { |
|
335 | + $primary_reg = $transaction->primary_registration(); |
|
336 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
337 | + if ($attendee instanceof EE_Attendee) { |
|
338 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
339 | + 'action' => 'view_registration', |
|
340 | + '_REG_ID' => $primary_reg->ID(), |
|
341 | + ), REG_ADMIN_URL); |
|
342 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
343 | + 'ee_read_registration', |
|
344 | + 'espresso_registrations_view_registration', |
|
345 | + $primary_reg->ID() |
|
346 | + ) |
|
347 | + ? '<a href="' . $edit_lnk_url . '"' |
|
348 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
349 | + . $attendee->full_name() |
|
350 | + . '</a>' |
|
351 | + : $attendee->full_name(); |
|
352 | + $content .= '<br>' . $attendee->email(); |
|
353 | + return $content; |
|
354 | + } |
|
355 | + return $transaction->failed() || $transaction->is_abandoned() |
|
356 | + ? esc_html__('no contact record.', 'event_espresso') |
|
357 | + : esc_html__( |
|
358 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
359 | + 'event_espresso' |
|
360 | + ); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * column_ATT_email |
|
366 | + * |
|
367 | + * @param \EE_Transaction $transaction |
|
368 | + * @return string |
|
369 | + * @throws \EE_Error |
|
370 | + */ |
|
371 | + public function column_ATT_email(EE_Transaction $transaction) |
|
372 | + { |
|
373 | + $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
374 | + if (! empty($attendee)) { |
|
375 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
376 | + . $attendee->get('ATT_email') |
|
377 | + . '</a>'; |
|
378 | + } else { |
|
379 | + return $transaction->failed() || $transaction->is_abandoned() |
|
380 | + ? esc_html__('no contact record.', 'event_espresso') |
|
381 | + : esc_html__( |
|
382 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
383 | + 'event_espresso' |
|
384 | + ); |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * column_event_name |
|
391 | + * |
|
392 | + * @param \EE_Transaction $transaction |
|
393 | + * @return string |
|
394 | + * @throws EE_Error |
|
395 | + * @throws InvalidArgumentException |
|
396 | + * @throws InvalidDataTypeException |
|
397 | + * @throws InvalidInterfaceException |
|
398 | + */ |
|
399 | + public function column_event_name(EE_Transaction $transaction) |
|
400 | + { |
|
401 | + $actions = array(); |
|
402 | + $event = $transaction->primary_registration()->get_first_related('Event'); |
|
403 | + if (! empty($event)) { |
|
404 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
405 | + array('action' => 'edit', 'post' => $event->ID()), |
|
406 | + EVENTS_ADMIN_URL |
|
407 | + ); |
|
408 | + $event_name = $event->get('EVT_name'); |
|
409 | + |
|
410 | + //filter this view by transactions for this event |
|
411 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
412 | + 'action' => 'default', |
|
413 | + 'EVT_ID' => $event->ID(), |
|
414 | + )); |
|
415 | + if (empty($this->_req_data['EVT_ID']) |
|
416 | + && EE_Registry::instance()->CAP->current_user_can( |
|
417 | + 'ee_edit_event', |
|
418 | + 'espresso_events_edit', |
|
419 | + $event->ID() |
|
420 | + ) |
|
421 | + ) { |
|
422 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
423 | + . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
424 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
425 | + . '</a>'; |
|
426 | + } |
|
427 | + |
|
428 | + return sprintf( |
|
429 | + '%1$s %2$s', |
|
430 | + EE_Registry::instance()->CAP->current_user_can( |
|
431 | + 'ee_edit_event', |
|
432 | + 'espresso_events_edit', |
|
433 | + $event->ID() |
|
434 | + ) |
|
435 | + ? '<a href="' . $edit_event_url . '"' |
|
436 | + . ' title="' |
|
437 | + . sprintf( |
|
438 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
439 | + $event->get('EVT_name') |
|
440 | + ) |
|
441 | + . '">' |
|
442 | + . wp_trim_words( |
|
443 | + $event_name, |
|
444 | + 30, |
|
445 | + '...' |
|
446 | + ) |
|
447 | + . '</a>' |
|
448 | + : wp_trim_words($event_name, 30, '...'), |
|
449 | + $this->row_actions($actions) |
|
450 | + ); |
|
451 | + } else { |
|
452 | + return esc_html__( |
|
453 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
454 | + 'event_espresso' |
|
455 | + ); |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * column_actions |
|
462 | + * |
|
463 | + * @param \EE_Transaction $transaction |
|
464 | + * @return string |
|
465 | + * @throws \EE_Error |
|
466 | + */ |
|
467 | + public function column_actions(EE_Transaction $transaction) |
|
468 | + { |
|
469 | + return $this->_action_string( |
|
470 | + $this->get_transaction_details_link($transaction) |
|
471 | + . $this->get_invoice_link($transaction) |
|
472 | + . $this->get_receipt_link($transaction) |
|
473 | + . $this->get_primary_registration_details_link($transaction) |
|
474 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
475 | + . $this->get_payment_overview_link($transaction) |
|
476 | + . $this->get_related_messages_link($transaction), |
|
477 | + $transaction, |
|
478 | + 'ul', |
|
479 | + 'txn-overview-actions-ul' |
|
480 | + ); |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * Get the transaction details link. |
|
486 | + * @param EE_Transaction $transaction |
|
487 | + * @return string |
|
488 | + * @throws EE_Error |
|
489 | + */ |
|
490 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
491 | + { |
|
492 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
493 | + 'action' => 'view_transaction', |
|
494 | + 'TXN_ID' => $transaction->ID(), |
|
495 | + ), TXN_ADMIN_URL); |
|
496 | + return ' |
|
497 | 497 | <li> |
498 | 498 | <a href="' . $url . '"' |
499 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
499 | + . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
500 | 500 | <span class="dashicons dashicons-cart"></span> |
501 | 501 | </a> |
502 | 502 | </li>'; |
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Get the invoice link for the given registration. |
|
508 | - * @param EE_Transaction $transaction |
|
509 | - * @return string |
|
510 | - * @throws EE_Error |
|
511 | - */ |
|
512 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
513 | - { |
|
514 | - $registration = $transaction->primary_registration(); |
|
515 | - if ($registration instanceof EE_Registration) { |
|
516 | - $url = $registration->invoice_url(); |
|
517 | - //only show invoice link if message type is active. |
|
518 | - if ($registration->attendee() instanceof EE_Attendee |
|
519 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
520 | - ) { |
|
521 | - return ' |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Get the invoice link for the given registration. |
|
508 | + * @param EE_Transaction $transaction |
|
509 | + * @return string |
|
510 | + * @throws EE_Error |
|
511 | + */ |
|
512 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
513 | + { |
|
514 | + $registration = $transaction->primary_registration(); |
|
515 | + if ($registration instanceof EE_Registration) { |
|
516 | + $url = $registration->invoice_url(); |
|
517 | + //only show invoice link if message type is active. |
|
518 | + if ($registration->attendee() instanceof EE_Attendee |
|
519 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
520 | + ) { |
|
521 | + return ' |
|
522 | 522 | <li> |
523 | 523 | <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
524 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
524 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
525 | 525 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
526 | 526 | </a> |
527 | 527 | </li>'; |
528 | - } |
|
529 | - } |
|
530 | - return ''; |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * Get the receipt link for the transaction. |
|
536 | - * @param EE_Transaction $transaction |
|
537 | - * @return string |
|
538 | - * @throws EE_Error |
|
539 | - */ |
|
540 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
541 | - { |
|
542 | - $registration = $transaction->primary_registration(); |
|
543 | - if ($registration instanceof EE_Registration) { |
|
544 | - $url = $registration->receipt_url(); |
|
545 | - //only show receipt link if message type is active. |
|
546 | - if ($registration->attendee() instanceof EE_Attendee |
|
547 | - && EEH_MSG_Template::is_mt_active('receipt')) { |
|
548 | - return ' |
|
528 | + } |
|
529 | + } |
|
530 | + return ''; |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * Get the receipt link for the transaction. |
|
536 | + * @param EE_Transaction $transaction |
|
537 | + * @return string |
|
538 | + * @throws EE_Error |
|
539 | + */ |
|
540 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
541 | + { |
|
542 | + $registration = $transaction->primary_registration(); |
|
543 | + if ($registration instanceof EE_Registration) { |
|
544 | + $url = $registration->receipt_url(); |
|
545 | + //only show receipt link if message type is active. |
|
546 | + if ($registration->attendee() instanceof EE_Attendee |
|
547 | + && EEH_MSG_Template::is_mt_active('receipt')) { |
|
548 | + return ' |
|
549 | 549 | <li> |
550 | 550 | <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
551 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
551 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
552 | 552 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
553 | 553 | </a> |
554 | 554 | </li>'; |
555 | - } |
|
556 | - } |
|
557 | - return ''; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Get the link to view the details for the primary registration. |
|
563 | - * |
|
564 | - * @param EE_Transaction $transaction |
|
565 | - * @return string |
|
566 | - * @throws EE_Error |
|
567 | - * @throws InvalidArgumentException |
|
568 | - * @throws InvalidDataTypeException |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - */ |
|
571 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
572 | - { |
|
573 | - $registration = $transaction->primary_registration(); |
|
574 | - if ($registration instanceof EE_Registration) { |
|
575 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
576 | - 'action' => 'view_registration', |
|
577 | - '_REG_ID' => $registration->ID(), |
|
578 | - ), REG_ADMIN_URL); |
|
579 | - return EE_Registry::instance()->CAP->current_user_can( |
|
580 | - 'ee_read_registration', |
|
581 | - 'espresso_registrations_view_registration', |
|
582 | - $registration->ID() |
|
583 | - ) |
|
584 | - ? ' |
|
555 | + } |
|
556 | + } |
|
557 | + return ''; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Get the link to view the details for the primary registration. |
|
563 | + * |
|
564 | + * @param EE_Transaction $transaction |
|
565 | + * @return string |
|
566 | + * @throws EE_Error |
|
567 | + * @throws InvalidArgumentException |
|
568 | + * @throws InvalidDataTypeException |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + */ |
|
571 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
572 | + { |
|
573 | + $registration = $transaction->primary_registration(); |
|
574 | + if ($registration instanceof EE_Registration) { |
|
575 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
576 | + 'action' => 'view_registration', |
|
577 | + '_REG_ID' => $registration->ID(), |
|
578 | + ), REG_ADMIN_URL); |
|
579 | + return EE_Registry::instance()->CAP->current_user_can( |
|
580 | + 'ee_read_registration', |
|
581 | + 'espresso_registrations_view_registration', |
|
582 | + $registration->ID() |
|
583 | + ) |
|
584 | + ? ' |
|
585 | 585 | <li> |
586 | 586 | <a href="' . $url . '"' |
587 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
587 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
588 | 588 | <span class="dashicons dashicons-clipboard"></span> |
589 | 589 | </a> |
590 | 590 | </li>' |
591 | - : ''; |
|
592 | - } |
|
593 | - return ''; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Get send payment reminder trigger link |
|
599 | - * @param EE_Transaction $transaction |
|
600 | - * @return string |
|
601 | - * @throws EE_Error |
|
602 | - * @throws InvalidArgumentException |
|
603 | - * @throws InvalidDataTypeException |
|
604 | - * @throws InvalidInterfaceException |
|
605 | - */ |
|
606 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
607 | - { |
|
608 | - $registration = $transaction->primary_registration(); |
|
609 | - if ($registration instanceof EE_Registration |
|
610 | - && $registration->attendee() instanceof EE_Attendee |
|
611 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
612 | - && ! in_array( |
|
613 | - $transaction->status_ID(), |
|
614 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
615 | - true |
|
616 | - ) |
|
617 | - && EE_Registry::instance()->CAP->current_user_can( |
|
618 | - 'ee_send_message', |
|
619 | - 'espresso_transactions_send_payment_reminder' |
|
620 | - ) |
|
621 | - ) { |
|
622 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
623 | - 'action' => 'send_payment_reminder', |
|
624 | - 'TXN_ID' => $transaction->ID(), |
|
625 | - ), TXN_ADMIN_URL); |
|
626 | - return ' |
|
591 | + : ''; |
|
592 | + } |
|
593 | + return ''; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Get send payment reminder trigger link |
|
599 | + * @param EE_Transaction $transaction |
|
600 | + * @return string |
|
601 | + * @throws EE_Error |
|
602 | + * @throws InvalidArgumentException |
|
603 | + * @throws InvalidDataTypeException |
|
604 | + * @throws InvalidInterfaceException |
|
605 | + */ |
|
606 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
607 | + { |
|
608 | + $registration = $transaction->primary_registration(); |
|
609 | + if ($registration instanceof EE_Registration |
|
610 | + && $registration->attendee() instanceof EE_Attendee |
|
611 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
612 | + && ! in_array( |
|
613 | + $transaction->status_ID(), |
|
614 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
615 | + true |
|
616 | + ) |
|
617 | + && EE_Registry::instance()->CAP->current_user_can( |
|
618 | + 'ee_send_message', |
|
619 | + 'espresso_transactions_send_payment_reminder' |
|
620 | + ) |
|
621 | + ) { |
|
622 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
623 | + 'action' => 'send_payment_reminder', |
|
624 | + 'TXN_ID' => $transaction->ID(), |
|
625 | + ), TXN_ADMIN_URL); |
|
626 | + return ' |
|
627 | 627 | <li> |
628 | 628 | <a href="' . $url . '"' |
629 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
629 | + . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
630 | 630 | <span class="dashicons dashicons-email-alt"></span> |
631 | 631 | </a> |
632 | 632 | </li>'; |
633 | - } |
|
634 | - return ''; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
640 | - * @param EE_Transaction $transaction |
|
641 | - * @return string |
|
642 | - * @throws EE_Error |
|
643 | - * @throws InvalidArgumentException |
|
644 | - * @throws InvalidDataTypeException |
|
645 | - * @throws InvalidInterfaceException |
|
646 | - */ |
|
647 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
648 | - { |
|
649 | - $url = EEH_MSG_Template::get_message_action_link( |
|
650 | - 'see_notifications_for', |
|
651 | - null, |
|
652 | - array('TXN_ID' => $transaction->ID()) |
|
653 | - ); |
|
654 | - return EE_Registry::instance()->CAP->current_user_can( |
|
655 | - 'ee_read_global_messages', |
|
656 | - 'view_filtered_messages' |
|
657 | - ) |
|
658 | - ? '<li>' . $url . '</li>' |
|
659 | - : ''; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Return the link to make a payment on the frontend |
|
665 | - * @param EE_Transaction $transaction |
|
666 | - * @return string |
|
667 | - * @throws EE_Error |
|
668 | - */ |
|
669 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
670 | - { |
|
671 | - $registration = $transaction->primary_registration(); |
|
672 | - if ($registration instanceof EE_Registration |
|
673 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
674 | - && $registration->owes_monies_and_can_pay() |
|
675 | - ) { |
|
676 | - return ' |
|
633 | + } |
|
634 | + return ''; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
640 | + * @param EE_Transaction $transaction |
|
641 | + * @return string |
|
642 | + * @throws EE_Error |
|
643 | + * @throws InvalidArgumentException |
|
644 | + * @throws InvalidDataTypeException |
|
645 | + * @throws InvalidInterfaceException |
|
646 | + */ |
|
647 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
648 | + { |
|
649 | + $url = EEH_MSG_Template::get_message_action_link( |
|
650 | + 'see_notifications_for', |
|
651 | + null, |
|
652 | + array('TXN_ID' => $transaction->ID()) |
|
653 | + ); |
|
654 | + return EE_Registry::instance()->CAP->current_user_can( |
|
655 | + 'ee_read_global_messages', |
|
656 | + 'view_filtered_messages' |
|
657 | + ) |
|
658 | + ? '<li>' . $url . '</li>' |
|
659 | + : ''; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Return the link to make a payment on the frontend |
|
665 | + * @param EE_Transaction $transaction |
|
666 | + * @return string |
|
667 | + * @throws EE_Error |
|
668 | + */ |
|
669 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
670 | + { |
|
671 | + $registration = $transaction->primary_registration(); |
|
672 | + if ($registration instanceof EE_Registration |
|
673 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
674 | + && $registration->owes_monies_and_can_pay() |
|
675 | + ) { |
|
676 | + return ' |
|
677 | 677 | <li> |
678 | 678 | <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
679 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
680 | - . ' class="tiny-text"> |
|
679 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
680 | + . ' class="tiny-text"> |
|
681 | 681 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
682 | 682 | </a> |
683 | 683 | </li> |
684 | 684 | '; |
685 | 685 | |
686 | - } |
|
687 | - return ''; |
|
688 | - } |
|
686 | + } |
|
687 | + return ''; |
|
688 | + } |
|
689 | 689 | } |