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