@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct() |
53 | 53 | { |
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | $this->_load_class_tools(); |
106 | 106 | // load interfaces |
107 | 107 | espresso_load_required('EEI_Payment_Method_Interfaces', |
108 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
108 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
109 | 109 | // deprecated functions |
110 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
110 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
111 | 111 | // WP cron jobs |
112 | 112 | $loader->getShared('EE_Cron_Tasks'); |
113 | 113 | $loader->getShared('EE_Request_Handler'); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function dependency_map() |
145 | 145 | { |
146 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
146 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
147 | 147 | throw new EE_Error( |
148 | 148 | sprintf( |
149 | 149 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function registry() |
164 | 164 | { |
165 | - if (! $this->registry instanceof EE_Registry) { |
|
165 | + if ( ! $this->registry instanceof EE_Registry) { |
|
166 | 166 | throw new EE_Error( |
167 | 167 | sprintf( |
168 | 168 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | */ |
181 | 181 | private function _load_dependency_map() |
182 | 182 | { |
183 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
183 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
184 | 184 | EE_Error::add_error( |
185 | 185 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
186 | 186 | __FILE__, __FUNCTION__, __LINE__ |
187 | 187 | ); |
188 | 188 | wp_die(EE_Error::get_notices()); |
189 | 189 | } |
190 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
190 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
191 | 191 | return EE_Dependency_Map::instance($this->request, $this->response); |
192 | 192 | } |
193 | 193 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function _load_registry() |
200 | 200 | { |
201 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
201 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
202 | 202 | EE_Error::add_error( |
203 | 203 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
204 | 204 | __FILE__, __FUNCTION__, __LINE__ |
205 | 205 | ); |
206 | 206 | wp_die(EE_Error::get_notices()); |
207 | 207 | } |
208 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
208 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
209 | 209 | return EE_Registry::instance($this->dependency_map); |
210 | 210 | } |
211 | 211 | |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function _load_class_tools() |
218 | 218 | { |
219 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
219 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
220 | 220 | EE_Error::add_error( |
221 | 221 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
222 | 222 | __FILE__, __FUNCTION__, __LINE__ |
223 | 223 | ); |
224 | 224 | } |
225 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
225 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -24,208 +24,208 @@ discard block |
||
24 | 24 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Request $request |
|
29 | - */ |
|
30 | - protected $request; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Response $response |
|
34 | - */ |
|
35 | - protected $response; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Dependency_Map $dependency_map |
|
39 | - */ |
|
40 | - protected $dependency_map; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registry $registry |
|
44 | - */ |
|
45 | - protected $registry; |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * EE_Load_Espresso_Core constructor |
|
51 | - */ |
|
52 | - public function __construct() |
|
53 | - { |
|
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * handle |
|
61 | - * sets hooks for running rest of system |
|
62 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | - * starting EE Addons from any other point may lead to problems |
|
64 | - * |
|
65 | - * @param EE_Request $request |
|
66 | - * @param EE_Response $response |
|
67 | - * @return EE_Response |
|
68 | - * @throws EE_Error |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - * @throws InvalidArgumentException |
|
72 | - */ |
|
73 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | - { |
|
75 | - $this->request = $request; |
|
76 | - $this->response = $response; |
|
77 | - // info about how to load classes required by other classes |
|
78 | - $this->dependency_map = $this->_load_dependency_map(); |
|
79 | - // central repository for classes |
|
80 | - $this->registry = $this->_load_registry(); |
|
81 | - // PSR4 Autoloaders |
|
82 | - $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | - $loader = LoaderFactory::getLoader($this->registry); |
|
85 | - $this->dependency_map->setLoader($loader); |
|
86 | - // build DI container |
|
87 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | - // $OpenCoffeeShop->addRecipes(); |
|
89 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | - // workarounds for PHP < 5.3 |
|
91 | - $this->_load_class_tools(); |
|
92 | - // load interfaces |
|
93 | - espresso_load_required('EEI_Payment_Method_Interfaces', |
|
94 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
95 | - // deprecated functions |
|
96 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
97 | - // WP cron jobs |
|
98 | - $loader->getShared('EE_Cron_Tasks'); |
|
99 | - $loader->getShared('EE_Request_Handler'); |
|
100 | - $loader->getShared('EE_System'); |
|
101 | - return $this->response; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return EE_Request |
|
108 | - */ |
|
109 | - public function request() |
|
110 | - { |
|
111 | - return $this->request; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return EE_Response |
|
118 | - */ |
|
119 | - public function response() |
|
120 | - { |
|
121 | - return $this->response; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return EE_Dependency_Map |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function dependency_map() |
|
131 | - { |
|
132 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
133 | - throw new EE_Error( |
|
134 | - sprintf( |
|
135 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
136 | - print_r($this->dependency_map, true) |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - return $this->dependency_map; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return EE_Registry |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public function registry() |
|
150 | - { |
|
151 | - if (! $this->registry instanceof EE_Registry) { |
|
152 | - throw new EE_Error( |
|
153 | - sprintf( |
|
154 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
155 | - print_r($this->registry, true) |
|
156 | - ) |
|
157 | - ); |
|
158 | - } |
|
159 | - return $this->registry; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @return EE_Dependency_Map |
|
166 | - */ |
|
167 | - private function _load_dependency_map() |
|
168 | - { |
|
169 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
170 | - EE_Error::add_error( |
|
171 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
172 | - __FILE__, __FUNCTION__, __LINE__ |
|
173 | - ); |
|
174 | - wp_die(EE_Error::get_notices()); |
|
175 | - } |
|
176 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
177 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @return EE_Registry |
|
184 | - */ |
|
185 | - private function _load_registry() |
|
186 | - { |
|
187 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
188 | - EE_Error::add_error( |
|
189 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
190 | - __FILE__, __FUNCTION__, __LINE__ |
|
191 | - ); |
|
192 | - wp_die(EE_Error::get_notices()); |
|
193 | - } |
|
194 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
195 | - return EE_Registry::instance($this->dependency_map); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - private function _load_class_tools() |
|
204 | - { |
|
205 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
206 | - EE_Error::add_error( |
|
207 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
208 | - __FILE__, __FUNCTION__, __LINE__ |
|
209 | - ); |
|
210 | - } |
|
211 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * called after the request stack has been fully processed |
|
218 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
219 | - * |
|
220 | - * @param EE_Request $request |
|
221 | - * @param EE_Response $response |
|
222 | - */ |
|
223 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
224 | - { |
|
225 | - if ($response->plugin_deactivated()) { |
|
226 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
227 | - } |
|
228 | - } |
|
27 | + /** |
|
28 | + * @var EE_Request $request |
|
29 | + */ |
|
30 | + protected $request; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Response $response |
|
34 | + */ |
|
35 | + protected $response; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Dependency_Map $dependency_map |
|
39 | + */ |
|
40 | + protected $dependency_map; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registry $registry |
|
44 | + */ |
|
45 | + protected $registry; |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * EE_Load_Espresso_Core constructor |
|
51 | + */ |
|
52 | + public function __construct() |
|
53 | + { |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * handle |
|
61 | + * sets hooks for running rest of system |
|
62 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | + * starting EE Addons from any other point may lead to problems |
|
64 | + * |
|
65 | + * @param EE_Request $request |
|
66 | + * @param EE_Response $response |
|
67 | + * @return EE_Response |
|
68 | + * @throws EE_Error |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + * @throws InvalidArgumentException |
|
72 | + */ |
|
73 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | + { |
|
75 | + $this->request = $request; |
|
76 | + $this->response = $response; |
|
77 | + // info about how to load classes required by other classes |
|
78 | + $this->dependency_map = $this->_load_dependency_map(); |
|
79 | + // central repository for classes |
|
80 | + $this->registry = $this->_load_registry(); |
|
81 | + // PSR4 Autoloaders |
|
82 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | + $loader = LoaderFactory::getLoader($this->registry); |
|
85 | + $this->dependency_map->setLoader($loader); |
|
86 | + // build DI container |
|
87 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | + // $OpenCoffeeShop->addRecipes(); |
|
89 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | + // workarounds for PHP < 5.3 |
|
91 | + $this->_load_class_tools(); |
|
92 | + // load interfaces |
|
93 | + espresso_load_required('EEI_Payment_Method_Interfaces', |
|
94 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
95 | + // deprecated functions |
|
96 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
97 | + // WP cron jobs |
|
98 | + $loader->getShared('EE_Cron_Tasks'); |
|
99 | + $loader->getShared('EE_Request_Handler'); |
|
100 | + $loader->getShared('EE_System'); |
|
101 | + return $this->response; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return EE_Request |
|
108 | + */ |
|
109 | + public function request() |
|
110 | + { |
|
111 | + return $this->request; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return EE_Response |
|
118 | + */ |
|
119 | + public function response() |
|
120 | + { |
|
121 | + return $this->response; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return EE_Dependency_Map |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function dependency_map() |
|
131 | + { |
|
132 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
133 | + throw new EE_Error( |
|
134 | + sprintf( |
|
135 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
136 | + print_r($this->dependency_map, true) |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + return $this->dependency_map; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return EE_Registry |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public function registry() |
|
150 | + { |
|
151 | + if (! $this->registry instanceof EE_Registry) { |
|
152 | + throw new EE_Error( |
|
153 | + sprintf( |
|
154 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
155 | + print_r($this->registry, true) |
|
156 | + ) |
|
157 | + ); |
|
158 | + } |
|
159 | + return $this->registry; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @return EE_Dependency_Map |
|
166 | + */ |
|
167 | + private function _load_dependency_map() |
|
168 | + { |
|
169 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
170 | + EE_Error::add_error( |
|
171 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
172 | + __FILE__, __FUNCTION__, __LINE__ |
|
173 | + ); |
|
174 | + wp_die(EE_Error::get_notices()); |
|
175 | + } |
|
176 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
177 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @return EE_Registry |
|
184 | + */ |
|
185 | + private function _load_registry() |
|
186 | + { |
|
187 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
188 | + EE_Error::add_error( |
|
189 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
190 | + __FILE__, __FUNCTION__, __LINE__ |
|
191 | + ); |
|
192 | + wp_die(EE_Error::get_notices()); |
|
193 | + } |
|
194 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
195 | + return EE_Registry::instance($this->dependency_map); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + private function _load_class_tools() |
|
204 | + { |
|
205 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
206 | + EE_Error::add_error( |
|
207 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
208 | + __FILE__, __FUNCTION__, __LINE__ |
|
209 | + ); |
|
210 | + } |
|
211 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * called after the request stack has been fully processed |
|
218 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
219 | + * |
|
220 | + * @param EE_Request $request |
|
221 | + * @param EE_Response $response |
|
222 | + */ |
|
223 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
224 | + { |
|
225 | + if ($response->plugin_deactivated()) { |
|
226 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
7 | 7 | |
@@ -17,193 +17,193 @@ discard block |
||
17 | 17 | class EEM_Transaction extends EEM_Base |
18 | 18 | { |
19 | 19 | |
20 | - // private instance of the Transaction object |
|
21 | - protected static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | - * but payment is pending. This is the state for transactions where payment is promised |
|
26 | - * from an offline gateway. |
|
27 | - */ |
|
28 | - // const open_status_code = 'TPN'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | - * either due to a technical reason (server or computer crash during registration), |
|
33 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | - */ |
|
35 | - const failed_status_code = 'TFL'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | - * either due to a technical reason (server or computer crash during registration), |
|
40 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | - * HOWEVER... |
|
42 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | - * registrant |
|
44 | - */ |
|
45 | - const abandoned_status_code = 'TAB'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | - */ |
|
51 | - const incomplete_status_code = 'TIN'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | - */ |
|
57 | - const complete_status_code = 'TCM'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | - */ |
|
63 | - const overpaid_status_code = 'TOP'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * private constructor to prevent direct creation |
|
68 | - * |
|
69 | - * @Constructor |
|
70 | - * @access protected |
|
71 | - * |
|
72 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | - * timezone in the 'timezone_string' wp option) |
|
76 | - * |
|
77 | - * @return EEM_Transaction |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - protected function __construct($timezone) |
|
81 | - { |
|
82 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | - |
|
85 | - $this->_tables = array( |
|
86 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | - ); |
|
88 | - $this->_fields = array( |
|
89 | - 'TransactionTable' => array( |
|
90 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | - 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | - $timezone), |
|
94 | - 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | - __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | - 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | - __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | - false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | - 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | - __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | - 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | - __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | - __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | - __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | - ) |
|
109 | - ); |
|
110 | - $this->_model_relations = array( |
|
111 | - 'Registration' => new EE_Has_Many_Relation(), |
|
112 | - 'Payment' => new EE_Has_Many_Relation(), |
|
113 | - 'Status' => new EE_Belongs_To_Relation(), |
|
114 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | - //you can delete a transaction without needing to delete its line items |
|
116 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | - 'Message' => new EE_Has_Many_Relation() |
|
118 | - ); |
|
119 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | - parent::__construct($timezone); |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * txn_status_array |
|
127 | - * get list of transaction statuses |
|
128 | - * |
|
129 | - * @access public |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public static function txn_status_array() |
|
133 | - { |
|
134 | - return apply_filters( |
|
135 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | - array( |
|
137 | - EEM_Transaction::overpaid_status_code, |
|
138 | - EEM_Transaction::complete_status_code, |
|
139 | - EEM_Transaction::incomplete_status_code, |
|
140 | - EEM_Transaction::abandoned_status_code, |
|
141 | - EEM_Transaction::failed_status_code, |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | - * |
|
149 | - * @access public |
|
150 | - * |
|
151 | - * @param string $period |
|
152 | - * |
|
153 | - * @return \stdClass[] |
|
154 | - */ |
|
155 | - public function get_revenue_per_day_report($period = '-1 month') |
|
156 | - { |
|
157 | - $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | - 'Y-m-d H:i:s', 'UTC'); |
|
159 | - |
|
160 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | - |
|
162 | - return $this->_get_all_wpdb_results( |
|
163 | - array( |
|
164 | - array( |
|
165 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | - ), |
|
167 | - 'group_by' => 'txnDate', |
|
168 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | - ), |
|
170 | - OBJECT, |
|
171 | - array( |
|
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * |
|
184 | - * @param string $period |
|
185 | - * |
|
186 | - * @throws \EE_Error |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function get_revenue_per_event_report($period = '-1 month') |
|
190 | - { |
|
191 | - global $wpdb; |
|
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | - $event_table = $wpdb->posts; |
|
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | - $extra_event_on_join = ''; |
|
200 | - //exclude events not authored by user if permissions in effect |
|
201 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | - } |
|
204 | - |
|
205 | - return $wpdb->get_results( |
|
206 | - "SELECT |
|
20 | + // private instance of the Transaction object |
|
21 | + protected static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | + * but payment is pending. This is the state for transactions where payment is promised |
|
26 | + * from an offline gateway. |
|
27 | + */ |
|
28 | + // const open_status_code = 'TPN'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | + * either due to a technical reason (server or computer crash during registration), |
|
33 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | + */ |
|
35 | + const failed_status_code = 'TFL'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | + * either due to a technical reason (server or computer crash during registration), |
|
40 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | + * HOWEVER... |
|
42 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | + * registrant |
|
44 | + */ |
|
45 | + const abandoned_status_code = 'TAB'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | + */ |
|
51 | + const incomplete_status_code = 'TIN'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | + */ |
|
57 | + const complete_status_code = 'TCM'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | + */ |
|
63 | + const overpaid_status_code = 'TOP'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * private constructor to prevent direct creation |
|
68 | + * |
|
69 | + * @Constructor |
|
70 | + * @access protected |
|
71 | + * |
|
72 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | + * timezone in the 'timezone_string' wp option) |
|
76 | + * |
|
77 | + * @return EEM_Transaction |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + protected function __construct($timezone) |
|
81 | + { |
|
82 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | + |
|
85 | + $this->_tables = array( |
|
86 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | + ); |
|
88 | + $this->_fields = array( |
|
89 | + 'TransactionTable' => array( |
|
90 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | + 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | + $timezone), |
|
94 | + 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | + __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | + 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | + __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | + false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | + 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | + __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | + 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | + __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | + __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | + __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | + ) |
|
109 | + ); |
|
110 | + $this->_model_relations = array( |
|
111 | + 'Registration' => new EE_Has_Many_Relation(), |
|
112 | + 'Payment' => new EE_Has_Many_Relation(), |
|
113 | + 'Status' => new EE_Belongs_To_Relation(), |
|
114 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | + //you can delete a transaction without needing to delete its line items |
|
116 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | + 'Message' => new EE_Has_Many_Relation() |
|
118 | + ); |
|
119 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | + parent::__construct($timezone); |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * txn_status_array |
|
127 | + * get list of transaction statuses |
|
128 | + * |
|
129 | + * @access public |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public static function txn_status_array() |
|
133 | + { |
|
134 | + return apply_filters( |
|
135 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | + array( |
|
137 | + EEM_Transaction::overpaid_status_code, |
|
138 | + EEM_Transaction::complete_status_code, |
|
139 | + EEM_Transaction::incomplete_status_code, |
|
140 | + EEM_Transaction::abandoned_status_code, |
|
141 | + EEM_Transaction::failed_status_code, |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | + * |
|
149 | + * @access public |
|
150 | + * |
|
151 | + * @param string $period |
|
152 | + * |
|
153 | + * @return \stdClass[] |
|
154 | + */ |
|
155 | + public function get_revenue_per_day_report($period = '-1 month') |
|
156 | + { |
|
157 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | + 'Y-m-d H:i:s', 'UTC'); |
|
159 | + |
|
160 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | + |
|
162 | + return $this->_get_all_wpdb_results( |
|
163 | + array( |
|
164 | + array( |
|
165 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | + ), |
|
167 | + 'group_by' => 'txnDate', |
|
168 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | + ), |
|
170 | + OBJECT, |
|
171 | + array( |
|
172 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * |
|
184 | + * @param string $period |
|
185 | + * |
|
186 | + * @throws \EE_Error |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function get_revenue_per_event_report($period = '-1 month') |
|
190 | + { |
|
191 | + global $wpdb; |
|
192 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | + $event_table = $wpdb->posts; |
|
196 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | + $extra_event_on_join = ''; |
|
200 | + //exclude events not authored by user if permissions in effect |
|
201 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | + } |
|
204 | + |
|
205 | + return $wpdb->get_results( |
|
206 | + "SELECT |
|
207 | 207 | Transaction_Event.event_name AS event_name, |
208 | 208 | SUM(Transaction_Event.paid) AS revenue |
209 | 209 | FROM |
@@ -230,185 +230,185 @@ discard block |
||
230 | 230 | $extra_event_on_join |
231 | 231 | ) AS Transaction_Event |
232 | 232 | GROUP BY event_name", |
233 | - OBJECT |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | - * the registration pointed to by reg_url_link), if not returns null |
|
242 | - * |
|
243 | - * @param string $reg_url_link |
|
244 | - * |
|
245 | - * @return EE_Transaction |
|
246 | - */ |
|
247 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | - { |
|
249 | - return $this->get_one(array( |
|
250 | - array( |
|
251 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | - '') |
|
253 | - ) |
|
254 | - )); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Updates the provided EE_Transaction with all the applicable payments |
|
260 | - * (or fetch the EE_Transaction from its ID) |
|
261 | - * |
|
262 | - * @deprecated |
|
263 | - * |
|
264 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | - * |
|
267 | - * @return boolean |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | - { |
|
272 | - EE_Error::doing_it_wrong( |
|
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
274 | - sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | - '4.6.0' |
|
277 | - ); |
|
278 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | - |
|
281 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | - ); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | - * and so we only use wpdb directly and only do minimal joins. |
|
290 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | - * it, it's probably not junk (regardless of what status it has). |
|
293 | - * The downside to this approach is that is addons are listening for object deletions |
|
294 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | - * to catch these types of deletions. |
|
296 | - * |
|
297 | - * @global WPDB $wpdb |
|
298 | - * @return mixed |
|
299 | - */ |
|
300 | - public function delete_junk_transactions() |
|
301 | - { |
|
302 | - /** @type WPDB $wpdb */ |
|
303 | - global $wpdb; |
|
304 | - $deleted = false; |
|
305 | - $time_to_leave_alone = apply_filters( |
|
306 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | - , WEEK_IN_SECONDS |
|
308 | - ); |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | - */ |
|
316 | - $ids_query = apply_filters( |
|
317 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | - array( |
|
319 | - 0 => array( |
|
320 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | - ) |
|
324 | - ), |
|
325 | - $time_to_leave_alone |
|
326 | - ); |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | - */ |
|
333 | - $txn_ids = apply_filters( |
|
334 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | - $time_to_leave_alone |
|
337 | - ); |
|
338 | - //now that we have the ids to delete |
|
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | - // let's get deletin'... |
|
343 | - // Why no wpdb->prepare? Because the data is trusted. |
|
344 | - // We got the ids from the original query to get them FROM |
|
345 | - // the db (which is sanitized) so no need to prepare them again. |
|
346 | - $query = ' |
|
233 | + OBJECT |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | + * the registration pointed to by reg_url_link), if not returns null |
|
242 | + * |
|
243 | + * @param string $reg_url_link |
|
244 | + * |
|
245 | + * @return EE_Transaction |
|
246 | + */ |
|
247 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | + { |
|
249 | + return $this->get_one(array( |
|
250 | + array( |
|
251 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | + '') |
|
253 | + ) |
|
254 | + )); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Updates the provided EE_Transaction with all the applicable payments |
|
260 | + * (or fetch the EE_Transaction from its ID) |
|
261 | + * |
|
262 | + * @deprecated |
|
263 | + * |
|
264 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | + * |
|
267 | + * @return boolean |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | + { |
|
272 | + EE_Error::doing_it_wrong( |
|
273 | + __CLASS__ . '::' . __FUNCTION__, |
|
274 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | + '4.6.0' |
|
277 | + ); |
|
278 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | + |
|
281 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | + ); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | + * and so we only use wpdb directly and only do minimal joins. |
|
290 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | + * it, it's probably not junk (regardless of what status it has). |
|
293 | + * The downside to this approach is that is addons are listening for object deletions |
|
294 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | + * to catch these types of deletions. |
|
296 | + * |
|
297 | + * @global WPDB $wpdb |
|
298 | + * @return mixed |
|
299 | + */ |
|
300 | + public function delete_junk_transactions() |
|
301 | + { |
|
302 | + /** @type WPDB $wpdb */ |
|
303 | + global $wpdb; |
|
304 | + $deleted = false; |
|
305 | + $time_to_leave_alone = apply_filters( |
|
306 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | + , WEEK_IN_SECONDS |
|
308 | + ); |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | + */ |
|
316 | + $ids_query = apply_filters( |
|
317 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | + array( |
|
319 | + 0 => array( |
|
320 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | + ) |
|
324 | + ), |
|
325 | + $time_to_leave_alone |
|
326 | + ); |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | + */ |
|
333 | + $txn_ids = apply_filters( |
|
334 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | + $time_to_leave_alone |
|
337 | + ); |
|
338 | + //now that we have the ids to delete |
|
339 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | + // let's get deletin'... |
|
343 | + // Why no wpdb->prepare? Because the data is trusted. |
|
344 | + // We got the ids from the original query to get them FROM |
|
345 | + // the db (which is sanitized) so no need to prepare them again. |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | 348 | FROM ' . $this->table() . ' |
349 | 349 | WHERE |
350 | 350 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
351 | - $deleted = $wpdb->query($query); |
|
352 | - } |
|
353 | - if ($deleted) { |
|
354 | - /** |
|
355 | - * Allows code to do something after the transactions have been deleted. |
|
356 | - */ |
|
357 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | - } |
|
359 | - |
|
360 | - return $deleted; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param array $transaction_IDs |
|
366 | - * |
|
367 | - * @return bool |
|
368 | - */ |
|
369 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | - { |
|
371 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | - $update = false; |
|
373 | - foreach ($transaction_IDs as $TXN_ID) { |
|
374 | - if (isset($locked_transactions[$TXN_ID])) { |
|
375 | - unset($locked_transactions[$TXN_ID]); |
|
376 | - $update = true; |
|
377 | - } |
|
378 | - } |
|
379 | - if ($update) { |
|
380 | - update_option('ee_locked_transactions', $locked_transactions); |
|
381 | - } |
|
382 | - |
|
383 | - return $update; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | - * |
|
392 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | - * @throws \EE_Error |
|
394 | - */ |
|
395 | - public function get_transactions_in_progress() |
|
396 | - { |
|
397 | - return $this->get_all( |
|
398 | - array( |
|
399 | - array( |
|
400 | - 'TXN_timestamp' => array( |
|
401 | - '>', |
|
402 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | - ), |
|
404 | - 'STS_ID' => array( |
|
405 | - '!=', |
|
406 | - EEM_Transaction::complete_status_code |
|
407 | - ), |
|
408 | - ) |
|
409 | - ) |
|
410 | - ); |
|
411 | - } |
|
351 | + $deleted = $wpdb->query($query); |
|
352 | + } |
|
353 | + if ($deleted) { |
|
354 | + /** |
|
355 | + * Allows code to do something after the transactions have been deleted. |
|
356 | + */ |
|
357 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | + } |
|
359 | + |
|
360 | + return $deleted; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param array $transaction_IDs |
|
366 | + * |
|
367 | + * @return bool |
|
368 | + */ |
|
369 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | + { |
|
371 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | + $update = false; |
|
373 | + foreach ($transaction_IDs as $TXN_ID) { |
|
374 | + if (isset($locked_transactions[$TXN_ID])) { |
|
375 | + unset($locked_transactions[$TXN_ID]); |
|
376 | + $update = true; |
|
377 | + } |
|
378 | + } |
|
379 | + if ($update) { |
|
380 | + update_option('ee_locked_transactions', $locked_transactions); |
|
381 | + } |
|
382 | + |
|
383 | + return $update; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | + * |
|
392 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | + * @throws \EE_Error |
|
394 | + */ |
|
395 | + public function get_transactions_in_progress() |
|
396 | + { |
|
397 | + return $this->get_all( |
|
398 | + array( |
|
399 | + array( |
|
400 | + 'TXN_timestamp' => array( |
|
401 | + '>', |
|
402 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | + ), |
|
404 | + 'STS_ID' => array( |
|
405 | + '!=', |
|
406 | + EEM_Transaction::complete_status_code |
|
407 | + ), |
|
408 | + ) |
|
409 | + ) |
|
410 | + ); |
|
411 | + } |
|
412 | 412 | |
413 | 413 | |
414 | 414 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
6 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | __('Registration Steps', 'event_espresso'), false, array()), |
108 | 108 | ) |
109 | 109 | ); |
110 | - $this->_model_relations = array( |
|
110 | + $this->_model_relations = array( |
|
111 | 111 | 'Registration' => new EE_Has_Many_Relation(), |
112 | 112 | 'Payment' => new EE_Has_Many_Relation(), |
113 | 113 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ), |
170 | 170 | OBJECT, |
171 | 171 | array( |
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
172 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
173 | 173 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
174 | 174 | ) |
175 | 175 | ); |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | public function get_revenue_per_event_report($period = '-1 month') |
190 | 190 | { |
191 | 191 | global $wpdb; |
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
192 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
195 | 195 | $event_table = $wpdb->posts; |
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
196 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
197 | 197 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
198 | 198 | $approved_payment_status = EEM_Payment::status_id_approved; |
199 | 199 | $extra_event_on_join = ''; |
200 | 200 | //exclude events not authored by user if permissions in effect |
201 | 201 | if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
202 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $wpdb->get_results( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
271 | 271 | { |
272 | 272 | EE_Error::doing_it_wrong( |
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
273 | + __CLASS__.'::'.__FUNCTION__, |
|
274 | 274 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
275 | 275 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
276 | 276 | '4.6.0' |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | array( |
319 | 319 | 0 => array( |
320 | 320 | 'STS_ID' => EEM_Transaction::failed_status_code, |
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
321 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
322 | 322 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
323 | 323 | ) |
324 | 324 | ), |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | $time_to_leave_alone |
337 | 337 | ); |
338 | 338 | //now that we have the ids to delete |
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
339 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | 340 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
341 | 341 | EEM_Transaction::unset_locked_transactions($txn_ids); |
342 | 342 | // let's get deletin'... |
343 | 343 | // Why no wpdb->prepare? Because the data is trusted. |
344 | 344 | // We got the ids from the original query to get them FROM |
345 | 345 | // the db (which is sanitized) so no need to prepare them again. |
346 | - $query = ' |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | - FROM ' . $this->table() . ' |
|
348 | + FROM ' . $this->table().' |
|
349 | 349 | WHERE |
350 | - TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
|
350 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
351 | 351 | $deleted = $wpdb->query($query); |
352 | 352 | } |
353 | 353 | if ($deleted) { |
@@ -125,14 +125,14 @@ |
||
125 | 125 | public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | - //backward compat: we still want to find the question's ID |
|
129 | - if( is_numeric( $question_system_id ) ) { |
|
130 | - //find this question's QST_system value |
|
131 | - $question_id = $question_system_id; |
|
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | - } else { |
|
134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
135 | - } |
|
128 | + //backward compat: we still want to find the question's ID |
|
129 | + if( is_numeric( $question_system_id ) ) { |
|
130 | + //find this question's QST_system value |
|
131 | + $question_id = $question_system_id; |
|
132 | + $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | + } else { |
|
134 | + $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
135 | + } |
|
136 | 136 | //only bother checking if the registration has an attendee |
137 | 137 | if( $registration->attendee() instanceof EE_Attendee ) { |
138 | 138 | $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * constructor |
53 | 53 | */ |
54 | - protected function __construct( $timezone = NULL ){ |
|
55 | - $this->singular_item = __('Answer','event_espresso'); |
|
56 | - $this->plural_item = __('Answers','event_espresso'); |
|
54 | + protected function __construct($timezone = NULL) { |
|
55 | + $this->singular_item = __('Answer', 'event_espresso'); |
|
56 | + $this->plural_item = __('Answers', 'event_espresso'); |
|
57 | 57 | $this->_tables = array( |
58 | 58 | 'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') |
59 | 59 | ); |
60 | 60 | $this->_fields = array( |
61 | 61 | 'Answer'=>array( |
62 | - 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')), |
|
63 | - 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'), |
|
64 | - 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'), |
|
65 | - 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '') |
|
62 | + 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
63 | + 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
64 | + 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
65 | + 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
66 | 66 | )); |
67 | 67 | $this->_model_relations = array( |
68 | 68 | 'Registration'=>new EE_Belongs_To_Relation(), |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | $this->_model_chain_to_wp_user = 'Registration.Event'; |
72 | 72 | $this->_caps_slug = 'registrations'; |
73 | - parent::__construct( $timezone ); |
|
73 | + parent::__construct($timezone); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){ |
|
87 | - $value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer ); |
|
88 | - if ( $value === NULL ){ |
|
89 | - $answer_obj = $this->get_registration_question_answer_object( $registration, $question_id); |
|
90 | - if( $answer_obj instanceof EE_Answer ){ |
|
91 | - if($pretty_answer){ |
|
86 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) { |
|
87 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
88 | + if ($value === NULL) { |
|
89 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
90 | + if ($answer_obj instanceof EE_Answer) { |
|
91 | + if ($pretty_answer) { |
|
92 | 92 | $value = $answer_obj->pretty_value(); |
93 | - }else{ |
|
93 | + } else { |
|
94 | 94 | $value = $answer_obj->value(); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | } |
98 | - return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id ); |
|
98 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param int $question_id |
107 | 107 | * @return EE_Answer |
108 | 108 | */ |
109 | - public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){ |
|
110 | - $answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
111 | - return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id ); |
|
109 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) { |
|
110 | + $answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID()))); |
|
111 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
@@ -122,39 +122,39 @@ discard block |
||
122 | 122 | * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for |
123 | 123 | * a question corresponding to an attendee field, returns null) |
124 | 124 | */ |
125 | - public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
|
125 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) { |
|
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | 128 | //backward compat: we still want to find the question's ID |
129 | - if( is_numeric( $question_system_id ) ) { |
|
129 | + if (is_numeric($question_system_id)) { |
|
130 | 130 | //find this question's QST_system value |
131 | 131 | $question_id = $question_system_id; |
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
132 | + $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); |
|
133 | 133 | } else { |
134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
134 | + $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'); |
|
135 | 135 | } |
136 | 136 | //only bother checking if the registration has an attendee |
137 | - if( $registration->attendee() instanceof EE_Attendee ) { |
|
138 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
|
139 | - if( $field_name ) { |
|
140 | - if( $pretty_answer ) { |
|
141 | - if( $field_name === 'STA_ID' ) { |
|
137 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
138 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
139 | + if ($field_name) { |
|
140 | + if ($pretty_answer) { |
|
141 | + if ($field_name === 'STA_ID') { |
|
142 | 142 | $state = $registration->attendee()->state_obj(); |
143 | - $value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() ); |
|
144 | - } else if($field_name === 'CNT_ISO') { |
|
143 | + $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
144 | + } else if ($field_name === 'CNT_ISO') { |
|
145 | 145 | $country = $registration->attendee()->country_obj(); |
146 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID()); |
|
146 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
147 | 147 | } else { |
148 | - $value = $registration->attendee()->get_pretty( $field_name ); |
|
148 | + $value = $registration->attendee()->get_pretty($field_name); |
|
149 | 149 | } |
150 | 150 | //if field name is blank, leave the value as null too |
151 | - }else{ |
|
152 | - $value = $registration->attendee()->get( $field_name ); |
|
151 | + } else { |
|
152 | + $value = $registration->attendee()->get($field_name); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | //if no field was found, leave value blank |
156 | 156 | } |
157 | - return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id ); |
|
157 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | public function previous(); |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | 122 | public function indexOf( $object ); |
123 | 123 | |
124 | 124 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | 167 | |
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * unsets and detaches ALL objects from the Collection |
|
172 | - */ |
|
173 | - public function trashAndDetachAll(); |
|
170 | + /** |
|
171 | + * unsets and detaches ALL objects from the Collection |
|
172 | + */ |
|
173 | + public function trashAndDetachAll(); |
|
174 | 174 | |
175 | 175 | } |
176 | 176 | // End of file CollectionInterface.php |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -352,34 +351,34 @@ discard block |
||
352 | 351 | |
353 | 352 | |
354 | 353 | |
355 | - /** |
|
356 | - * detaches ALL objects from the Collection |
|
357 | - */ |
|
358 | - public function detachAll() |
|
359 | - { |
|
360 | - $this->rewind(); |
|
361 | - while ($this->valid()) { |
|
362 | - $object = $this->current(); |
|
363 | - $this->next(); |
|
364 | - $this->detach($object); |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * unsets and detaches ALL objects from the Collection |
|
372 | - */ |
|
373 | - public function trashAndDetachAll() |
|
374 | - { |
|
375 | - $this->rewind(); |
|
376 | - while ($this->valid()) { |
|
377 | - $object = $this->current(); |
|
378 | - $this->next(); |
|
379 | - $this->detach($object); |
|
380 | - unset($object); |
|
381 | - } |
|
382 | - } |
|
354 | + /** |
|
355 | + * detaches ALL objects from the Collection |
|
356 | + */ |
|
357 | + public function detachAll() |
|
358 | + { |
|
359 | + $this->rewind(); |
|
360 | + while ($this->valid()) { |
|
361 | + $object = $this->current(); |
|
362 | + $this->next(); |
|
363 | + $this->detach($object); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * unsets and detaches ALL objects from the Collection |
|
371 | + */ |
|
372 | + public function trashAndDetachAll() |
|
373 | + { |
|
374 | + $this->rewind(); |
|
375 | + while ($this->valid()) { |
|
376 | + $object = $this->current(); |
|
377 | + $this->next(); |
|
378 | + $this->detach($object); |
|
379 | + unset($object); |
|
380 | + } |
|
381 | + } |
|
383 | 382 | |
384 | 383 | |
385 | 384 |
@@ -79,37 +79,37 @@ |
||
79 | 79 | class LoaderFactory |
80 | 80 | { |
81 | 81 | |
82 | - /** |
|
83 | - * @var LoaderInterface $loader ; |
|
84 | - */ |
|
85 | - private static $loader; |
|
82 | + /** |
|
83 | + * @var LoaderInterface $loader ; |
|
84 | + */ |
|
85 | + private static $loader; |
|
86 | 86 | |
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param mixed $generator provided during very first instantiation in |
|
91 | - * EE_Load_Espresso_Core::handle_request() |
|
92 | - * otherwise can be left null |
|
93 | - * @return LoaderInterface |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidInterfaceException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - */ |
|
98 | - public static function getLoader($generator = null) |
|
99 | - { |
|
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | - $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | - $core_loader = new CoreLoader($generator); |
|
103 | - LoaderFactory::$loader = new Loader( |
|
104 | - $core_loader, |
|
105 | - new CachingLoader( |
|
106 | - $core_loader, |
|
107 | - new LooseCollection('') |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
89 | + /** |
|
90 | + * @param mixed $generator provided during very first instantiation in |
|
91 | + * EE_Load_Espresso_Core::handle_request() |
|
92 | + * otherwise can be left null |
|
93 | + * @return LoaderInterface |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidInterfaceException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + */ |
|
98 | + public static function getLoader($generator = null) |
|
99 | + { |
|
100 | + if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | + $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | + $core_loader = new CoreLoader($generator); |
|
103 | + LoaderFactory::$loader = new Loader( |
|
104 | + $core_loader, |
|
105 | + new CachingLoader( |
|
106 | + $core_loader, |
|
107 | + new LooseCollection('') |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | */ |
98 | 98 | public static function getLoader($generator = null) |
99 | 99 | { |
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
100 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | 101 | $generator = $generator !== null ? $generator : EE_Registry::instance(); |
102 | 102 | $core_loader = new CoreLoader($generator); |
103 | 103 | LoaderFactory::$loader = new Loader( |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress', |
56 | 56 | 'event_espresso' |
57 | 57 | ); |
58 | - $this->label = array( |
|
58 | + $this->label = array( |
|
59 | 59 | 'singular' => esc_html__('email', 'event_espresso'), |
60 | 60 | 'plural' => esc_html__('emails', 'event_espresso'), |
61 | 61 | ); |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | $this->_body(), |
420 | 420 | $this->_headers() |
421 | 421 | ); |
422 | - if (! $success) { |
|
422 | + if ( ! $success) { |
|
423 | 423 | EE_Error::add_error( |
424 | 424 | sprintf( |
425 | 425 | esc_html__( |
@@ -464,13 +464,13 @@ discard block |
||
464 | 464 | $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
465 | 465 | $headers = array( |
466 | 466 | 'MIME-Version: 1.0', |
467 | - 'From:' . $from, |
|
468 | - 'Reply-To:' . $from, |
|
467 | + 'From:'.$from, |
|
468 | + 'Reply-To:'.$from, |
|
469 | 469 | 'Content-Type:text/html; charset=utf-8', |
470 | 470 | ); |
471 | 471 | |
472 | - if (! empty($this->_cc)) { |
|
473 | - $headers[] = 'cc: ' . $this->_cc; |
|
472 | + if ( ! empty($this->_cc)) { |
|
473 | + $headers[] = 'cc: '.$this->_cc; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | ) |
581 | 581 | ), |
582 | 582 | ); |
583 | - $body = $this->_get_main_template($preview); |
|
583 | + $body = $this->_get_main_template($preview); |
|
584 | 584 | |
585 | 585 | /** |
586 | 586 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | */ |
591 | 591 | if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
592 | 592 | //require CssToInlineStyles library and its dependencies via composer autoloader |
593 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
593 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php'; |
|
594 | 594 | |
595 | 595 | //now if this isn't a preview, let's setup the body so it has inline styles |
596 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
596 | + if ( ! $preview || ($preview && defined('DOING_AJAX'))) { |
|
597 | 597 | $style = file_get_contents( |
598 | 598 | $this->get_variation( |
599 | 599 | $this->_tmp_pack, |
@@ -8,643 +8,643 @@ |
||
8 | 8 | class EE_Email_messenger extends EE_messenger |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * To field for email |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $_to = ''; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * CC field for email. |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_cc = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * From field for email |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $_from = ''; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Subject field for email |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_subject = ''; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Content field for email |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_content = ''; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * constructor |
|
47 | - * |
|
48 | - * @access public |
|
49 | - */ |
|
50 | - public function __construct() |
|
51 | - { |
|
52 | - //set name and description properties |
|
53 | - $this->name = 'email'; |
|
54 | - $this->description = esc_html__( |
|
55 | - 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress', |
|
56 | - 'event_espresso' |
|
57 | - ); |
|
58 | - $this->label = array( |
|
59 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
60 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
61 | - ); |
|
62 | - $this->activate_on_install = true; |
|
63 | - |
|
64 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
65 | - // properties |
|
66 | - parent::__construct(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * see abstract declaration in parent class for details. |
|
72 | - */ |
|
73 | - protected function _set_admin_pages() |
|
74 | - { |
|
75 | - $this->admin_registered_pages = array( |
|
76 | - 'events_edit' => true, |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * see abstract declaration in parent class for details |
|
83 | - */ |
|
84 | - protected function _set_valid_shortcodes() |
|
85 | - { |
|
86 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
87 | - // message type. |
|
88 | - $this->_valid_shortcodes = array( |
|
89 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
90 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
91 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
92 | - ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * see abstract declaration in parent class for details |
|
98 | - * |
|
99 | - * @access protected |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - protected function _set_validator_config() |
|
103 | - { |
|
104 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
105 | - |
|
106 | - $this->_validator_config = array( |
|
107 | - 'to' => array( |
|
108 | - 'shortcodes' => $valid_shortcodes['to'], |
|
109 | - 'type' => 'email', |
|
110 | - ), |
|
111 | - 'cc' => array( |
|
112 | - 'shortcodes' => $valid_shortcodes['to'], |
|
113 | - 'type' => 'email', |
|
114 | - ), |
|
115 | - 'from' => array( |
|
116 | - 'shortcodes' => $valid_shortcodes['from'], |
|
117 | - 'type' => 'email', |
|
118 | - ), |
|
119 | - 'subject' => array( |
|
120 | - 'shortcodes' => array( |
|
121 | - 'organization', |
|
122 | - 'primary_registration_details', |
|
123 | - 'event_author', |
|
124 | - 'primary_registration_details', |
|
125 | - 'recipient_details', |
|
126 | - ), |
|
127 | - ), |
|
128 | - 'content' => array( |
|
129 | - 'shortcodes' => array( |
|
130 | - 'event_list', |
|
131 | - 'attendee_list', |
|
132 | - 'ticket_list', |
|
133 | - 'organization', |
|
134 | - 'primary_registration_details', |
|
135 | - 'primary_registration_list', |
|
136 | - 'event_author', |
|
137 | - 'recipient_details', |
|
138 | - 'recipient_list', |
|
139 | - 'transaction', |
|
140 | - 'messenger', |
|
141 | - ), |
|
142 | - ), |
|
143 | - 'attendee_list' => array( |
|
144 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
145 | - 'required' => array('[ATTENDEE_LIST]'), |
|
146 | - ), |
|
147 | - 'event_list' => array( |
|
148 | - 'shortcodes' => array( |
|
149 | - 'event', |
|
150 | - 'attendee_list', |
|
151 | - 'ticket_list', |
|
152 | - 'venue', |
|
153 | - 'datetime_list', |
|
154 | - 'attendee', |
|
155 | - 'primary_registration_details', |
|
156 | - 'primary_registration_list', |
|
157 | - 'event_author', |
|
158 | - 'recipient_details', |
|
159 | - 'recipient_list', |
|
160 | - ), |
|
161 | - 'required' => array('[EVENT_LIST]'), |
|
162 | - ), |
|
163 | - 'ticket_list' => array( |
|
164 | - 'shortcodes' => array( |
|
165 | - 'event_list', |
|
166 | - 'attendee_list', |
|
167 | - 'ticket', |
|
168 | - 'datetime_list', |
|
169 | - 'primary_registration_details', |
|
170 | - 'recipient_details', |
|
171 | - ), |
|
172 | - 'required' => array('[TICKET_LIST]'), |
|
173 | - ), |
|
174 | - 'datetime_list' => array( |
|
175 | - 'shortcodes' => array('datetime'), |
|
176 | - 'required' => array('[DATETIME_LIST]'), |
|
177 | - ), |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @see parent EE_messenger class for docs |
|
184 | - * @since 4.5.0 |
|
185 | - */ |
|
186 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
187 | - { |
|
188 | - if ($sending_messenger_name = 'html') { |
|
189 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - public function add_email_css( |
|
195 | - $variation_path, |
|
196 | - $messenger, |
|
197 | - $message_type, |
|
198 | - $type, |
|
199 | - $variation, |
|
200 | - $file_extension, |
|
201 | - $url, |
|
202 | - EE_Messages_Template_Pack $template_pack |
|
203 | - ) { |
|
204 | - //prevent recursion on this callback. |
|
205 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
206 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
207 | - |
|
208 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
209 | - return $variation; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * See parent for details |
|
215 | - * |
|
216 | - * @access protected |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - protected function _set_test_settings_fields() |
|
220 | - { |
|
221 | - $this->_test_settings_fields = array( |
|
222 | - 'to' => array( |
|
223 | - 'input' => 'text', |
|
224 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
225 | - 'type' => 'email', |
|
226 | - 'required' => true, |
|
227 | - 'validation' => true, |
|
228 | - 'css_class' => 'large-text', |
|
229 | - 'format' => '%s', |
|
230 | - 'default' => get_bloginfo('admin_email'), |
|
231 | - ), |
|
232 | - 'subject' => array( |
|
233 | - 'input' => 'hidden', |
|
234 | - 'label' => '', |
|
235 | - 'type' => 'string', |
|
236 | - 'required' => false, |
|
237 | - 'validation' => false, |
|
238 | - 'format' => '%s', |
|
239 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
240 | - 'default' => '', |
|
241 | - 'css_class' => '', |
|
242 | - ), |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * _set_template_fields |
|
249 | - * This sets up the fields that a messenger requires for the message to go out. |
|
250 | - * |
|
251 | - * @access protected |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - protected function _set_template_fields() |
|
255 | - { |
|
256 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
257 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
258 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
259 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
260 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
261 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
262 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
263 | - // will not be displayed/parsed. |
|
264 | - $this->_template_fields = array( |
|
265 | - 'to' => array( |
|
266 | - 'input' => 'text', |
|
267 | - 'label' => esc_html_x( |
|
268 | - 'To', |
|
269 | - 'Label for the "To" field for email addresses', |
|
270 | - 'event_espresso' |
|
271 | - ), |
|
272 | - 'type' => 'string', |
|
273 | - 'required' => true, |
|
274 | - 'validation' => true, |
|
275 | - 'css_class' => 'large-text', |
|
276 | - 'format' => '%s', |
|
277 | - ), |
|
278 | - 'cc' => array( |
|
279 | - 'input' => 'text', |
|
280 | - 'label' => esc_html_x( |
|
281 | - 'CC', |
|
282 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
283 | - 'event_espresso' |
|
284 | - ), |
|
285 | - 'type' => 'string', |
|
286 | - 'required' => false, |
|
287 | - 'validation' => true, |
|
288 | - 'css_class' => 'large-text', |
|
289 | - 'format' => '%s', |
|
290 | - ), |
|
291 | - 'from' => array( |
|
292 | - 'input' => 'text', |
|
293 | - 'label' => esc_html_x( |
|
294 | - 'From', |
|
295 | - 'Label for the "From" field for email addresses.', |
|
296 | - 'event_espresso' |
|
297 | - ), |
|
298 | - 'type' => 'string', |
|
299 | - 'required' => true, |
|
300 | - 'validation' => true, |
|
301 | - 'css_class' => 'large-text', |
|
302 | - 'format' => '%s', |
|
303 | - ), |
|
304 | - 'subject' => array( |
|
305 | - 'input' => 'text', |
|
306 | - 'label' => esc_html_x( |
|
307 | - 'Subject', |
|
308 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
309 | - 'event_espresso' |
|
310 | - ), |
|
311 | - 'type' => 'string', |
|
312 | - 'required' => true, |
|
313 | - 'validation' => true, |
|
314 | - 'css_class' => 'large-text', |
|
315 | - 'format' => '%s', |
|
316 | - ), |
|
317 | - 'content' => '', |
|
318 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
319 | - 'extra' => array( |
|
320 | - 'content' => array( |
|
321 | - 'main' => array( |
|
322 | - 'input' => 'wp_editor', |
|
323 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
324 | - 'type' => 'string', |
|
325 | - 'required' => true, |
|
326 | - 'validation' => true, |
|
327 | - 'format' => '%s', |
|
328 | - 'rows' => '15', |
|
329 | - ), |
|
330 | - 'event_list' => array( |
|
331 | - 'input' => 'wp_editor', |
|
332 | - 'label' => '[EVENT_LIST]', |
|
333 | - 'type' => 'string', |
|
334 | - 'required' => true, |
|
335 | - 'validation' => true, |
|
336 | - 'format' => '%s', |
|
337 | - 'rows' => '15', |
|
338 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
339 | - ), |
|
340 | - 'attendee_list' => array( |
|
341 | - 'input' => 'textarea', |
|
342 | - 'label' => '[ATTENDEE_LIST]', |
|
343 | - 'type' => 'string', |
|
344 | - 'required' => true, |
|
345 | - 'validation' => true, |
|
346 | - 'format' => '%s', |
|
347 | - 'css_class' => 'large-text', |
|
348 | - 'rows' => '5', |
|
349 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
350 | - ), |
|
351 | - 'ticket_list' => array( |
|
352 | - 'input' => 'textarea', |
|
353 | - 'label' => '[TICKET_LIST]', |
|
354 | - 'type' => 'string', |
|
355 | - 'required' => true, |
|
356 | - 'validation' => true, |
|
357 | - 'format' => '%s', |
|
358 | - 'css_class' => 'large-text', |
|
359 | - 'rows' => '10', |
|
360 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
361 | - ), |
|
362 | - 'datetime_list' => array( |
|
363 | - 'input' => 'textarea', |
|
364 | - 'label' => '[DATETIME_LIST]', |
|
365 | - 'type' => 'string', |
|
366 | - 'required' => true, |
|
367 | - 'validation' => true, |
|
368 | - 'format' => '%s', |
|
369 | - 'css_class' => 'large-text', |
|
370 | - 'rows' => '10', |
|
371 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
372 | - ), |
|
373 | - ), |
|
374 | - ), |
|
375 | - ); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * See definition of this class in parent |
|
381 | - */ |
|
382 | - protected function _set_default_message_types() |
|
383 | - { |
|
384 | - $this->_default_message_types = array( |
|
385 | - 'payment', |
|
386 | - 'payment_refund', |
|
387 | - 'registration', |
|
388 | - 'not_approved_registration', |
|
389 | - 'pending_approval', |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @see definition of this class in parent |
|
396 | - * @since 4.5.0 |
|
397 | - */ |
|
398 | - protected function _set_valid_message_types() |
|
399 | - { |
|
400 | - $this->_valid_message_types = array( |
|
401 | - 'payment', |
|
402 | - 'registration', |
|
403 | - 'not_approved_registration', |
|
404 | - 'declined_registration', |
|
405 | - 'cancelled_registration', |
|
406 | - 'pending_approval', |
|
407 | - 'registration_summary', |
|
408 | - 'payment_reminder', |
|
409 | - 'payment_declined', |
|
410 | - 'payment_refund', |
|
411 | - ); |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * setting up admin_settings_fields for messenger. |
|
417 | - */ |
|
418 | - protected function _set_admin_settings_fields() |
|
419 | - { |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * We just deliver the messages don't kill us!! |
|
424 | - * |
|
425 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
426 | - * present. |
|
427 | - * @throws EE_Error |
|
428 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
429 | - */ |
|
430 | - protected function _send_message() |
|
431 | - { |
|
432 | - $success = wp_mail( |
|
433 | - html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"), |
|
434 | - stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")), |
|
435 | - $this->_body(), |
|
436 | - $this->_headers() |
|
437 | - ); |
|
438 | - if (! $success) { |
|
439 | - EE_Error::add_error( |
|
440 | - sprintf( |
|
441 | - esc_html__( |
|
442 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
443 | - 'event_espresso' |
|
444 | - ), |
|
445 | - $this->_to, |
|
446 | - $this->_from, |
|
447 | - '<br />' |
|
448 | - ), |
|
449 | - __FILE__, |
|
450 | - __FUNCTION__, |
|
451 | - __LINE__ |
|
452 | - ); |
|
453 | - } |
|
454 | - return $success; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * see parent for definition |
|
460 | - * |
|
461 | - * @return string html body of the message content and the related css. |
|
462 | - * @throws EE_Error |
|
463 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
464 | - */ |
|
465 | - protected function _preview() |
|
466 | - { |
|
467 | - return $this->_body(true); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * Setup headers for email |
|
473 | - * |
|
474 | - * @access protected |
|
475 | - * @return string formatted header for email |
|
476 | - */ |
|
477 | - protected function _headers() |
|
478 | - { |
|
479 | - $this->_ensure_has_from_email_address(); |
|
480 | - $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
|
481 | - $headers = array( |
|
482 | - 'MIME-Version: 1.0', |
|
483 | - 'From:' . $from, |
|
484 | - 'Reply-To:' . $from, |
|
485 | - 'Content-Type:text/html; charset=utf-8', |
|
486 | - ); |
|
487 | - |
|
488 | - if (! empty($this->_cc)) { |
|
489 | - $headers[] = 'cc: ' . $this->_cc; |
|
490 | - } |
|
491 | - |
|
492 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
493 | - // header. |
|
494 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
495 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
496 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
502 | - * address for the from address to avoid problems with sending emails. |
|
503 | - */ |
|
504 | - protected function _ensure_has_from_email_address() |
|
505 | - { |
|
506 | - if (empty($this->_from)) { |
|
507 | - $this->_from = get_bloginfo('admin_email'); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
514 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
515 | - * be empty |
|
516 | - * |
|
517 | - * @since 4.3.1 |
|
518 | - * @return array |
|
519 | - */ |
|
520 | - private function _parse_from() |
|
521 | - { |
|
522 | - if (strpos($this->_from, '<') !== false) { |
|
523 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
524 | - $from_name = str_replace('"', '', $from_name); |
|
525 | - $from_name = trim($from_name); |
|
526 | - |
|
527 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
528 | - $from_email = str_replace('>', '', $from_email); |
|
529 | - $from_email = trim($from_email); |
|
530 | - } elseif (trim($this->_from) !== '') { |
|
531 | - $from_name = ''; |
|
532 | - $from_email = trim($this->_from); |
|
533 | - } else { |
|
534 | - $from_name = $from_email = ''; |
|
535 | - } |
|
536 | - return array($from_name, $from_email); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Callback for the wp_mail_from filter. |
|
542 | - * |
|
543 | - * @since 4.3.1 |
|
544 | - * @param string $from_email What the original from_email is. |
|
545 | - * @return string |
|
546 | - */ |
|
547 | - public function set_from_address($from_email) |
|
548 | - { |
|
549 | - $parsed_from = $this->_parse_from(); |
|
550 | - //includes fallback if the parsing failed. |
|
551 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
552 | - ? $parsed_from[1] |
|
553 | - : get_bloginfo('admin_email'); |
|
554 | - return $from_email; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Callback fro the wp_mail_from_name filter. |
|
560 | - * |
|
561 | - * @since 4.3.1 |
|
562 | - * @param string $from_name The original from_name. |
|
563 | - * @return string |
|
564 | - */ |
|
565 | - public function set_from_name($from_name) |
|
566 | - { |
|
567 | - $parsed_from = $this->_parse_from(); |
|
568 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
569 | - $from_name = $parsed_from[0]; |
|
570 | - } |
|
571 | - |
|
572 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
573 | - $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name; |
|
574 | - |
|
575 | - return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8")); |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * setup body for email |
|
581 | - * |
|
582 | - * @param bool $preview will determine whether this is preview template or not. |
|
583 | - * @return string formatted body for email. |
|
584 | - * @throws EE_Error |
|
585 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
586 | - */ |
|
587 | - protected function _body($preview = false) |
|
588 | - { |
|
589 | - //setup template args! |
|
590 | - $this->_template_args = array( |
|
591 | - 'subject' => $this->_subject, |
|
592 | - 'from' => $this->_from, |
|
593 | - 'main_body' => wpautop( |
|
594 | - stripslashes_deep( |
|
595 | - html_entity_decode($this->_content, ENT_QUOTES, "UTF-8") |
|
596 | - ) |
|
597 | - ), |
|
598 | - ); |
|
599 | - $body = $this->_get_main_template($preview); |
|
600 | - |
|
601 | - /** |
|
602 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
603 | - * |
|
604 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
605 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
606 | - */ |
|
607 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
608 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
609 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
610 | - |
|
611 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
612 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
613 | - $style = file_get_contents( |
|
614 | - $this->get_variation( |
|
615 | - $this->_tmp_pack, |
|
616 | - $this->_incoming_message_type->name, |
|
617 | - false, |
|
618 | - 'main', |
|
619 | - $this->_variation |
|
620 | - ), |
|
621 | - true |
|
622 | - ); |
|
623 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
624 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
625 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
626 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
627 | - $body = ltrim($body, "<?"); |
|
628 | - } |
|
629 | - |
|
630 | - } |
|
631 | - return $body; |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * This just returns any existing test settings that might be saved in the database |
|
637 | - * |
|
638 | - * @access public |
|
639 | - * @return array |
|
640 | - */ |
|
641 | - public function get_existing_test_settings() |
|
642 | - { |
|
643 | - $settings = parent::get_existing_test_settings(); |
|
644 | - //override subject if present because we always want it to be fresh. |
|
645 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
646 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
647 | - } |
|
648 | - return $settings; |
|
649 | - } |
|
11 | + /** |
|
12 | + * To field for email |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $_to = ''; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * CC field for email. |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_cc = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * From field for email |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $_from = ''; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Subject field for email |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_subject = ''; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Content field for email |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_content = ''; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * constructor |
|
47 | + * |
|
48 | + * @access public |
|
49 | + */ |
|
50 | + public function __construct() |
|
51 | + { |
|
52 | + //set name and description properties |
|
53 | + $this->name = 'email'; |
|
54 | + $this->description = esc_html__( |
|
55 | + 'This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress', |
|
56 | + 'event_espresso' |
|
57 | + ); |
|
58 | + $this->label = array( |
|
59 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
60 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
61 | + ); |
|
62 | + $this->activate_on_install = true; |
|
63 | + |
|
64 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
65 | + // properties |
|
66 | + parent::__construct(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * see abstract declaration in parent class for details. |
|
72 | + */ |
|
73 | + protected function _set_admin_pages() |
|
74 | + { |
|
75 | + $this->admin_registered_pages = array( |
|
76 | + 'events_edit' => true, |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * see abstract declaration in parent class for details |
|
83 | + */ |
|
84 | + protected function _set_valid_shortcodes() |
|
85 | + { |
|
86 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
87 | + // message type. |
|
88 | + $this->_valid_shortcodes = array( |
|
89 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
90 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
91 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
92 | + ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * see abstract declaration in parent class for details |
|
98 | + * |
|
99 | + * @access protected |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + protected function _set_validator_config() |
|
103 | + { |
|
104 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
105 | + |
|
106 | + $this->_validator_config = array( |
|
107 | + 'to' => array( |
|
108 | + 'shortcodes' => $valid_shortcodes['to'], |
|
109 | + 'type' => 'email', |
|
110 | + ), |
|
111 | + 'cc' => array( |
|
112 | + 'shortcodes' => $valid_shortcodes['to'], |
|
113 | + 'type' => 'email', |
|
114 | + ), |
|
115 | + 'from' => array( |
|
116 | + 'shortcodes' => $valid_shortcodes['from'], |
|
117 | + 'type' => 'email', |
|
118 | + ), |
|
119 | + 'subject' => array( |
|
120 | + 'shortcodes' => array( |
|
121 | + 'organization', |
|
122 | + 'primary_registration_details', |
|
123 | + 'event_author', |
|
124 | + 'primary_registration_details', |
|
125 | + 'recipient_details', |
|
126 | + ), |
|
127 | + ), |
|
128 | + 'content' => array( |
|
129 | + 'shortcodes' => array( |
|
130 | + 'event_list', |
|
131 | + 'attendee_list', |
|
132 | + 'ticket_list', |
|
133 | + 'organization', |
|
134 | + 'primary_registration_details', |
|
135 | + 'primary_registration_list', |
|
136 | + 'event_author', |
|
137 | + 'recipient_details', |
|
138 | + 'recipient_list', |
|
139 | + 'transaction', |
|
140 | + 'messenger', |
|
141 | + ), |
|
142 | + ), |
|
143 | + 'attendee_list' => array( |
|
144 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
145 | + 'required' => array('[ATTENDEE_LIST]'), |
|
146 | + ), |
|
147 | + 'event_list' => array( |
|
148 | + 'shortcodes' => array( |
|
149 | + 'event', |
|
150 | + 'attendee_list', |
|
151 | + 'ticket_list', |
|
152 | + 'venue', |
|
153 | + 'datetime_list', |
|
154 | + 'attendee', |
|
155 | + 'primary_registration_details', |
|
156 | + 'primary_registration_list', |
|
157 | + 'event_author', |
|
158 | + 'recipient_details', |
|
159 | + 'recipient_list', |
|
160 | + ), |
|
161 | + 'required' => array('[EVENT_LIST]'), |
|
162 | + ), |
|
163 | + 'ticket_list' => array( |
|
164 | + 'shortcodes' => array( |
|
165 | + 'event_list', |
|
166 | + 'attendee_list', |
|
167 | + 'ticket', |
|
168 | + 'datetime_list', |
|
169 | + 'primary_registration_details', |
|
170 | + 'recipient_details', |
|
171 | + ), |
|
172 | + 'required' => array('[TICKET_LIST]'), |
|
173 | + ), |
|
174 | + 'datetime_list' => array( |
|
175 | + 'shortcodes' => array('datetime'), |
|
176 | + 'required' => array('[DATETIME_LIST]'), |
|
177 | + ), |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @see parent EE_messenger class for docs |
|
184 | + * @since 4.5.0 |
|
185 | + */ |
|
186 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
187 | + { |
|
188 | + if ($sending_messenger_name = 'html') { |
|
189 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + public function add_email_css( |
|
195 | + $variation_path, |
|
196 | + $messenger, |
|
197 | + $message_type, |
|
198 | + $type, |
|
199 | + $variation, |
|
200 | + $file_extension, |
|
201 | + $url, |
|
202 | + EE_Messages_Template_Pack $template_pack |
|
203 | + ) { |
|
204 | + //prevent recursion on this callback. |
|
205 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
206 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
207 | + |
|
208 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
209 | + return $variation; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * See parent for details |
|
215 | + * |
|
216 | + * @access protected |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + protected function _set_test_settings_fields() |
|
220 | + { |
|
221 | + $this->_test_settings_fields = array( |
|
222 | + 'to' => array( |
|
223 | + 'input' => 'text', |
|
224 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
225 | + 'type' => 'email', |
|
226 | + 'required' => true, |
|
227 | + 'validation' => true, |
|
228 | + 'css_class' => 'large-text', |
|
229 | + 'format' => '%s', |
|
230 | + 'default' => get_bloginfo('admin_email'), |
|
231 | + ), |
|
232 | + 'subject' => array( |
|
233 | + 'input' => 'hidden', |
|
234 | + 'label' => '', |
|
235 | + 'type' => 'string', |
|
236 | + 'required' => false, |
|
237 | + 'validation' => false, |
|
238 | + 'format' => '%s', |
|
239 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
240 | + 'default' => '', |
|
241 | + 'css_class' => '', |
|
242 | + ), |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * _set_template_fields |
|
249 | + * This sets up the fields that a messenger requires for the message to go out. |
|
250 | + * |
|
251 | + * @access protected |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + protected function _set_template_fields() |
|
255 | + { |
|
256 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
257 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
258 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
259 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
260 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
261 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
262 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
263 | + // will not be displayed/parsed. |
|
264 | + $this->_template_fields = array( |
|
265 | + 'to' => array( |
|
266 | + 'input' => 'text', |
|
267 | + 'label' => esc_html_x( |
|
268 | + 'To', |
|
269 | + 'Label for the "To" field for email addresses', |
|
270 | + 'event_espresso' |
|
271 | + ), |
|
272 | + 'type' => 'string', |
|
273 | + 'required' => true, |
|
274 | + 'validation' => true, |
|
275 | + 'css_class' => 'large-text', |
|
276 | + 'format' => '%s', |
|
277 | + ), |
|
278 | + 'cc' => array( |
|
279 | + 'input' => 'text', |
|
280 | + 'label' => esc_html_x( |
|
281 | + 'CC', |
|
282 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
283 | + 'event_espresso' |
|
284 | + ), |
|
285 | + 'type' => 'string', |
|
286 | + 'required' => false, |
|
287 | + 'validation' => true, |
|
288 | + 'css_class' => 'large-text', |
|
289 | + 'format' => '%s', |
|
290 | + ), |
|
291 | + 'from' => array( |
|
292 | + 'input' => 'text', |
|
293 | + 'label' => esc_html_x( |
|
294 | + 'From', |
|
295 | + 'Label for the "From" field for email addresses.', |
|
296 | + 'event_espresso' |
|
297 | + ), |
|
298 | + 'type' => 'string', |
|
299 | + 'required' => true, |
|
300 | + 'validation' => true, |
|
301 | + 'css_class' => 'large-text', |
|
302 | + 'format' => '%s', |
|
303 | + ), |
|
304 | + 'subject' => array( |
|
305 | + 'input' => 'text', |
|
306 | + 'label' => esc_html_x( |
|
307 | + 'Subject', |
|
308 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
309 | + 'event_espresso' |
|
310 | + ), |
|
311 | + 'type' => 'string', |
|
312 | + 'required' => true, |
|
313 | + 'validation' => true, |
|
314 | + 'css_class' => 'large-text', |
|
315 | + 'format' => '%s', |
|
316 | + ), |
|
317 | + 'content' => '', |
|
318 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
319 | + 'extra' => array( |
|
320 | + 'content' => array( |
|
321 | + 'main' => array( |
|
322 | + 'input' => 'wp_editor', |
|
323 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
324 | + 'type' => 'string', |
|
325 | + 'required' => true, |
|
326 | + 'validation' => true, |
|
327 | + 'format' => '%s', |
|
328 | + 'rows' => '15', |
|
329 | + ), |
|
330 | + 'event_list' => array( |
|
331 | + 'input' => 'wp_editor', |
|
332 | + 'label' => '[EVENT_LIST]', |
|
333 | + 'type' => 'string', |
|
334 | + 'required' => true, |
|
335 | + 'validation' => true, |
|
336 | + 'format' => '%s', |
|
337 | + 'rows' => '15', |
|
338 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
339 | + ), |
|
340 | + 'attendee_list' => array( |
|
341 | + 'input' => 'textarea', |
|
342 | + 'label' => '[ATTENDEE_LIST]', |
|
343 | + 'type' => 'string', |
|
344 | + 'required' => true, |
|
345 | + 'validation' => true, |
|
346 | + 'format' => '%s', |
|
347 | + 'css_class' => 'large-text', |
|
348 | + 'rows' => '5', |
|
349 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
350 | + ), |
|
351 | + 'ticket_list' => array( |
|
352 | + 'input' => 'textarea', |
|
353 | + 'label' => '[TICKET_LIST]', |
|
354 | + 'type' => 'string', |
|
355 | + 'required' => true, |
|
356 | + 'validation' => true, |
|
357 | + 'format' => '%s', |
|
358 | + 'css_class' => 'large-text', |
|
359 | + 'rows' => '10', |
|
360 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
361 | + ), |
|
362 | + 'datetime_list' => array( |
|
363 | + 'input' => 'textarea', |
|
364 | + 'label' => '[DATETIME_LIST]', |
|
365 | + 'type' => 'string', |
|
366 | + 'required' => true, |
|
367 | + 'validation' => true, |
|
368 | + 'format' => '%s', |
|
369 | + 'css_class' => 'large-text', |
|
370 | + 'rows' => '10', |
|
371 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
372 | + ), |
|
373 | + ), |
|
374 | + ), |
|
375 | + ); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * See definition of this class in parent |
|
381 | + */ |
|
382 | + protected function _set_default_message_types() |
|
383 | + { |
|
384 | + $this->_default_message_types = array( |
|
385 | + 'payment', |
|
386 | + 'payment_refund', |
|
387 | + 'registration', |
|
388 | + 'not_approved_registration', |
|
389 | + 'pending_approval', |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @see definition of this class in parent |
|
396 | + * @since 4.5.0 |
|
397 | + */ |
|
398 | + protected function _set_valid_message_types() |
|
399 | + { |
|
400 | + $this->_valid_message_types = array( |
|
401 | + 'payment', |
|
402 | + 'registration', |
|
403 | + 'not_approved_registration', |
|
404 | + 'declined_registration', |
|
405 | + 'cancelled_registration', |
|
406 | + 'pending_approval', |
|
407 | + 'registration_summary', |
|
408 | + 'payment_reminder', |
|
409 | + 'payment_declined', |
|
410 | + 'payment_refund', |
|
411 | + ); |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * setting up admin_settings_fields for messenger. |
|
417 | + */ |
|
418 | + protected function _set_admin_settings_fields() |
|
419 | + { |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * We just deliver the messages don't kill us!! |
|
424 | + * |
|
425 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
426 | + * present. |
|
427 | + * @throws EE_Error |
|
428 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
429 | + */ |
|
430 | + protected function _send_message() |
|
431 | + { |
|
432 | + $success = wp_mail( |
|
433 | + html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"), |
|
434 | + stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")), |
|
435 | + $this->_body(), |
|
436 | + $this->_headers() |
|
437 | + ); |
|
438 | + if (! $success) { |
|
439 | + EE_Error::add_error( |
|
440 | + sprintf( |
|
441 | + esc_html__( |
|
442 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
443 | + 'event_espresso' |
|
444 | + ), |
|
445 | + $this->_to, |
|
446 | + $this->_from, |
|
447 | + '<br />' |
|
448 | + ), |
|
449 | + __FILE__, |
|
450 | + __FUNCTION__, |
|
451 | + __LINE__ |
|
452 | + ); |
|
453 | + } |
|
454 | + return $success; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * see parent for definition |
|
460 | + * |
|
461 | + * @return string html body of the message content and the related css. |
|
462 | + * @throws EE_Error |
|
463 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
464 | + */ |
|
465 | + protected function _preview() |
|
466 | + { |
|
467 | + return $this->_body(true); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * Setup headers for email |
|
473 | + * |
|
474 | + * @access protected |
|
475 | + * @return string formatted header for email |
|
476 | + */ |
|
477 | + protected function _headers() |
|
478 | + { |
|
479 | + $this->_ensure_has_from_email_address(); |
|
480 | + $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
|
481 | + $headers = array( |
|
482 | + 'MIME-Version: 1.0', |
|
483 | + 'From:' . $from, |
|
484 | + 'Reply-To:' . $from, |
|
485 | + 'Content-Type:text/html; charset=utf-8', |
|
486 | + ); |
|
487 | + |
|
488 | + if (! empty($this->_cc)) { |
|
489 | + $headers[] = 'cc: ' . $this->_cc; |
|
490 | + } |
|
491 | + |
|
492 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
493 | + // header. |
|
494 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
495 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
496 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
502 | + * address for the from address to avoid problems with sending emails. |
|
503 | + */ |
|
504 | + protected function _ensure_has_from_email_address() |
|
505 | + { |
|
506 | + if (empty($this->_from)) { |
|
507 | + $this->_from = get_bloginfo('admin_email'); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
514 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
515 | + * be empty |
|
516 | + * |
|
517 | + * @since 4.3.1 |
|
518 | + * @return array |
|
519 | + */ |
|
520 | + private function _parse_from() |
|
521 | + { |
|
522 | + if (strpos($this->_from, '<') !== false) { |
|
523 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
524 | + $from_name = str_replace('"', '', $from_name); |
|
525 | + $from_name = trim($from_name); |
|
526 | + |
|
527 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
528 | + $from_email = str_replace('>', '', $from_email); |
|
529 | + $from_email = trim($from_email); |
|
530 | + } elseif (trim($this->_from) !== '') { |
|
531 | + $from_name = ''; |
|
532 | + $from_email = trim($this->_from); |
|
533 | + } else { |
|
534 | + $from_name = $from_email = ''; |
|
535 | + } |
|
536 | + return array($from_name, $from_email); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Callback for the wp_mail_from filter. |
|
542 | + * |
|
543 | + * @since 4.3.1 |
|
544 | + * @param string $from_email What the original from_email is. |
|
545 | + * @return string |
|
546 | + */ |
|
547 | + public function set_from_address($from_email) |
|
548 | + { |
|
549 | + $parsed_from = $this->_parse_from(); |
|
550 | + //includes fallback if the parsing failed. |
|
551 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
552 | + ? $parsed_from[1] |
|
553 | + : get_bloginfo('admin_email'); |
|
554 | + return $from_email; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Callback fro the wp_mail_from_name filter. |
|
560 | + * |
|
561 | + * @since 4.3.1 |
|
562 | + * @param string $from_name The original from_name. |
|
563 | + * @return string |
|
564 | + */ |
|
565 | + public function set_from_name($from_name) |
|
566 | + { |
|
567 | + $parsed_from = $this->_parse_from(); |
|
568 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
569 | + $from_name = $parsed_from[0]; |
|
570 | + } |
|
571 | + |
|
572 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
573 | + $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name; |
|
574 | + |
|
575 | + return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8")); |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * setup body for email |
|
581 | + * |
|
582 | + * @param bool $preview will determine whether this is preview template or not. |
|
583 | + * @return string formatted body for email. |
|
584 | + * @throws EE_Error |
|
585 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
586 | + */ |
|
587 | + protected function _body($preview = false) |
|
588 | + { |
|
589 | + //setup template args! |
|
590 | + $this->_template_args = array( |
|
591 | + 'subject' => $this->_subject, |
|
592 | + 'from' => $this->_from, |
|
593 | + 'main_body' => wpautop( |
|
594 | + stripslashes_deep( |
|
595 | + html_entity_decode($this->_content, ENT_QUOTES, "UTF-8") |
|
596 | + ) |
|
597 | + ), |
|
598 | + ); |
|
599 | + $body = $this->_get_main_template($preview); |
|
600 | + |
|
601 | + /** |
|
602 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
603 | + * |
|
604 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
605 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
606 | + */ |
|
607 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
608 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
609 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
610 | + |
|
611 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
612 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
613 | + $style = file_get_contents( |
|
614 | + $this->get_variation( |
|
615 | + $this->_tmp_pack, |
|
616 | + $this->_incoming_message_type->name, |
|
617 | + false, |
|
618 | + 'main', |
|
619 | + $this->_variation |
|
620 | + ), |
|
621 | + true |
|
622 | + ); |
|
623 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
624 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
625 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
626 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
627 | + $body = ltrim($body, "<?"); |
|
628 | + } |
|
629 | + |
|
630 | + } |
|
631 | + return $body; |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * This just returns any existing test settings that might be saved in the database |
|
637 | + * |
|
638 | + * @access public |
|
639 | + * @return array |
|
640 | + */ |
|
641 | + public function get_existing_test_settings() |
|
642 | + { |
|
643 | + $settings = parent::get_existing_test_settings(); |
|
644 | + //override subject if present because we always want it to be fresh. |
|
645 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
646 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
647 | + } |
|
648 | + return $settings; |
|
649 | + } |
|
650 | 650 | } |
@@ -13,1095 +13,1095 @@ |
||
13 | 13 | class EED_Messages extends EED_Module |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * This holds the EE_messages controller |
|
18 | - * |
|
19 | - * @deprecated 4.9.0 |
|
20 | - * @var EE_messages $_EEMSG |
|
21 | - */ |
|
22 | - protected static $_EEMSG; |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | - */ |
|
27 | - protected static $_message_resource_manager; |
|
28 | - |
|
29 | - /** |
|
30 | - * This holds the EE_Messages_Processor business class. |
|
31 | - * |
|
32 | - * @type EE_Messages_Processor |
|
33 | - */ |
|
34 | - protected static $_MSG_PROCESSOR; |
|
35 | - |
|
36 | - /** |
|
37 | - * holds all the paths for various messages components. |
|
38 | - * Utilized by autoloader registry |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $_MSG_PATHS; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | - * Format is: |
|
48 | - * array( |
|
49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | - * ) |
|
51 | - * |
|
52 | - * @var EE_Messages_Template_Pack[] |
|
53 | - */ |
|
54 | - protected static $_TMP_PACKS = array(); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @return EED_Messages |
|
59 | - */ |
|
60 | - public static function instance() |
|
61 | - { |
|
62 | - return parent::get_instance(__CLASS__); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks() |
|
73 | - { |
|
74 | - //actions |
|
75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | - //filters |
|
79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | - //register routes |
|
84 | - self::_register_routes(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - public static function set_hooks_admin() |
|
94 | - { |
|
95 | - //actions |
|
96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | - //filters |
|
108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * All the message triggers done by route go in here. |
|
119 | - * |
|
120 | - * @since 4.5.0 |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected static function _register_routes() |
|
124 | - { |
|
125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This is called when a browser display trigger is executed. |
|
135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | - * browser. |
|
137 | - * |
|
138 | - * @since 4.9.0 |
|
139 | - * @param WP $WP |
|
140 | - */ |
|
141 | - public function browser_trigger($WP) |
|
142 | - { |
|
143 | - //ensure controller is loaded |
|
144 | - self::_load_controller(); |
|
145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | - try { |
|
147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | - } catch (EE_Error $e) { |
|
150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | - 'event_espresso'); |
|
152 | - // add specific message for developers if WP_DEBUG in on |
|
153 | - $error_msg .= '||' . $e->getMessage(); |
|
154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * This is called when a browser error trigger is executed. |
|
161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | - * message and display it. |
|
163 | - * |
|
164 | - * @since 4.9.0 |
|
165 | - * @param $WP |
|
166 | - */ |
|
167 | - public function browser_error_trigger($WP) |
|
168 | - { |
|
169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | - if ($token) { |
|
171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | - if ($message instanceof EE_Message) { |
|
173 | - header('HTTP/1.1 200 OK'); |
|
174 | - $error_msg = nl2br($message->error_message()); |
|
175 | - ?> |
|
16 | + /** |
|
17 | + * This holds the EE_messages controller |
|
18 | + * |
|
19 | + * @deprecated 4.9.0 |
|
20 | + * @var EE_messages $_EEMSG |
|
21 | + */ |
|
22 | + protected static $_EEMSG; |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
26 | + */ |
|
27 | + protected static $_message_resource_manager; |
|
28 | + |
|
29 | + /** |
|
30 | + * This holds the EE_Messages_Processor business class. |
|
31 | + * |
|
32 | + * @type EE_Messages_Processor |
|
33 | + */ |
|
34 | + protected static $_MSG_PROCESSOR; |
|
35 | + |
|
36 | + /** |
|
37 | + * holds all the paths for various messages components. |
|
38 | + * Utilized by autoloader registry |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $_MSG_PATHS; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
47 | + * Format is: |
|
48 | + * array( |
|
49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
50 | + * ) |
|
51 | + * |
|
52 | + * @var EE_Messages_Template_Pack[] |
|
53 | + */ |
|
54 | + protected static $_TMP_PACKS = array(); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @return EED_Messages |
|
59 | + */ |
|
60 | + public static function instance() |
|
61 | + { |
|
62 | + return parent::get_instance(__CLASS__); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks() |
|
73 | + { |
|
74 | + //actions |
|
75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
78 | + //filters |
|
79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
83 | + //register routes |
|
84 | + self::_register_routes(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + public static function set_hooks_admin() |
|
94 | + { |
|
95 | + //actions |
|
96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
107 | + //filters |
|
108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * All the message triggers done by route go in here. |
|
119 | + * |
|
120 | + * @since 4.5.0 |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected static function _register_routes() |
|
124 | + { |
|
125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This is called when a browser display trigger is executed. |
|
135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
136 | + * browser. |
|
137 | + * |
|
138 | + * @since 4.9.0 |
|
139 | + * @param WP $WP |
|
140 | + */ |
|
141 | + public function browser_trigger($WP) |
|
142 | + { |
|
143 | + //ensure controller is loaded |
|
144 | + self::_load_controller(); |
|
145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
146 | + try { |
|
147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
149 | + } catch (EE_Error $e) { |
|
150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
151 | + 'event_espresso'); |
|
152 | + // add specific message for developers if WP_DEBUG in on |
|
153 | + $error_msg .= '||' . $e->getMessage(); |
|
154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * This is called when a browser error trigger is executed. |
|
161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
162 | + * message and display it. |
|
163 | + * |
|
164 | + * @since 4.9.0 |
|
165 | + * @param $WP |
|
166 | + */ |
|
167 | + public function browser_error_trigger($WP) |
|
168 | + { |
|
169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
170 | + if ($token) { |
|
171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
172 | + if ($message instanceof EE_Message) { |
|
173 | + header('HTTP/1.1 200 OK'); |
|
174 | + $error_msg = nl2br($message->error_message()); |
|
175 | + ?> |
|
176 | 176 | <!DOCTYPE html> |
177 | 177 | <html> |
178 | 178 | <head></head> |
179 | 179 | <body> |
180 | 180 | <?php echo empty($error_msg) |
181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | - 'event_espresso') |
|
183 | - : wp_kses( |
|
184 | - $error_msg, |
|
185 | - array( |
|
186 | - 'a' => array( |
|
187 | - 'href' => array(), |
|
188 | - 'title' => array(), |
|
189 | - ), |
|
190 | - 'span' => array(), |
|
191 | - 'div' => array(), |
|
192 | - 'p' => array(), |
|
193 | - 'strong' => array(), |
|
194 | - 'em' => array(), |
|
195 | - 'br' => array(), |
|
196 | - ) |
|
197 | - ); ?> |
|
181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
182 | + 'event_espresso') |
|
183 | + : wp_kses( |
|
184 | + $error_msg, |
|
185 | + array( |
|
186 | + 'a' => array( |
|
187 | + 'href' => array(), |
|
188 | + 'title' => array(), |
|
189 | + ), |
|
190 | + 'span' => array(), |
|
191 | + 'div' => array(), |
|
192 | + 'p' => array(), |
|
193 | + 'strong' => array(), |
|
194 | + 'em' => array(), |
|
195 | + 'br' => array(), |
|
196 | + ) |
|
197 | + ); ?> |
|
198 | 198 | </body> |
199 | 199 | </html> |
200 | 200 | <?php |
201 | - exit; |
|
202 | - } |
|
203 | - } |
|
204 | - return; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * This runs when the msg_url_trigger route has initiated. |
|
210 | - * |
|
211 | - * @since 4.5.0 |
|
212 | - * @param WP $WP |
|
213 | - * @throws EE_Error |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function run($WP) |
|
217 | - { |
|
218 | - //ensure controller is loaded |
|
219 | - self::_load_controller(); |
|
220 | - // attempt to process message |
|
221 | - try { |
|
222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | - } catch (EE_Error $e) { |
|
226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | - 'event_espresso'); |
|
228 | - // add specific message for developers if WP_DEBUG in on |
|
229 | - $error_msg .= '||' . $e->getMessage(); |
|
230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
237 | - * |
|
238 | - * @param WP $WP |
|
239 | - */ |
|
240 | - public function execute_batch_request($WP) |
|
241 | - { |
|
242 | - $this->run_cron(); |
|
243 | - header('HTTP/1.1 200 OK'); |
|
244 | - exit(); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | - * request. |
|
251 | - */ |
|
252 | - public function run_cron() |
|
253 | - { |
|
254 | - self::_load_controller(); |
|
255 | - //get required vars |
|
256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | - |
|
259 | - //now let's verify transient, if not valid exit immediately |
|
260 | - if (! get_transient($transient_key)) { |
|
261 | - /** |
|
262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | - */ |
|
264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | - } |
|
266 | - |
|
267 | - //if made it here, lets' delete the transient to keep the db clean |
|
268 | - delete_transient($transient_key); |
|
269 | - |
|
270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | - |
|
272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | - self::$_MSG_PROCESSOR->$method(); |
|
275 | - } else { |
|
276 | - //no matching task |
|
277 | - /** |
|
278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | - */ |
|
280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | - $cron_type))); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * This is used to retrieve the template pack for the given name. |
|
291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | - * the default template pack is returned. |
|
293 | - * |
|
294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | - * in generating the Pack class name). |
|
297 | - * @return EE_Messages_Template_Pack |
|
298 | - */ |
|
299 | - public static function get_template_pack($template_pack_name) |
|
300 | - { |
|
301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Retrieves an array of all template packs. |
|
308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | - * |
|
310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | - * @return EE_Messages_Template_Pack[] |
|
312 | - */ |
|
313 | - public static function get_template_packs() |
|
314 | - { |
|
315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | - |
|
317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | - $template_pack_collection->rewind(); |
|
320 | - $template_packs = array(); |
|
321 | - while ($template_pack_collection->valid()) { |
|
322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | - $template_pack_collection->next(); |
|
324 | - } |
|
325 | - return $template_packs; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | - * |
|
332 | - * @since 4.5.0 |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public static function set_autoloaders() |
|
336 | - { |
|
337 | - if (empty(self::$_MSG_PATHS)) { |
|
338 | - self::_set_messages_paths(); |
|
339 | - foreach (self::$_MSG_PATHS as $path) { |
|
340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | - } |
|
342 | - // add aliases |
|
343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | - * for use by the Messages Autoloaders |
|
352 | - * |
|
353 | - * @since 4.5.0 |
|
354 | - * @return void. |
|
355 | - */ |
|
356 | - protected static function _set_messages_paths() |
|
357 | - { |
|
358 | - $dir_ref = array( |
|
359 | - 'messages/message_type', |
|
360 | - 'messages/messenger', |
|
361 | - 'messages/defaults', |
|
362 | - 'messages/defaults/email', |
|
363 | - 'messages/data_class', |
|
364 | - 'messages/validators', |
|
365 | - 'messages/validators/email', |
|
366 | - 'messages/validators/html', |
|
367 | - 'shortcodes', |
|
368 | - ); |
|
369 | - $paths = array(); |
|
370 | - foreach ($dir_ref as $index => $dir) { |
|
371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | - } |
|
373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Takes care of loading dependencies |
|
379 | - * |
|
380 | - * @since 4.5.0 |
|
381 | - * @return void |
|
382 | - */ |
|
383 | - protected static function _load_controller() |
|
384 | - { |
|
385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | - self::set_autoloaders(); |
|
388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * @param EE_Transaction $transaction |
|
397 | - */ |
|
398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
399 | - { |
|
400 | - self::_load_controller(); |
|
401 | - $data = array($transaction, null); |
|
402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
408 | - * |
|
409 | - * @param EE_Transaction object |
|
410 | - * @param EE_Payment object |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | - { |
|
415 | - self::_load_controller(); |
|
416 | - $data = array($transaction, $payment); |
|
417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @param EE_Transaction $transaction |
|
427 | - */ |
|
428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | - { |
|
430 | - self::_load_controller(); |
|
431 | - $data = array($transaction, null); |
|
432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Trigger for Registration messages |
|
438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | - * incoming transaction. |
|
440 | - * |
|
441 | - * @param EE_Registration $registration |
|
442 | - * @param array $extra_details |
|
443 | - * @return void |
|
444 | - */ |
|
445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | - { |
|
447 | - |
|
448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | - //no messages please |
|
450 | - return; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - //get all registrations so we make sure we send messages for the right status. |
|
455 | - $all_registrations = $registration->transaction()->registrations(); |
|
456 | - |
|
457 | - //cached array of statuses so we only trigger messages once per status. |
|
458 | - $statuses_sent = array(); |
|
459 | - self::_load_controller(); |
|
460 | - $mtgs = array(); |
|
461 | - |
|
462 | - //loop through registrations and trigger messages once per status. |
|
463 | - foreach ($all_registrations as $reg) { |
|
464 | - |
|
465 | - //already triggered? |
|
466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | - continue; |
|
468 | - } |
|
469 | - |
|
470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | - $mtgs = array_merge( |
|
472 | - $mtgs, |
|
473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | - $message_type, |
|
475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
476 | - ) |
|
477 | - ); |
|
478 | - $statuses_sent[] = $reg->status_ID(); |
|
479 | - } |
|
480 | - |
|
481 | - if (count($statuses_sent) > 1) { |
|
482 | - $mtgs = array_merge( |
|
483 | - $mtgs, |
|
484 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
485 | - 'registration_summary', |
|
486 | - array($registration->transaction(), null) |
|
487 | - ) |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - //batch queue and initiate request |
|
492 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
493 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * This is a helper method used to very whether a registration notification should be sent or |
|
499 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
500 | - * |
|
501 | - * @param EE_Registration $registration [description] |
|
502 | - * @param array $extra_details [description] |
|
503 | - * @return bool true = send away, false = nope halt the presses. |
|
504 | - */ |
|
505 | - protected static function _verify_registration_notification_send( |
|
506 | - EE_Registration $registration, |
|
507 | - $extra_details = array() |
|
508 | - ) { |
|
509 | - //self::log( |
|
510 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
511 | - // $registration->transaction(), |
|
512 | - // array( '$extra_details' => $extra_details ) |
|
513 | - //); |
|
514 | - // currently only using this to send messages for the primary registrant |
|
515 | - if (! $registration->is_primary_registrant()) { |
|
516 | - return false; |
|
517 | - } |
|
518 | - // first we check if we're in admin and not doing front ajax |
|
519 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
520 | - //make sure appropriate admin params are set for sending messages |
|
521 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
522 | - //no messages sent please. |
|
523 | - return false; |
|
524 | - } |
|
525 | - } else { |
|
526 | - // frontend request (either regular or via AJAX) |
|
527 | - // TXN is NOT finalized ? |
|
528 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
529 | - return false; |
|
530 | - } |
|
531 | - // return visit but nothing changed ??? |
|
532 | - if ( |
|
533 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
534 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
535 | - ) { |
|
536 | - return false; |
|
537 | - } |
|
538 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
539 | - if ( |
|
540 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
541 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
542 | - ) { |
|
543 | - return false; |
|
544 | - } |
|
545 | - } |
|
546 | - // release the kraken |
|
547 | - return true; |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
553 | - * status id. |
|
554 | - * |
|
555 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
556 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
557 | - * @param string $reg_status |
|
558 | - * @return array |
|
559 | - */ |
|
560 | - protected static function _get_reg_status_array($reg_status = '') |
|
561 | - { |
|
562 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
563 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
564 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
565 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * Simply returns the payment message type for the given payment status. |
|
571 | - * |
|
572 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
573 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
574 | - * @param string $payment_status The payment status being matched. |
|
575 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
576 | - */ |
|
577 | - protected static function _get_payment_message_type($payment_status) |
|
578 | - { |
|
579 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
580 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
581 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
582 | - : false; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
588 | - * |
|
589 | - * @access public |
|
590 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
591 | - * @return bool success/fail |
|
592 | - */ |
|
593 | - public static function process_resend($req_data) |
|
594 | - { |
|
595 | - self::_load_controller(); |
|
596 | - |
|
597 | - //if $msgID in this request then skip to the new resend_message |
|
598 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
599 | - return self::resend_message(); |
|
600 | - } |
|
601 | - |
|
602 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
603 | - $req_data = (array)$req_data; |
|
604 | - foreach ($req_data as $request_key => $request_value) { |
|
605 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
606 | - } |
|
607 | - |
|
608 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
609 | - return false; |
|
610 | - } |
|
611 | - |
|
612 | - try { |
|
613 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
614 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
615 | - } catch (EE_Error $e) { |
|
616 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
617 | - return false; |
|
618 | - } |
|
619 | - EE_Error::add_success( |
|
620 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
621 | - ); |
|
622 | - return true; //everything got queued. |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
628 | - * |
|
629 | - * @return bool |
|
630 | - */ |
|
631 | - public static function resend_message() |
|
632 | - { |
|
633 | - self::_load_controller(); |
|
634 | - |
|
635 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
636 | - if (! $msgID) { |
|
637 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
638 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
643 | - |
|
644 | - //setup success message. |
|
645 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
646 | - EE_Error::add_success(sprintf( |
|
647 | - _n( |
|
648 | - 'There was %d message queued for resending.', |
|
649 | - 'There were %d messages queued for resending.', |
|
650 | - $count_ready_for_resend, |
|
651 | - 'event_espresso' |
|
652 | - ), |
|
653 | - $count_ready_for_resend |
|
654 | - )); |
|
655 | - return true; |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Message triggers for manual payment applied by admin |
|
661 | - * |
|
662 | - * @param EE_Payment $payment EE_payment object |
|
663 | - * @return bool success/fail |
|
664 | - */ |
|
665 | - public static function process_admin_payment(EE_Payment $payment) |
|
666 | - { |
|
667 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
668 | - //we need to get the transaction object |
|
669 | - $transaction = $payment->transaction(); |
|
670 | - if ($transaction instanceof EE_Transaction) { |
|
671 | - $data = array($transaction, $payment); |
|
672 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
673 | - |
|
674 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
675 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
676 | - |
|
677 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
678 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
679 | - |
|
680 | - self::_load_controller(); |
|
681 | - |
|
682 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
683 | - |
|
684 | - //get count of queued for generation |
|
685 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
686 | - EEM_Message::status_incomplete, |
|
687 | - EEM_Message::status_idle, |
|
688 | - )); |
|
689 | - |
|
690 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
691 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
692 | - return true; |
|
693 | - } else { |
|
694 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
695 | - /** |
|
696 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
697 | - * IMMEDIATE generation. |
|
698 | - */ |
|
699 | - if ($count_failed > 0) { |
|
700 | - EE_Error::add_error(sprintf( |
|
701 | - _n( |
|
702 | - 'The payment notification generation failed.', |
|
703 | - '%d payment notifications failed being sent.', |
|
704 | - $count_failed, |
|
705 | - 'event_espresso' |
|
706 | - ), |
|
707 | - $count_failed |
|
708 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
709 | - |
|
710 | - return false; |
|
711 | - } else { |
|
712 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
713 | - return true; |
|
714 | - } |
|
715 | - } |
|
716 | - } else { |
|
717 | - EE_Error::add_error( |
|
718 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
719 | - 'event_espresso' |
|
720 | - ); |
|
721 | - return false; |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
728 | - * |
|
729 | - * @since 4.3.0 |
|
730 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
731 | - * @param int $grp_id a specific message template group id. |
|
732 | - * @return void |
|
733 | - */ |
|
734 | - public static function send_newsletter_message($registrations, $grp_id) |
|
735 | - { |
|
736 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
737 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
738 | - self::_load_controller(); |
|
739 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
745 | - * |
|
746 | - * @since 4.3.0 |
|
747 | - * @param string $registration_message_trigger_url |
|
748 | - * @param EE_Registration $registration |
|
749 | - * @param string $messenger |
|
750 | - * @param string $message_type |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - public static function registration_message_trigger_url( |
|
754 | - $registration_message_trigger_url, |
|
755 | - EE_Registration $registration, |
|
756 | - $messenger = 'html', |
|
757 | - $message_type = 'invoice' |
|
758 | - ) { |
|
759 | - // whitelist $messenger |
|
760 | - switch ($messenger) { |
|
761 | - case 'pdf' : |
|
762 | - $sending_messenger = 'pdf'; |
|
763 | - $generating_messenger = 'html'; |
|
764 | - break; |
|
765 | - case 'html' : |
|
766 | - default : |
|
767 | - $sending_messenger = 'html'; |
|
768 | - $generating_messenger = 'html'; |
|
769 | - break; |
|
770 | - } |
|
771 | - // whitelist $message_type |
|
772 | - switch ($message_type) { |
|
773 | - case 'receipt' : |
|
774 | - $message_type = 'receipt'; |
|
775 | - break; |
|
776 | - case 'invoice' : |
|
777 | - default : |
|
778 | - $message_type = 'invoice'; |
|
779 | - break; |
|
780 | - } |
|
781 | - // verify that both the messenger AND the message type are active |
|
782 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
783 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
784 | - $template_query_params = array( |
|
785 | - 'MTP_is_active' => true, |
|
786 | - 'MTP_messenger' => $generating_messenger, |
|
787 | - 'MTP_message_type' => $message_type, |
|
788 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
789 | - ); |
|
790 | - //get the message template group. |
|
791 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
792 | - //if we don't have an EE_Message_Template_Group then return |
|
793 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
794 | - // remove EVT_ID from query params so that global templates get picked up |
|
795 | - unset($template_query_params['Event.EVT_ID']); |
|
796 | - //get global template as the fallback |
|
797 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
798 | - } |
|
799 | - //if we don't have an EE_Message_Template_Group then return |
|
800 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
801 | - return ''; |
|
802 | - } |
|
803 | - // generate the URL |
|
804 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
805 | - $sending_messenger, |
|
806 | - $generating_messenger, |
|
807 | - 'purchaser', |
|
808 | - $message_type, |
|
809 | - $registration, |
|
810 | - $msg_template_group->ID(), |
|
811 | - $registration->transaction_ID() |
|
812 | - ); |
|
813 | - |
|
814 | - } |
|
815 | - return $registration_message_trigger_url; |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - /** |
|
820 | - * Use to generate and return a message preview! |
|
821 | - * |
|
822 | - * @param string $type This should correspond with a valid message type |
|
823 | - * @param string $context This should correspond with a valid context for the message type |
|
824 | - * @param string $messenger This should correspond with a valid messenger. |
|
825 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
826 | - * preview |
|
827 | - * @return bool|string The body of the message or if send is requested, sends. |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
831 | - { |
|
832 | - self::_load_controller(); |
|
833 | - $mtg = new EE_Message_To_Generate( |
|
834 | - $messenger, |
|
835 | - $type, |
|
836 | - array(), |
|
837 | - $context, |
|
838 | - true |
|
839 | - ); |
|
840 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
841 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
842 | - $content = $generated_preview_queue->get_message_repository()->current()->content(); |
|
843 | - //if the current message was persisted to the db (which will happen with any extra fields on a message) then |
|
844 | - //let's delete it because we don't need previews cluttering up the db. |
|
845 | - if ($generated_preview_queue->get_message_repository()->current()->ID() > 0 |
|
846 | - && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed |
|
847 | - ) { |
|
848 | - $generated_preview_queue->get_message_repository()->delete(); |
|
849 | - } |
|
850 | - return $content; |
|
851 | - } else { |
|
852 | - return $generated_preview_queue; |
|
853 | - } |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
859 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
860 | - * content found in the EE_Message objects in the queue. |
|
861 | - * |
|
862 | - * @since 4.9.0 |
|
863 | - * @param string $messenger a string matching a valid active messenger in the system |
|
864 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
865 | - * type name is still required to send along the message type to the |
|
866 | - * messenger because this is used for determining what specific |
|
867 | - * variations might be loaded for the generated message. |
|
868 | - * @param EE_Messages_Queue $queue |
|
869 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
870 | - * aggregate EE_Message object. |
|
871 | - * @return bool success or fail. |
|
872 | - */ |
|
873 | - public static function send_message_with_messenger_only( |
|
874 | - $messenger, |
|
875 | - $message_type, |
|
876 | - EE_Messages_Queue $queue, |
|
877 | - $custom_subject = '' |
|
878 | - ) { |
|
879 | - self::_load_controller(); |
|
880 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
881 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
882 | - 'Message_To_Generate_From_Queue', |
|
883 | - array( |
|
884 | - $messenger, |
|
885 | - $message_type, |
|
886 | - $queue, |
|
887 | - $custom_subject, |
|
888 | - ) |
|
889 | - ); |
|
890 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
896 | - * |
|
897 | - * @since 4.9.0 |
|
898 | - * @param array $message_ids An array of message ids |
|
899 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
900 | - * messages. |
|
901 | - */ |
|
902 | - public static function generate_now($message_ids) |
|
903 | - { |
|
904 | - self::_load_controller(); |
|
905 | - $messages = EEM_Message::instance()->get_all( |
|
906 | - array( |
|
907 | - 0 => array( |
|
908 | - 'MSG_ID' => array('IN', $message_ids), |
|
909 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
910 | - ), |
|
911 | - ) |
|
912 | - ); |
|
913 | - $generated_queue = false; |
|
914 | - if ($messages) { |
|
915 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
916 | - } |
|
917 | - |
|
918 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
919 | - EE_Error::add_error( |
|
920 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
921 | - 'event_espresso'), |
|
922 | - __FILE__, __FUNCTION__, __LINE__ |
|
923 | - ); |
|
924 | - } |
|
925 | - return $generated_queue; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
931 | - * EEM_Message::status_idle |
|
932 | - * |
|
933 | - * @since 4.9.0 |
|
934 | - * @param $message_ids |
|
935 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
936 | - */ |
|
937 | - public static function send_now($message_ids) |
|
938 | - { |
|
939 | - self::_load_controller(); |
|
940 | - $messages = EEM_Message::instance()->get_all( |
|
941 | - array( |
|
942 | - 0 => array( |
|
943 | - 'MSG_ID' => array('IN', $message_ids), |
|
944 | - 'STS_ID' => array( |
|
945 | - 'IN', |
|
946 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
947 | - ), |
|
948 | - ), |
|
949 | - ) |
|
950 | - ); |
|
951 | - $sent_queue = false; |
|
952 | - if ($messages) { |
|
953 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
954 | - } |
|
955 | - |
|
956 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
957 | - EE_Error::add_error( |
|
958 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
959 | - 'event_espresso'), |
|
960 | - __FILE__, __FUNCTION__, __LINE__ |
|
961 | - ); |
|
962 | - } else { |
|
963 | - //can count how many sent by using the messages in the queue |
|
964 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
965 | - if ($sent_count > 0) { |
|
966 | - EE_Error::add_success( |
|
967 | - sprintf( |
|
968 | - _n( |
|
969 | - 'There was %d message successfully sent.', |
|
970 | - 'There were %d messages successfully sent.', |
|
971 | - $sent_count, |
|
972 | - 'event_espresso' |
|
973 | - ), |
|
974 | - $sent_count |
|
975 | - ) |
|
976 | - ); |
|
977 | - } else { |
|
978 | - EE_Error::overwrite_errors(); |
|
979 | - EE_Error::add_error( |
|
980 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
201 | + exit; |
|
202 | + } |
|
203 | + } |
|
204 | + return; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * This runs when the msg_url_trigger route has initiated. |
|
210 | + * |
|
211 | + * @since 4.5.0 |
|
212 | + * @param WP $WP |
|
213 | + * @throws EE_Error |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function run($WP) |
|
217 | + { |
|
218 | + //ensure controller is loaded |
|
219 | + self::_load_controller(); |
|
220 | + // attempt to process message |
|
221 | + try { |
|
222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
225 | + } catch (EE_Error $e) { |
|
226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
227 | + 'event_espresso'); |
|
228 | + // add specific message for developers if WP_DEBUG in on |
|
229 | + $error_msg .= '||' . $e->getMessage(); |
|
230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
237 | + * |
|
238 | + * @param WP $WP |
|
239 | + */ |
|
240 | + public function execute_batch_request($WP) |
|
241 | + { |
|
242 | + $this->run_cron(); |
|
243 | + header('HTTP/1.1 200 OK'); |
|
244 | + exit(); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
250 | + * request. |
|
251 | + */ |
|
252 | + public function run_cron() |
|
253 | + { |
|
254 | + self::_load_controller(); |
|
255 | + //get required vars |
|
256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
258 | + |
|
259 | + //now let's verify transient, if not valid exit immediately |
|
260 | + if (! get_transient($transient_key)) { |
|
261 | + /** |
|
262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
263 | + */ |
|
264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
265 | + } |
|
266 | + |
|
267 | + //if made it here, lets' delete the transient to keep the db clean |
|
268 | + delete_transient($transient_key); |
|
269 | + |
|
270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
271 | + |
|
272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
274 | + self::$_MSG_PROCESSOR->$method(); |
|
275 | + } else { |
|
276 | + //no matching task |
|
277 | + /** |
|
278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
279 | + */ |
|
280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
281 | + $cron_type))); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * This is used to retrieve the template pack for the given name. |
|
291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
292 | + * the default template pack is returned. |
|
293 | + * |
|
294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
296 | + * in generating the Pack class name). |
|
297 | + * @return EE_Messages_Template_Pack |
|
298 | + */ |
|
299 | + public static function get_template_pack($template_pack_name) |
|
300 | + { |
|
301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Retrieves an array of all template packs. |
|
308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
309 | + * |
|
310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
311 | + * @return EE_Messages_Template_Pack[] |
|
312 | + */ |
|
313 | + public static function get_template_packs() |
|
314 | + { |
|
315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
316 | + |
|
317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
319 | + $template_pack_collection->rewind(); |
|
320 | + $template_packs = array(); |
|
321 | + while ($template_pack_collection->valid()) { |
|
322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
323 | + $template_pack_collection->next(); |
|
324 | + } |
|
325 | + return $template_packs; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
331 | + * |
|
332 | + * @since 4.5.0 |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public static function set_autoloaders() |
|
336 | + { |
|
337 | + if (empty(self::$_MSG_PATHS)) { |
|
338 | + self::_set_messages_paths(); |
|
339 | + foreach (self::$_MSG_PATHS as $path) { |
|
340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
341 | + } |
|
342 | + // add aliases |
|
343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
351 | + * for use by the Messages Autoloaders |
|
352 | + * |
|
353 | + * @since 4.5.0 |
|
354 | + * @return void. |
|
355 | + */ |
|
356 | + protected static function _set_messages_paths() |
|
357 | + { |
|
358 | + $dir_ref = array( |
|
359 | + 'messages/message_type', |
|
360 | + 'messages/messenger', |
|
361 | + 'messages/defaults', |
|
362 | + 'messages/defaults/email', |
|
363 | + 'messages/data_class', |
|
364 | + 'messages/validators', |
|
365 | + 'messages/validators/email', |
|
366 | + 'messages/validators/html', |
|
367 | + 'shortcodes', |
|
368 | + ); |
|
369 | + $paths = array(); |
|
370 | + foreach ($dir_ref as $index => $dir) { |
|
371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
372 | + } |
|
373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Takes care of loading dependencies |
|
379 | + * |
|
380 | + * @since 4.5.0 |
|
381 | + * @return void |
|
382 | + */ |
|
383 | + protected static function _load_controller() |
|
384 | + { |
|
385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
387 | + self::set_autoloaders(); |
|
388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * @param EE_Transaction $transaction |
|
397 | + */ |
|
398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
399 | + { |
|
400 | + self::_load_controller(); |
|
401 | + $data = array($transaction, null); |
|
402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
408 | + * |
|
409 | + * @param EE_Transaction object |
|
410 | + * @param EE_Payment object |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
414 | + { |
|
415 | + self::_load_controller(); |
|
416 | + $data = array($transaction, $payment); |
|
417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @param EE_Transaction $transaction |
|
427 | + */ |
|
428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
429 | + { |
|
430 | + self::_load_controller(); |
|
431 | + $data = array($transaction, null); |
|
432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Trigger for Registration messages |
|
438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
439 | + * incoming transaction. |
|
440 | + * |
|
441 | + * @param EE_Registration $registration |
|
442 | + * @param array $extra_details |
|
443 | + * @return void |
|
444 | + */ |
|
445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
446 | + { |
|
447 | + |
|
448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
449 | + //no messages please |
|
450 | + return; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + //get all registrations so we make sure we send messages for the right status. |
|
455 | + $all_registrations = $registration->transaction()->registrations(); |
|
456 | + |
|
457 | + //cached array of statuses so we only trigger messages once per status. |
|
458 | + $statuses_sent = array(); |
|
459 | + self::_load_controller(); |
|
460 | + $mtgs = array(); |
|
461 | + |
|
462 | + //loop through registrations and trigger messages once per status. |
|
463 | + foreach ($all_registrations as $reg) { |
|
464 | + |
|
465 | + //already triggered? |
|
466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
467 | + continue; |
|
468 | + } |
|
469 | + |
|
470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
471 | + $mtgs = array_merge( |
|
472 | + $mtgs, |
|
473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
474 | + $message_type, |
|
475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
476 | + ) |
|
477 | + ); |
|
478 | + $statuses_sent[] = $reg->status_ID(); |
|
479 | + } |
|
480 | + |
|
481 | + if (count($statuses_sent) > 1) { |
|
482 | + $mtgs = array_merge( |
|
483 | + $mtgs, |
|
484 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
485 | + 'registration_summary', |
|
486 | + array($registration->transaction(), null) |
|
487 | + ) |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + //batch queue and initiate request |
|
492 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
493 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * This is a helper method used to very whether a registration notification should be sent or |
|
499 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
500 | + * |
|
501 | + * @param EE_Registration $registration [description] |
|
502 | + * @param array $extra_details [description] |
|
503 | + * @return bool true = send away, false = nope halt the presses. |
|
504 | + */ |
|
505 | + protected static function _verify_registration_notification_send( |
|
506 | + EE_Registration $registration, |
|
507 | + $extra_details = array() |
|
508 | + ) { |
|
509 | + //self::log( |
|
510 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
511 | + // $registration->transaction(), |
|
512 | + // array( '$extra_details' => $extra_details ) |
|
513 | + //); |
|
514 | + // currently only using this to send messages for the primary registrant |
|
515 | + if (! $registration->is_primary_registrant()) { |
|
516 | + return false; |
|
517 | + } |
|
518 | + // first we check if we're in admin and not doing front ajax |
|
519 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
520 | + //make sure appropriate admin params are set for sending messages |
|
521 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
522 | + //no messages sent please. |
|
523 | + return false; |
|
524 | + } |
|
525 | + } else { |
|
526 | + // frontend request (either regular or via AJAX) |
|
527 | + // TXN is NOT finalized ? |
|
528 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
529 | + return false; |
|
530 | + } |
|
531 | + // return visit but nothing changed ??? |
|
532 | + if ( |
|
533 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
534 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
535 | + ) { |
|
536 | + return false; |
|
537 | + } |
|
538 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
539 | + if ( |
|
540 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
541 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
542 | + ) { |
|
543 | + return false; |
|
544 | + } |
|
545 | + } |
|
546 | + // release the kraken |
|
547 | + return true; |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
553 | + * status id. |
|
554 | + * |
|
555 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
556 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
557 | + * @param string $reg_status |
|
558 | + * @return array |
|
559 | + */ |
|
560 | + protected static function _get_reg_status_array($reg_status = '') |
|
561 | + { |
|
562 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
563 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
564 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
565 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * Simply returns the payment message type for the given payment status. |
|
571 | + * |
|
572 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
573 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
574 | + * @param string $payment_status The payment status being matched. |
|
575 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
576 | + */ |
|
577 | + protected static function _get_payment_message_type($payment_status) |
|
578 | + { |
|
579 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
580 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
581 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
582 | + : false; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
588 | + * |
|
589 | + * @access public |
|
590 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
591 | + * @return bool success/fail |
|
592 | + */ |
|
593 | + public static function process_resend($req_data) |
|
594 | + { |
|
595 | + self::_load_controller(); |
|
596 | + |
|
597 | + //if $msgID in this request then skip to the new resend_message |
|
598 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
599 | + return self::resend_message(); |
|
600 | + } |
|
601 | + |
|
602 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
603 | + $req_data = (array)$req_data; |
|
604 | + foreach ($req_data as $request_key => $request_value) { |
|
605 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
606 | + } |
|
607 | + |
|
608 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
609 | + return false; |
|
610 | + } |
|
611 | + |
|
612 | + try { |
|
613 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
614 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
615 | + } catch (EE_Error $e) { |
|
616 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
617 | + return false; |
|
618 | + } |
|
619 | + EE_Error::add_success( |
|
620 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
621 | + ); |
|
622 | + return true; //everything got queued. |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
628 | + * |
|
629 | + * @return bool |
|
630 | + */ |
|
631 | + public static function resend_message() |
|
632 | + { |
|
633 | + self::_load_controller(); |
|
634 | + |
|
635 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
636 | + if (! $msgID) { |
|
637 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
638 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
643 | + |
|
644 | + //setup success message. |
|
645 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
646 | + EE_Error::add_success(sprintf( |
|
647 | + _n( |
|
648 | + 'There was %d message queued for resending.', |
|
649 | + 'There were %d messages queued for resending.', |
|
650 | + $count_ready_for_resend, |
|
651 | + 'event_espresso' |
|
652 | + ), |
|
653 | + $count_ready_for_resend |
|
654 | + )); |
|
655 | + return true; |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Message triggers for manual payment applied by admin |
|
661 | + * |
|
662 | + * @param EE_Payment $payment EE_payment object |
|
663 | + * @return bool success/fail |
|
664 | + */ |
|
665 | + public static function process_admin_payment(EE_Payment $payment) |
|
666 | + { |
|
667 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
668 | + //we need to get the transaction object |
|
669 | + $transaction = $payment->transaction(); |
|
670 | + if ($transaction instanceof EE_Transaction) { |
|
671 | + $data = array($transaction, $payment); |
|
672 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
673 | + |
|
674 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
675 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
676 | + |
|
677 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
678 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
679 | + |
|
680 | + self::_load_controller(); |
|
681 | + |
|
682 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
683 | + |
|
684 | + //get count of queued for generation |
|
685 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
686 | + EEM_Message::status_incomplete, |
|
687 | + EEM_Message::status_idle, |
|
688 | + )); |
|
689 | + |
|
690 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
691 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
692 | + return true; |
|
693 | + } else { |
|
694 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
695 | + /** |
|
696 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
697 | + * IMMEDIATE generation. |
|
698 | + */ |
|
699 | + if ($count_failed > 0) { |
|
700 | + EE_Error::add_error(sprintf( |
|
701 | + _n( |
|
702 | + 'The payment notification generation failed.', |
|
703 | + '%d payment notifications failed being sent.', |
|
704 | + $count_failed, |
|
705 | + 'event_espresso' |
|
706 | + ), |
|
707 | + $count_failed |
|
708 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
709 | + |
|
710 | + return false; |
|
711 | + } else { |
|
712 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
713 | + return true; |
|
714 | + } |
|
715 | + } |
|
716 | + } else { |
|
717 | + EE_Error::add_error( |
|
718 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
719 | + 'event_espresso' |
|
720 | + ); |
|
721 | + return false; |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
728 | + * |
|
729 | + * @since 4.3.0 |
|
730 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
731 | + * @param int $grp_id a specific message template group id. |
|
732 | + * @return void |
|
733 | + */ |
|
734 | + public static function send_newsletter_message($registrations, $grp_id) |
|
735 | + { |
|
736 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
737 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
738 | + self::_load_controller(); |
|
739 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
745 | + * |
|
746 | + * @since 4.3.0 |
|
747 | + * @param string $registration_message_trigger_url |
|
748 | + * @param EE_Registration $registration |
|
749 | + * @param string $messenger |
|
750 | + * @param string $message_type |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + public static function registration_message_trigger_url( |
|
754 | + $registration_message_trigger_url, |
|
755 | + EE_Registration $registration, |
|
756 | + $messenger = 'html', |
|
757 | + $message_type = 'invoice' |
|
758 | + ) { |
|
759 | + // whitelist $messenger |
|
760 | + switch ($messenger) { |
|
761 | + case 'pdf' : |
|
762 | + $sending_messenger = 'pdf'; |
|
763 | + $generating_messenger = 'html'; |
|
764 | + break; |
|
765 | + case 'html' : |
|
766 | + default : |
|
767 | + $sending_messenger = 'html'; |
|
768 | + $generating_messenger = 'html'; |
|
769 | + break; |
|
770 | + } |
|
771 | + // whitelist $message_type |
|
772 | + switch ($message_type) { |
|
773 | + case 'receipt' : |
|
774 | + $message_type = 'receipt'; |
|
775 | + break; |
|
776 | + case 'invoice' : |
|
777 | + default : |
|
778 | + $message_type = 'invoice'; |
|
779 | + break; |
|
780 | + } |
|
781 | + // verify that both the messenger AND the message type are active |
|
782 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
783 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
784 | + $template_query_params = array( |
|
785 | + 'MTP_is_active' => true, |
|
786 | + 'MTP_messenger' => $generating_messenger, |
|
787 | + 'MTP_message_type' => $message_type, |
|
788 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
789 | + ); |
|
790 | + //get the message template group. |
|
791 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
792 | + //if we don't have an EE_Message_Template_Group then return |
|
793 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
794 | + // remove EVT_ID from query params so that global templates get picked up |
|
795 | + unset($template_query_params['Event.EVT_ID']); |
|
796 | + //get global template as the fallback |
|
797 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
798 | + } |
|
799 | + //if we don't have an EE_Message_Template_Group then return |
|
800 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
801 | + return ''; |
|
802 | + } |
|
803 | + // generate the URL |
|
804 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
805 | + $sending_messenger, |
|
806 | + $generating_messenger, |
|
807 | + 'purchaser', |
|
808 | + $message_type, |
|
809 | + $registration, |
|
810 | + $msg_template_group->ID(), |
|
811 | + $registration->transaction_ID() |
|
812 | + ); |
|
813 | + |
|
814 | + } |
|
815 | + return $registration_message_trigger_url; |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + /** |
|
820 | + * Use to generate and return a message preview! |
|
821 | + * |
|
822 | + * @param string $type This should correspond with a valid message type |
|
823 | + * @param string $context This should correspond with a valid context for the message type |
|
824 | + * @param string $messenger This should correspond with a valid messenger. |
|
825 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
826 | + * preview |
|
827 | + * @return bool|string The body of the message or if send is requested, sends. |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
831 | + { |
|
832 | + self::_load_controller(); |
|
833 | + $mtg = new EE_Message_To_Generate( |
|
834 | + $messenger, |
|
835 | + $type, |
|
836 | + array(), |
|
837 | + $context, |
|
838 | + true |
|
839 | + ); |
|
840 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
841 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
842 | + $content = $generated_preview_queue->get_message_repository()->current()->content(); |
|
843 | + //if the current message was persisted to the db (which will happen with any extra fields on a message) then |
|
844 | + //let's delete it because we don't need previews cluttering up the db. |
|
845 | + if ($generated_preview_queue->get_message_repository()->current()->ID() > 0 |
|
846 | + && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed |
|
847 | + ) { |
|
848 | + $generated_preview_queue->get_message_repository()->delete(); |
|
849 | + } |
|
850 | + return $content; |
|
851 | + } else { |
|
852 | + return $generated_preview_queue; |
|
853 | + } |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
859 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
860 | + * content found in the EE_Message objects in the queue. |
|
861 | + * |
|
862 | + * @since 4.9.0 |
|
863 | + * @param string $messenger a string matching a valid active messenger in the system |
|
864 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
865 | + * type name is still required to send along the message type to the |
|
866 | + * messenger because this is used for determining what specific |
|
867 | + * variations might be loaded for the generated message. |
|
868 | + * @param EE_Messages_Queue $queue |
|
869 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
870 | + * aggregate EE_Message object. |
|
871 | + * @return bool success or fail. |
|
872 | + */ |
|
873 | + public static function send_message_with_messenger_only( |
|
874 | + $messenger, |
|
875 | + $message_type, |
|
876 | + EE_Messages_Queue $queue, |
|
877 | + $custom_subject = '' |
|
878 | + ) { |
|
879 | + self::_load_controller(); |
|
880 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
881 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
882 | + 'Message_To_Generate_From_Queue', |
|
883 | + array( |
|
884 | + $messenger, |
|
885 | + $message_type, |
|
886 | + $queue, |
|
887 | + $custom_subject, |
|
888 | + ) |
|
889 | + ); |
|
890 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
896 | + * |
|
897 | + * @since 4.9.0 |
|
898 | + * @param array $message_ids An array of message ids |
|
899 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
900 | + * messages. |
|
901 | + */ |
|
902 | + public static function generate_now($message_ids) |
|
903 | + { |
|
904 | + self::_load_controller(); |
|
905 | + $messages = EEM_Message::instance()->get_all( |
|
906 | + array( |
|
907 | + 0 => array( |
|
908 | + 'MSG_ID' => array('IN', $message_ids), |
|
909 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
910 | + ), |
|
911 | + ) |
|
912 | + ); |
|
913 | + $generated_queue = false; |
|
914 | + if ($messages) { |
|
915 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
916 | + } |
|
917 | + |
|
918 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
919 | + EE_Error::add_error( |
|
920 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
921 | + 'event_espresso'), |
|
922 | + __FILE__, __FUNCTION__, __LINE__ |
|
923 | + ); |
|
924 | + } |
|
925 | + return $generated_queue; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
931 | + * EEM_Message::status_idle |
|
932 | + * |
|
933 | + * @since 4.9.0 |
|
934 | + * @param $message_ids |
|
935 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
936 | + */ |
|
937 | + public static function send_now($message_ids) |
|
938 | + { |
|
939 | + self::_load_controller(); |
|
940 | + $messages = EEM_Message::instance()->get_all( |
|
941 | + array( |
|
942 | + 0 => array( |
|
943 | + 'MSG_ID' => array('IN', $message_ids), |
|
944 | + 'STS_ID' => array( |
|
945 | + 'IN', |
|
946 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
947 | + ), |
|
948 | + ), |
|
949 | + ) |
|
950 | + ); |
|
951 | + $sent_queue = false; |
|
952 | + if ($messages) { |
|
953 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
954 | + } |
|
955 | + |
|
956 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
957 | + EE_Error::add_error( |
|
958 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
959 | + 'event_espresso'), |
|
960 | + __FILE__, __FUNCTION__, __LINE__ |
|
961 | + ); |
|
962 | + } else { |
|
963 | + //can count how many sent by using the messages in the queue |
|
964 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
965 | + if ($sent_count > 0) { |
|
966 | + EE_Error::add_success( |
|
967 | + sprintf( |
|
968 | + _n( |
|
969 | + 'There was %d message successfully sent.', |
|
970 | + 'There were %d messages successfully sent.', |
|
971 | + $sent_count, |
|
972 | + 'event_espresso' |
|
973 | + ), |
|
974 | + $sent_count |
|
975 | + ) |
|
976 | + ); |
|
977 | + } else { |
|
978 | + EE_Error::overwrite_errors(); |
|
979 | + EE_Error::add_error( |
|
980 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
981 | 981 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
982 | - 'event_espresso'), |
|
983 | - __FILE__, __FUNCTION__, __LINE__ |
|
984 | - ); |
|
985 | - } |
|
986 | - } |
|
987 | - return $sent_queue; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - /** |
|
992 | - * This will queue the incoming message ids for resending. |
|
993 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
994 | - * |
|
995 | - * @since 4.9.0 |
|
996 | - * @param array $message_ids An array of EE_Message IDs |
|
997 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
998 | - * resending. |
|
999 | - */ |
|
1000 | - public static function queue_for_resending($message_ids) |
|
1001 | - { |
|
1002 | - self::_load_controller(); |
|
1003 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1004 | - |
|
1005 | - //get queue and count |
|
1006 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1007 | - |
|
1008 | - if ( |
|
1009 | - $queue_count > 0 |
|
1010 | - ) { |
|
1011 | - EE_Error::add_success( |
|
1012 | - sprintf( |
|
1013 | - _n( |
|
1014 | - '%d message successfully queued for resending.', |
|
1015 | - '%d messages successfully queued for resending.', |
|
1016 | - $queue_count, |
|
1017 | - 'event_espresso' |
|
1018 | - ), |
|
1019 | - $queue_count |
|
1020 | - ) |
|
1021 | - ); |
|
1022 | - /** |
|
1023 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1024 | - */ |
|
1025 | - } elseif ( |
|
1026 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1027 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1028 | - ) { |
|
1029 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1030 | - if ($queue_count > 0) { |
|
1031 | - EE_Error::add_success( |
|
1032 | - sprintf( |
|
1033 | - _n( |
|
1034 | - '%d message successfully sent.', |
|
1035 | - '%d messages successfully sent.', |
|
1036 | - $queue_count, |
|
1037 | - 'event_espresso' |
|
1038 | - ), |
|
1039 | - $queue_count |
|
1040 | - ) |
|
1041 | - ); |
|
1042 | - } else { |
|
1043 | - EE_Error::add_error( |
|
1044 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1045 | - 'event_espresso'), |
|
1046 | - __FILE__, __FUNCTION__, __LINE__ |
|
1047 | - ); |
|
1048 | - } |
|
1049 | - } else { |
|
1050 | - EE_Error::add_error( |
|
1051 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1052 | - 'event_espresso'), |
|
1053 | - __FILE__, __FUNCTION__, __LINE__ |
|
1054 | - ); |
|
1055 | - } |
|
1056 | - return (bool)$queue_count; |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * debug |
|
1062 | - * |
|
1063 | - * @param string $class |
|
1064 | - * @param string $func |
|
1065 | - * @param string $line |
|
1066 | - * @param \EE_Transaction $transaction |
|
1067 | - * @param array $info |
|
1068 | - * @param bool $display_request |
|
1069 | - */ |
|
1070 | - protected static function log( |
|
1071 | - $class = '', |
|
1072 | - $func = '', |
|
1073 | - $line = '', |
|
1074 | - EE_Transaction $transaction, |
|
1075 | - $info = array(), |
|
1076 | - $display_request = false |
|
1077 | - ) { |
|
1078 | - if (WP_DEBUG && false) { |
|
1079 | - if ($transaction instanceof EE_Transaction) { |
|
1080 | - // don't serialize objects |
|
1081 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1082 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1083 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1084 | - if ($transaction->ID()) { |
|
1085 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1086 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1087 | - } |
|
1088 | - } |
|
1089 | - } |
|
1090 | - |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Resets all the static properties in this class when called. |
|
1096 | - */ |
|
1097 | - public static function reset() |
|
1098 | - { |
|
1099 | - self::$_EEMSG = null; |
|
1100 | - self::$_message_resource_manager = null; |
|
1101 | - self::$_MSG_PROCESSOR = null; |
|
1102 | - self::$_MSG_PATHS = null; |
|
1103 | - self::$_TMP_PACKS = array(); |
|
1104 | - } |
|
982 | + 'event_espresso'), |
|
983 | + __FILE__, __FUNCTION__, __LINE__ |
|
984 | + ); |
|
985 | + } |
|
986 | + } |
|
987 | + return $sent_queue; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + /** |
|
992 | + * This will queue the incoming message ids for resending. |
|
993 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
994 | + * |
|
995 | + * @since 4.9.0 |
|
996 | + * @param array $message_ids An array of EE_Message IDs |
|
997 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
998 | + * resending. |
|
999 | + */ |
|
1000 | + public static function queue_for_resending($message_ids) |
|
1001 | + { |
|
1002 | + self::_load_controller(); |
|
1003 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1004 | + |
|
1005 | + //get queue and count |
|
1006 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1007 | + |
|
1008 | + if ( |
|
1009 | + $queue_count > 0 |
|
1010 | + ) { |
|
1011 | + EE_Error::add_success( |
|
1012 | + sprintf( |
|
1013 | + _n( |
|
1014 | + '%d message successfully queued for resending.', |
|
1015 | + '%d messages successfully queued for resending.', |
|
1016 | + $queue_count, |
|
1017 | + 'event_espresso' |
|
1018 | + ), |
|
1019 | + $queue_count |
|
1020 | + ) |
|
1021 | + ); |
|
1022 | + /** |
|
1023 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1024 | + */ |
|
1025 | + } elseif ( |
|
1026 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1027 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1028 | + ) { |
|
1029 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1030 | + if ($queue_count > 0) { |
|
1031 | + EE_Error::add_success( |
|
1032 | + sprintf( |
|
1033 | + _n( |
|
1034 | + '%d message successfully sent.', |
|
1035 | + '%d messages successfully sent.', |
|
1036 | + $queue_count, |
|
1037 | + 'event_espresso' |
|
1038 | + ), |
|
1039 | + $queue_count |
|
1040 | + ) |
|
1041 | + ); |
|
1042 | + } else { |
|
1043 | + EE_Error::add_error( |
|
1044 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1045 | + 'event_espresso'), |
|
1046 | + __FILE__, __FUNCTION__, __LINE__ |
|
1047 | + ); |
|
1048 | + } |
|
1049 | + } else { |
|
1050 | + EE_Error::add_error( |
|
1051 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1052 | + 'event_espresso'), |
|
1053 | + __FILE__, __FUNCTION__, __LINE__ |
|
1054 | + ); |
|
1055 | + } |
|
1056 | + return (bool)$queue_count; |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * debug |
|
1062 | + * |
|
1063 | + * @param string $class |
|
1064 | + * @param string $func |
|
1065 | + * @param string $line |
|
1066 | + * @param \EE_Transaction $transaction |
|
1067 | + * @param array $info |
|
1068 | + * @param bool $display_request |
|
1069 | + */ |
|
1070 | + protected static function log( |
|
1071 | + $class = '', |
|
1072 | + $func = '', |
|
1073 | + $line = '', |
|
1074 | + EE_Transaction $transaction, |
|
1075 | + $info = array(), |
|
1076 | + $display_request = false |
|
1077 | + ) { |
|
1078 | + if (WP_DEBUG && false) { |
|
1079 | + if ($transaction instanceof EE_Transaction) { |
|
1080 | + // don't serialize objects |
|
1081 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1082 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1083 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1084 | + if ($transaction->ID()) { |
|
1085 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1086 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1087 | + } |
|
1088 | + } |
|
1089 | + } |
|
1090 | + |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Resets all the static properties in this class when called. |
|
1096 | + */ |
|
1097 | + public static function reset() |
|
1098 | + { |
|
1099 | + self::$_EEMSG = null; |
|
1100 | + self::$_message_resource_manager = null; |
|
1101 | + self::$_MSG_PROCESSOR = null; |
|
1102 | + self::$_MSG_PATHS = null; |
|
1103 | + self::$_TMP_PACKS = array(); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | 1106 | } |
1107 | 1107 | // End of file EED_Messages.module.php |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param EE_Message_Resource_Manager $message_resource_manager |
37 | 37 | */ |
38 | - public function __construct( EE_Message_Resource_Manager $message_resource_manager ) { |
|
38 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager) { |
|
39 | 39 | $this->_message_resource_manager = $message_resource_manager; |
40 | 40 | $this->_init_queue_and_generator(); |
41 | 41 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * - $_generator = holds the messages generator |
51 | 51 | */ |
52 | 52 | protected function _init_queue_and_generator() { |
53 | - $this->_generator = EE_Registry::factory( 'EE_Messages_Generator' ); |
|
53 | + $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
54 | 54 | $this->_queue = $this->_generator->generation_queue(); |
55 | 55 | } |
56 | 56 | |
@@ -75,31 +75,31 @@ discard block |
||
75 | 75 | * @param EE_Messages_Queue $queue_to_process |
76 | 76 | * @return bool true for success false for error. |
77 | 77 | */ |
78 | - public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) { |
|
78 | + public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) { |
|
79 | 79 | $success = false; |
80 | 80 | $messages_to_send = array(); |
81 | 81 | $messages_to_generate = array(); |
82 | 82 | //loop through and setup the various messages from the queue so we know what is being processed |
83 | 83 | $queue_to_process->get_message_repository()->rewind(); |
84 | - foreach ( $queue_to_process->get_message_repository() as $message ) { |
|
85 | - if ( $message->STS_ID() === EEM_Message::status_incomplete ) { |
|
84 | + foreach ($queue_to_process->get_message_repository() as $message) { |
|
85 | + if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
86 | 86 | $messages_to_generate[] = $message; |
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) { |
|
90 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
91 | 91 | $messages_to_send[] = $message; |
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | //do generation/sends |
97 | - if ( $messages_to_generate ) { |
|
98 | - $success = $this->batch_generate_from_queue( $messages_to_generate, true ); |
|
97 | + if ($messages_to_generate) { |
|
98 | + $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( $messages_to_send ) { |
|
102 | - $sent = $this->batch_send_from_queue( $messages_to_send, true ); |
|
101 | + if ($messages_to_send) { |
|
102 | + $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
103 | 103 | //if there was messages to generate and it failed, then we override any success value for the sending process |
104 | 104 | //otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
105 | 105 | //Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
120 | 120 | * generated messages. |
121 | 121 | */ |
122 | - public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) { |
|
123 | - if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) { |
|
122 | + public function batch_generate_from_queue($messages = array(), $clear_queue = false) { |
|
123 | + if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
124 | 124 | $new_queue = $this->_generator->generate(); |
125 | - if ( $new_queue instanceof EE_Messages_Queue ) { |
|
125 | + if ($new_queue instanceof EE_Messages_Queue) { |
|
126 | 126 | //unlock queue |
127 | 127 | $this->_queue->unlock_queue(); |
128 | - $new_queue->initiate_request_by_priority( 'send' ); |
|
128 | + $new_queue->initiate_request_by_priority('send'); |
|
129 | 129 | return $new_queue; |
130 | 130 | } |
131 | 131 | } |
@@ -146,24 +146,24 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @return bool true means queue prepped, false means there was a lock so no generation please. |
148 | 148 | */ |
149 | - protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) { |
|
149 | + protected function _build_queue_for_generation($messages = array(), $clear_queue = false) { |
|
150 | 150 | |
151 | - if ( $clear_queue ) { |
|
151 | + if ($clear_queue) { |
|
152 | 152 | $this->_init_queue_and_generator(); |
153 | 153 | } |
154 | 154 | |
155 | - if ( $messages ) { |
|
155 | + if ($messages) { |
|
156 | 156 | //if generation is locked then get out now because that means processing is already happening. |
157 | - if ( $this->_queue->is_locked() ) { |
|
157 | + if ($this->_queue->is_locked()) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | 161 | $this->_queue->lock_queue(); |
162 | - $messages = is_array( $messages ) ? $messages : array( $messages ); |
|
163 | - foreach ( $messages as $message ) { |
|
164 | - if ( $message instanceof EE_Message ) { |
|
162 | + $messages = is_array($messages) ? $messages : array($messages); |
|
163 | + foreach ($messages as $message) { |
|
164 | + if ($message instanceof EE_Message) { |
|
165 | 165 | $data = $message->all_extra_meta_array(); |
166 | - $this->_queue->add( $message, $data ); |
|
166 | + $this->_queue->add($message, $data); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | return true; |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
183 | 183 | */ |
184 | - protected function _build_queue_for_sending( $messages, $clear_queue = false ) { |
|
184 | + protected function _build_queue_for_sending($messages, $clear_queue = false) { |
|
185 | 185 | //if sending is locked then get out now because that means processing is already happening. |
186 | - if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) { |
|
186 | + if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | |
190 | - $this->_queue->lock_queue( EE_Messages_Queue::action_sending ); |
|
190 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
191 | 191 | |
192 | - if ( $clear_queue ) { |
|
192 | + if ($clear_queue) { |
|
193 | 193 | $this->_init_queue_and_generator(); |
194 | 194 | } |
195 | 195 | |
196 | - $messages = is_array( $messages ) ? $messages : array( $messages ); |
|
196 | + $messages = is_array($messages) ? $messages : array($messages); |
|
197 | 197 | |
198 | - foreach ( $messages as $message ) { |
|
199 | - $this->_queue->add( $message ); |
|
198 | + foreach ($messages as $message) { |
|
199 | + $this->_queue->add($message); |
|
200 | 200 | } |
201 | 201 | return true; |
202 | 202 | } |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @return EE_Messages_Queue |
214 | 214 | */ |
215 | - public function batch_send_from_queue( $messages = array(), $clear_queue = false ) { |
|
215 | + public function batch_send_from_queue($messages = array(), $clear_queue = false) { |
|
216 | 216 | |
217 | - if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) { |
|
217 | + if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
218 | 218 | $this->_queue->execute(); |
219 | - $this->_queue->unlock_queue( EE_Messages_Queue::action_sending ); |
|
219 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
220 | 220 | } else { |
221 | 221 | //get messages to send and execute. |
222 | 222 | $this->_queue->get_to_send_batch_and_send(); |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * @param EE_Message_To_Generate[] $messages_to_generate |
240 | 240 | * @return EE_Messages_Queue |
241 | 241 | */ |
242 | - public function generate_and_return( $messages_to_generate ) { |
|
242 | + public function generate_and_return($messages_to_generate) { |
|
243 | 243 | $this->_init_queue_and_generator(); |
244 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
245 | - return $this->_generator->generate( false ); |
|
244 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
245 | + return $this->_generator->generate(false); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
254 | 254 | * @return EE_Messages_Queue |
255 | 255 | */ |
256 | - public function generate_queue( $persist = true ) { |
|
257 | - return $this->_generator->generate( $persist ); |
|
256 | + public function generate_queue($persist = true) { |
|
257 | + return $this->_generator->generate($persist); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | * @param bool $test_send Whether this item is for a test send or not. |
268 | 268 | * @return EE_Messages_Queue |
269 | 269 | */ |
270 | - public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) { |
|
271 | - if ( $message_to_generate->valid() ) { |
|
272 | - $this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send ); |
|
270 | + public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) { |
|
271 | + if ($message_to_generate->valid()) { |
|
272 | + $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @param EE_Message_To_Generate[] $messages_to_generate |
287 | 287 | */ |
288 | - public function batch_queue_for_generation_and_persist( $messages_to_generate ) { |
|
288 | + public function batch_queue_for_generation_and_persist($messages_to_generate) { |
|
289 | 289 | $this->_init_queue_and_generator(); |
290 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
290 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
291 | 291 | $this->_queue->save(); |
292 | 292 | } |
293 | 293 | |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param EE_Message_To_Generate[] $messages_to_generate |
305 | 305 | */ |
306 | - public function batch_queue_for_generation_no_persist( $messages_to_generate ) { |
|
306 | + public function batch_queue_for_generation_no_persist($messages_to_generate) { |
|
307 | 307 | $this->_init_queue_and_generator(); |
308 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
308 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -317,15 +317,15 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @param EE_Message_To_Generate[] $messages_to_generate |
319 | 319 | */ |
320 | - protected function _queue_for_generation_loop( $messages_to_generate ) { |
|
320 | + protected function _queue_for_generation_loop($messages_to_generate) { |
|
321 | 321 | //make sure is in an array. |
322 | - if ( ! is_array( $messages_to_generate ) ) { |
|
323 | - $messages_to_generate = array( $messages_to_generate ); |
|
322 | + if ( ! is_array($messages_to_generate)) { |
|
323 | + $messages_to_generate = array($messages_to_generate); |
|
324 | 324 | } |
325 | 325 | |
326 | - foreach ( $messages_to_generate as $message_to_generate ) { |
|
327 | - if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) { |
|
328 | - $this->queue_for_generation( $message_to_generate ); |
|
326 | + foreach ($messages_to_generate as $message_to_generate) { |
|
327 | + if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
328 | + $this->queue_for_generation($message_to_generate); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | } |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * @param EE_Message_To_Generate[] |
341 | 341 | * @return EE_Messages_Queue |
342 | 342 | */ |
343 | - public function generate_and_queue_for_sending( $messages_to_generate ) { |
|
343 | + public function generate_and_queue_for_sending($messages_to_generate) { |
|
344 | 344 | $this->_init_queue_and_generator(); |
345 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
346 | - return $this->_generator->generate( true ); |
|
345 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
346 | + return $this->_generator->generate(true); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param bool $test_send Whether this is a test send or not. |
358 | 358 | * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
359 | 359 | */ |
360 | - public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) { |
|
361 | - if ( ! $message_to_generate->valid() ) { |
|
360 | + public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) { |
|
361 | + if ( ! $message_to_generate->valid()) { |
|
362 | 362 | EE_Error::add_error( |
363 | - __( 'Unable to generate preview because of invalid data', 'event_espresso' ), |
|
363 | + __('Unable to generate preview because of invalid data', 'event_espresso'), |
|
364 | 364 | __FILE__, |
365 | 365 | __FUNCTION__, |
366 | 366 | __LINE__ |
@@ -368,14 +368,14 @@ discard block |
||
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | //just make sure preview is set on the $message_to_generate (in case client forgot) |
371 | - $message_to_generate->set_preview( true ); |
|
371 | + $message_to_generate->set_preview(true); |
|
372 | 372 | $this->_init_queue_and_generator(); |
373 | - $this->queue_for_generation( $message_to_generate, $test_send ); |
|
374 | - $generated_queue = $this->_generator->generate( false ); |
|
375 | - if ( $generated_queue->execute( false ) ) { |
|
373 | + $this->queue_for_generation($message_to_generate, $test_send); |
|
374 | + $generated_queue = $this->_generator->generate(false); |
|
375 | + if ($generated_queue->execute(false)) { |
|
376 | 376 | //the first queue item should be the preview |
377 | 377 | $generated_queue->get_message_repository()->rewind(); |
378 | - if ( ! $generated_queue->get_message_repository()->valid() ) { |
|
378 | + if ( ! $generated_queue->get_message_repository()->valid()) { |
|
379 | 379 | return $generated_queue; |
380 | 380 | } |
381 | 381 | return $generated_queue; |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param EE_Message_To_Generate $message_to_generate |
393 | 393 | * @return bool true or false for success. |
394 | 394 | */ |
395 | - public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) { |
|
396 | - if ( ! $message_to_generate->valid() ) { |
|
395 | + public function queue_for_sending(EE_Message_To_Generate $message_to_generate) { |
|
396 | + if ( ! $message_to_generate->valid()) { |
|
397 | 397 | return false; |
398 | 398 | } |
399 | 399 | $this->_init_queue_and_generator(); |
400 | 400 | $message = $message_to_generate->get_EE_Message(); |
401 | - $this->_queue->add( $message ); |
|
402 | - if ( $message->send_now() ) { |
|
403 | - $this->_queue->execute( false ); |
|
401 | + $this->_queue->add($message); |
|
402 | + if ($message->send_now()) { |
|
403 | + $this->_queue->execute(false); |
|
404 | 404 | } else { |
405 | 405 | $this->_queue->save(); |
406 | 406 | } |
@@ -413,12 +413,12 @@ discard block |
||
413 | 413 | * @param EE_Message_To_Generate $message_to_generate |
414 | 414 | * @return EE_Messages_Queue | null |
415 | 415 | */ |
416 | - public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) { |
|
417 | - if ( ! $message_to_generate->valid() ) { |
|
416 | + public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) { |
|
417 | + if ( ! $message_to_generate->valid()) { |
|
418 | 418 | return null; |
419 | 419 | } |
420 | 420 | // is there supposed to be a sending messenger for this message? |
421 | - if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) { |
|
421 | + if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
422 | 422 | // make sure it's valid, but if it's not, |
423 | 423 | // then set the value of $sending_messenger to an EE_Error object |
424 | 424 | // so that downstream code can easily see that things went wrong. |
@@ -434,14 +434,14 @@ discard block |
||
434 | 434 | $sending_messenger = null; |
435 | 435 | } |
436 | 436 | |
437 | - if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) { |
|
437 | + if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
438 | 438 | $this->_init_queue_and_generator(); |
439 | - $this->_queue->add( $message_to_generate->get_EE_Message() ); |
|
440 | - $this->_queue->execute( false, $sending_messenger ); |
|
439 | + $this->_queue->add($message_to_generate->get_EE_Message()); |
|
440 | + $this->_queue->execute(false, $sending_messenger); |
|
441 | 441 | return $this->_queue; |
442 | - } elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) { |
|
443 | - $generated_queue = $this->generate_and_return( array( $message_to_generate ) ); |
|
444 | - $generated_queue->execute( false, $sending_messenger ); |
|
442 | + } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
443 | + $generated_queue = $this->generate_and_return(array($message_to_generate)); |
|
444 | + $generated_queue->execute(false, $sending_messenger); |
|
445 | 445 | return $generated_queue; |
446 | 446 | } |
447 | 447 | return null; |
@@ -458,13 +458,13 @@ discard block |
||
458 | 458 | * @param mixed $data The data being used for generation. |
459 | 459 | * @param bool $persist Whether to persist the queued messages to the db or not. |
460 | 460 | */ |
461 | - public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) { |
|
462 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data ); |
|
463 | - if ( $persist ) { |
|
464 | - $this->batch_queue_for_generation_and_persist( $messages_to_generate ); |
|
461 | + public function generate_for_all_active_messengers($message_type, $data, $persist = true) { |
|
462 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
463 | + if ($persist) { |
|
464 | + $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
465 | 465 | $this->_queue->initiate_request_by_priority(); |
466 | 466 | } else { |
467 | - $this->batch_queue_for_generation_no_persist( $messages_to_generate ); |
|
467 | + $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
@@ -479,11 +479,11 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return EE_Message_To_Generate[] |
481 | 481 | */ |
482 | - public function setup_mtgs_for_all_active_messengers( $message_type, $data ) { |
|
482 | + public function setup_mtgs_for_all_active_messengers($message_type, $data) { |
|
483 | 483 | $messages_to_generate = array(); |
484 | - foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object ) { |
|
485 | - $message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data ); |
|
486 | - if ( $message_to_generate->valid() ) { |
|
484 | + foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
485 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
486 | + if ($message_to_generate->valid()) { |
|
487 | 487 | $messages_to_generate[] = $message_to_generate; |
488 | 488 | } |
489 | 489 | } |
@@ -498,29 +498,29 @@ discard block |
||
498 | 498 | * and send. |
499 | 499 | * @param array $message_ids |
500 | 500 | */ |
501 | - public function setup_messages_from_ids_and_send( $message_ids ) { |
|
501 | + public function setup_messages_from_ids_and_send($message_ids) { |
|
502 | 502 | $this->_init_queue_and_generator(); |
503 | - $messages = EEM_Message::instance()->get_all( array( |
|
503 | + $messages = EEM_Message::instance()->get_all(array( |
|
504 | 504 | array( |
505 | - 'MSG_ID' => array( 'IN', $message_ids ), |
|
505 | + 'MSG_ID' => array('IN', $message_ids), |
|
506 | 506 | 'STS_ID' => array( |
507 | 507 | 'IN', |
508 | 508 | array_merge( |
509 | 509 | EEM_Message::instance()->stati_indicating_sent(), |
510 | - array( EEM_Message::status_retry ) |
|
510 | + array(EEM_Message::status_retry) |
|
511 | 511 | ), |
512 | 512 | ), |
513 | 513 | ), |
514 | 514 | )); |
515 | 515 | //set the Messages to resend. |
516 | - foreach ( $messages as $message ) { |
|
517 | - if ( $message instanceof EE_Message ) { |
|
518 | - $message->set_STS_ID( EEM_Message::status_resend ); |
|
519 | - $this->_queue->add( $message ); |
|
516 | + foreach ($messages as $message) { |
|
517 | + if ($message instanceof EE_Message) { |
|
518 | + $message->set_STS_ID(EEM_Message::status_resend); |
|
519 | + $this->_queue->add($message); |
|
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - $this->_queue->initiate_request_by_priority( 'send' ); |
|
523 | + $this->_queue->initiate_request_by_priority('send'); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | |
@@ -534,23 +534,23 @@ discard block |
||
534 | 534 | * |
535 | 535 | * @return EE_Message_To_Generate[] |
536 | 536 | */ |
537 | - public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) { |
|
538 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
539 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
537 | + public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') { |
|
538 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
539 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
540 | 540 | $regs_to_send = array(); |
541 | - $regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key ); |
|
542 | - if ( empty( $regIDs ) ) { |
|
543 | - EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
541 | + $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key); |
|
542 | + if (empty($regIDs)) { |
|
543 | + EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
544 | 544 | return false; |
545 | 545 | } |
546 | 546 | |
547 | 547 | //make sure is an array |
548 | - $regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs ); |
|
548 | + $regIDs = is_array($regIDs) ? $regIDs : array($regIDs); |
|
549 | 549 | |
550 | - foreach( $regIDs as $regID ) { |
|
551 | - $reg = EEM_Registration::instance()->get_one_by_ID( $regID ); |
|
552 | - if ( ! $reg instanceof EE_Registration ) { |
|
553 | - EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) ); |
|
550 | + foreach ($regIDs as $regID) { |
|
551 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
552 | + if ( ! $reg instanceof EE_Registration) { |
|
553 | + EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg; |
@@ -558,13 +558,13 @@ discard block |
||
558 | 558 | |
559 | 559 | $messages_to_generate = array(); |
560 | 560 | |
561 | - foreach ( $regs_to_send as $status_group ) { |
|
562 | - foreach ( $status_group as $status_id => $registrations ) { |
|
561 | + foreach ($regs_to_send as $status_group) { |
|
562 | + foreach ($status_group as $status_id => $registrations) { |
|
563 | 563 | $messages_to_generate = array_merge( |
564 | 564 | $messages_to_generate, |
565 | 565 | $this->setup_mtgs_for_all_active_messengers( |
566 | - EEH_MSG_Template::convert_reg_status_to_message_type( $status_id ), |
|
567 | - array( $registrations, $status_id ) |
|
566 | + EEH_MSG_Template::convert_reg_status_to_message_type($status_id), |
|
567 | + array($registrations, $status_id) |
|
568 | 568 | ) |
569 | 569 | ); |
570 | 570 | } |