@@ -11,12 +11,12 @@ |
||
11 | 11 | */ |
12 | 12 | interface LocatorInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * given a string or an array of information for where to look, |
|
16 | - * will find all files in that location |
|
17 | - * |
|
18 | - * @param array|string $location |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function locate($location): array; |
|
14 | + /** |
|
15 | + * given a string or an array of information for where to look, |
|
16 | + * will find all files in that location |
|
17 | + * |
|
18 | + * @param array|string $location |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function locate($location): array; |
|
22 | 22 | } |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | */ |
35 | 35 | protected function setNamespace(?string $namespace, ?string $namespace_base_dir) |
36 | 36 | { |
37 | - if (! is_string($namespace)) { |
|
37 | + if ( ! is_string($namespace)) { |
|
38 | 38 | throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
39 | 39 | } |
40 | - if (! is_string($namespace_base_dir)) { |
|
40 | + if ( ! is_string($namespace_base_dir)) { |
|
41 | 41 | throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
42 | 42 | } |
43 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
43 | + $this->namespaces[$namespace] = $namespace_base_dir; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function locate($namespaces): array |
74 | 74 | { |
75 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
75 | + if ( ! (is_string($namespaces) || is_array($namespaces))) { |
|
76 | 76 | throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
77 | 77 | } |
78 | 78 | foreach ((array) $namespaces as $namespace) { |
79 | 79 | foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
80 | - $this->FQCNs[ $key ] = $file; |
|
80 | + $this->FQCNs[$key] = $file; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | return $this->FQCNs; |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | } |
107 | 107 | foreach ($iterator as $file) { |
108 | 108 | if ($file->isFile() && $file->getExtension() === 'php') { |
109 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
109 | + $file = $file->getPath().'/'.$file->getBasename('.php'); |
|
110 | 110 | foreach ($this->namespaces as $namespace => $base_dir) { |
111 | 111 | $namespace .= Psr4Autoloader::NS; |
112 | 112 | if (strpos($file, $base_dir) === 0) { |
113 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
113 | + $this->FQCNs[] = Psr4Autoloader::NS.str_replace( |
|
114 | 114 | [$base_dir, '/'], |
115 | 115 | [$namespace, Psr4Autoloader::NS], |
116 | 116 | $file |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | // we're only interested in the Vendor and secondary base, so pull those from the array |
144 | 144 | $vendor_base = array_slice($namespace_segments, 0, 2); |
145 | 145 | $namespace = $prefix = null; |
146 | - while (! empty($vendor_base)) { |
|
146 | + while ( ! empty($vendor_base)) { |
|
147 | 147 | $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
148 | 148 | // check if there's a base directory registered for that namespace |
149 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
150 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
149 | + $prefix = $psr4_loader->prefixes($namespace.Psr4Autoloader::NS); |
|
150 | + if ( ! empty($prefix) && ! empty($prefix[0])) { |
|
151 | 151 | // found one! |
152 | 152 | break; |
153 | 153 | } |
@@ -160,6 +160,6 @@ discard block |
||
160 | 160 | } |
161 | 161 | $this->setNamespace($namespace, $prefix[0]); |
162 | 162 | // but if it's good, add that base directory to the rest of the path, and return it |
163 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
163 | + return $prefix[0].implode('/', array_diff($namespace_segments, $vendor_base)).'/'; |
|
164 | 164 | } |
165 | 165 | } |
@@ -18,146 +18,146 @@ |
||
18 | 18 | */ |
19 | 19 | class FqcnLocator extends Locator |
20 | 20 | { |
21 | - protected array $FQCNs = []; |
|
22 | - |
|
23 | - protected array $namespaces = []; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string|null $namespace |
|
28 | - * @param string|null $namespace_base_dir |
|
29 | - */ |
|
30 | - protected function setNamespace(?string $namespace, ?string $namespace_base_dir) |
|
31 | - { |
|
32 | - if (! is_string($namespace)) { |
|
33 | - throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
34 | - } |
|
35 | - if (! is_string($namespace_base_dir)) { |
|
36 | - throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
37 | - } |
|
38 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function getFQCNs(): array |
|
46 | - { |
|
47 | - return $this->FQCNs; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @return int |
|
53 | - */ |
|
54 | - public function count(): int |
|
55 | - { |
|
56 | - return count($this->FQCNs); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * given a valid namespace, will find all files that match the provided mask |
|
62 | - * |
|
63 | - * @param string|array $namespaces |
|
64 | - * @return array |
|
65 | - * @throws InvalidClassException |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - * @throws EE_Error |
|
68 | - */ |
|
69 | - public function locate($namespaces): array |
|
70 | - { |
|
71 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
72 | - throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
73 | - } |
|
74 | - foreach ((array) $namespaces as $namespace) { |
|
75 | - foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
76 | - $this->FQCNs[ $key ] = $file; |
|
77 | - } |
|
78 | - } |
|
79 | - return $this->FQCNs; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * given a partial namespace, will find all files in that folder |
|
85 | - * ** PLZ NOTE ** |
|
86 | - * This assumes that all files within the specified folder should be loaded |
|
87 | - * |
|
88 | - * @param string $partial_namespace |
|
89 | - * @return array |
|
90 | - * @throws InvalidClassException |
|
91 | - * @throws InvalidDataTypeException |
|
92 | - * @throws EE_Error |
|
93 | - */ |
|
94 | - protected function findFQCNsByNamespace(string $partial_namespace): array |
|
95 | - { |
|
96 | - $iterator = new FilesystemIterator( |
|
97 | - $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
98 | - ); |
|
99 | - $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
100 | - $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
101 | - if (iterator_count($iterator) === 0) { |
|
102 | - return []; |
|
103 | - } |
|
104 | - foreach ($iterator as $file) { |
|
105 | - if ($file->isFile() && $file->getExtension() === 'php') { |
|
106 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
107 | - foreach ($this->namespaces as $namespace => $base_dir) { |
|
108 | - $namespace .= Psr4Autoloader::NS; |
|
109 | - if (strpos($file, $base_dir) === 0) { |
|
110 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
111 | - [$base_dir, '/'], |
|
112 | - [$namespace, Psr4Autoloader::NS], |
|
113 | - $file |
|
114 | - ); |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - return $this->FQCNs; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * getDirectoryFromPartialNamespace |
|
125 | - * |
|
126 | - * @param string $partial_namespace almost fully qualified class name ? |
|
127 | - * @return string |
|
128 | - * @throws InvalidDataTypeException |
|
129 | - * @throws InvalidClassException |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - protected function getDirectoryFromPartialNamespace(string $partial_namespace): string |
|
133 | - { |
|
134 | - if (empty($partial_namespace)) { |
|
135 | - throw new InvalidClassException($partial_namespace); |
|
136 | - } |
|
137 | - // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
138 | - $psr4_loader = EE_Psr4AutoloaderInit::psr4_loader(); |
|
139 | - // breakup the incoming namespace into segments so we can loop thru them |
|
140 | - $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
141 | - // we're only interested in the Vendor and secondary base, so pull those from the array |
|
142 | - $vendor_base = array_slice($namespace_segments, 0, 2); |
|
143 | - $namespace = $prefix = null; |
|
144 | - while (! empty($vendor_base)) { |
|
145 | - $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
146 | - // check if there's a base directory registered for that namespace |
|
147 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
148 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
149 | - // found one! |
|
150 | - break; |
|
151 | - } |
|
152 | - // remove base and try vendor only portion of namespace |
|
153 | - array_pop($vendor_base); |
|
154 | - } |
|
155 | - // nope? then the incoming namespace is invalid |
|
156 | - if (empty($prefix) || empty($prefix[0])) { |
|
157 | - throw new InvalidClassException($partial_namespace); |
|
158 | - } |
|
159 | - $this->setNamespace($namespace, $prefix[0]); |
|
160 | - // but if it's good, add that base directory to the rest of the path, and return it |
|
161 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
162 | - } |
|
21 | + protected array $FQCNs = []; |
|
22 | + |
|
23 | + protected array $namespaces = []; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string|null $namespace |
|
28 | + * @param string|null $namespace_base_dir |
|
29 | + */ |
|
30 | + protected function setNamespace(?string $namespace, ?string $namespace_base_dir) |
|
31 | + { |
|
32 | + if (! is_string($namespace)) { |
|
33 | + throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
34 | + } |
|
35 | + if (! is_string($namespace_base_dir)) { |
|
36 | + throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
37 | + } |
|
38 | + $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function getFQCNs(): array |
|
46 | + { |
|
47 | + return $this->FQCNs; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @return int |
|
53 | + */ |
|
54 | + public function count(): int |
|
55 | + { |
|
56 | + return count($this->FQCNs); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * given a valid namespace, will find all files that match the provided mask |
|
62 | + * |
|
63 | + * @param string|array $namespaces |
|
64 | + * @return array |
|
65 | + * @throws InvalidClassException |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + * @throws EE_Error |
|
68 | + */ |
|
69 | + public function locate($namespaces): array |
|
70 | + { |
|
71 | + if (! (is_string($namespaces) || is_array($namespaces))) { |
|
72 | + throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
73 | + } |
|
74 | + foreach ((array) $namespaces as $namespace) { |
|
75 | + foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
76 | + $this->FQCNs[ $key ] = $file; |
|
77 | + } |
|
78 | + } |
|
79 | + return $this->FQCNs; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * given a partial namespace, will find all files in that folder |
|
85 | + * ** PLZ NOTE ** |
|
86 | + * This assumes that all files within the specified folder should be loaded |
|
87 | + * |
|
88 | + * @param string $partial_namespace |
|
89 | + * @return array |
|
90 | + * @throws InvalidClassException |
|
91 | + * @throws InvalidDataTypeException |
|
92 | + * @throws EE_Error |
|
93 | + */ |
|
94 | + protected function findFQCNsByNamespace(string $partial_namespace): array |
|
95 | + { |
|
96 | + $iterator = new FilesystemIterator( |
|
97 | + $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
98 | + ); |
|
99 | + $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
100 | + $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
101 | + if (iterator_count($iterator) === 0) { |
|
102 | + return []; |
|
103 | + } |
|
104 | + foreach ($iterator as $file) { |
|
105 | + if ($file->isFile() && $file->getExtension() === 'php') { |
|
106 | + $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
107 | + foreach ($this->namespaces as $namespace => $base_dir) { |
|
108 | + $namespace .= Psr4Autoloader::NS; |
|
109 | + if (strpos($file, $base_dir) === 0) { |
|
110 | + $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
111 | + [$base_dir, '/'], |
|
112 | + [$namespace, Psr4Autoloader::NS], |
|
113 | + $file |
|
114 | + ); |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + return $this->FQCNs; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * getDirectoryFromPartialNamespace |
|
125 | + * |
|
126 | + * @param string $partial_namespace almost fully qualified class name ? |
|
127 | + * @return string |
|
128 | + * @throws InvalidDataTypeException |
|
129 | + * @throws InvalidClassException |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + protected function getDirectoryFromPartialNamespace(string $partial_namespace): string |
|
133 | + { |
|
134 | + if (empty($partial_namespace)) { |
|
135 | + throw new InvalidClassException($partial_namespace); |
|
136 | + } |
|
137 | + // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
138 | + $psr4_loader = EE_Psr4AutoloaderInit::psr4_loader(); |
|
139 | + // breakup the incoming namespace into segments so we can loop thru them |
|
140 | + $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
141 | + // we're only interested in the Vendor and secondary base, so pull those from the array |
|
142 | + $vendor_base = array_slice($namespace_segments, 0, 2); |
|
143 | + $namespace = $prefix = null; |
|
144 | + while (! empty($vendor_base)) { |
|
145 | + $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
146 | + // check if there's a base directory registered for that namespace |
|
147 | + $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
148 | + if (! empty($prefix) && ! empty($prefix[0])) { |
|
149 | + // found one! |
|
150 | + break; |
|
151 | + } |
|
152 | + // remove base and try vendor only portion of namespace |
|
153 | + array_pop($vendor_base); |
|
154 | + } |
|
155 | + // nope? then the incoming namespace is invalid |
|
156 | + if (empty($prefix) || empty($prefix[0])) { |
|
157 | + throw new InvalidClassException($partial_namespace); |
|
158 | + } |
|
159 | + $this->setNamespace($namespace, $prefix[0]); |
|
160 | + // but if it's good, add that base directory to the rest of the path, and return it |
|
161 | + return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
162 | + } |
|
163 | 163 | } |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Registration_Form_Tips extends EE_Qtip_Config |
15 | 15 | { |
16 | - protected function _set_tips_array() |
|
17 | - { |
|
18 | - $this->_qtipsa = array( |
|
19 | - 0 => array( |
|
20 | - 'content_id' => 'about-system-lock-icon', |
|
21 | - 'target' => '.questions .ee-system-lock', |
|
22 | - 'content' => esc_html__('This question is a system question and cannot be trashed', 'event_espresso'), |
|
23 | - 'options' => array(), // defaults |
|
24 | - ), |
|
25 | - 1 => array( |
|
26 | - 'content_id' => 'about-non-system-lock-icon', |
|
27 | - 'target' => '.questions .ee-alternate-color', |
|
28 | - 'content' => esc_html__( |
|
29 | - 'This question has answers attached to it from registrations that have the question. It cannot be permanently deleted.', |
|
30 | - 'event_espresso' |
|
31 | - ), |
|
32 | - 'options' => array(), |
|
33 | - ), |
|
34 | - 2 => array( |
|
35 | - 'content_id' => 'about-question-group-lock-icon', |
|
36 | - 'target' => '.questiongroups .ee-system-lock', |
|
37 | - 'content' => esc_html__('This question group is a system group and cannot be trashed', 'event_espresso'), |
|
38 | - 'options' => array(), |
|
39 | - ), |
|
40 | - 3 => array( |
|
41 | - 'content_id' => 'about-non-system-qg-lock-icon', |
|
42 | - 'target' => '.questiongroups .ee-alternate-color', |
|
43 | - 'content' => esc_html__( |
|
44 | - 'This question group has questions that have answers attached to it from registrations that have the question. It cannot be permanently deleted.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - 'options' => array(), |
|
48 | - ), |
|
49 | - ); |
|
50 | - } |
|
16 | + protected function _set_tips_array() |
|
17 | + { |
|
18 | + $this->_qtipsa = array( |
|
19 | + 0 => array( |
|
20 | + 'content_id' => 'about-system-lock-icon', |
|
21 | + 'target' => '.questions .ee-system-lock', |
|
22 | + 'content' => esc_html__('This question is a system question and cannot be trashed', 'event_espresso'), |
|
23 | + 'options' => array(), // defaults |
|
24 | + ), |
|
25 | + 1 => array( |
|
26 | + 'content_id' => 'about-non-system-lock-icon', |
|
27 | + 'target' => '.questions .ee-alternate-color', |
|
28 | + 'content' => esc_html__( |
|
29 | + 'This question has answers attached to it from registrations that have the question. It cannot be permanently deleted.', |
|
30 | + 'event_espresso' |
|
31 | + ), |
|
32 | + 'options' => array(), |
|
33 | + ), |
|
34 | + 2 => array( |
|
35 | + 'content_id' => 'about-question-group-lock-icon', |
|
36 | + 'target' => '.questiongroups .ee-system-lock', |
|
37 | + 'content' => esc_html__('This question group is a system group and cannot be trashed', 'event_espresso'), |
|
38 | + 'options' => array(), |
|
39 | + ), |
|
40 | + 3 => array( |
|
41 | + 'content_id' => 'about-non-system-qg-lock-icon', |
|
42 | + 'target' => '.questiongroups .ee-alternate-color', |
|
43 | + 'content' => esc_html__( |
|
44 | + 'This question group has questions that have answers attached to it from registrations that have the question. It cannot be permanently deleted.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + 'options' => array(), |
|
48 | + ), |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
@@ -13,69 +13,69 @@ |
||
13 | 13 | */ |
14 | 14 | class Transactions_List_Table_Tips extends EE_Qtip_Config |
15 | 15 | { |
16 | - protected function _set_tips_array() |
|
17 | - { |
|
18 | - $this->_qtipsa = array( |
|
19 | - // 0 => array( |
|
20 | - // 'content_id' => 'transaction-status-' . EEM_Transaction::overpaid_status_code, |
|
21 | - // 'target' => '.txn-status-' . EEM_Transaction::overpaid_status_code, |
|
22 | - // 'content' => $this->_transaction_status_legend(EEM_Transaction::overpaid_status_code), |
|
23 | - // 'options' => array( |
|
24 | - // 'position' => array( |
|
25 | - // 'target' => 'mouse', |
|
26 | - // ), |
|
27 | - // ), |
|
28 | - // ), |
|
29 | - // 1 => array( |
|
30 | - // 'content_id' => 'transaction-status-' . EEM_Transaction::complete_status_code, |
|
31 | - // 'target' => '.txn-status-' . EEM_Transaction::complete_status_code, |
|
32 | - // 'content' => $this->_transaction_status_legend(EEM_Transaction::complete_status_code), |
|
33 | - // 'options' => array( |
|
34 | - // 'position' => array( |
|
35 | - // 'target' => 'mouse', |
|
36 | - // ), |
|
37 | - // ), |
|
38 | - // ), |
|
39 | - // 2 => array( |
|
40 | - // 'content_id' => 'transaction-status-' . EEM_Transaction::incomplete_status_code, |
|
41 | - // 'target' => '.txn-status-' . EEM_Transaction::incomplete_status_code, |
|
42 | - // 'content' => $this->_transaction_status_legend(EEM_Transaction::incomplete_status_code), |
|
43 | - // 'options' => array( |
|
44 | - // 'position' => array( |
|
45 | - // 'target' => 'mouse', |
|
46 | - // ), |
|
47 | - // ), |
|
48 | - // ), |
|
49 | - // 3 => array( |
|
50 | - // 'content_id' => 'transaction-status-' . EEM_Transaction::failed_status_code, |
|
51 | - // 'target' => '.txn-status-' . EEM_Transaction::failed_status_code, |
|
52 | - // 'content' => $this->_transaction_status_legend(EEM_Transaction::failed_status_code), |
|
53 | - // 'options' => array( |
|
54 | - // 'position' => array( |
|
55 | - // 'target' => 'mouse', |
|
56 | - // ), |
|
57 | - // ), |
|
58 | - // ) |
|
59 | - ); |
|
60 | - } |
|
16 | + protected function _set_tips_array() |
|
17 | + { |
|
18 | + $this->_qtipsa = array( |
|
19 | + // 0 => array( |
|
20 | + // 'content_id' => 'transaction-status-' . EEM_Transaction::overpaid_status_code, |
|
21 | + // 'target' => '.txn-status-' . EEM_Transaction::overpaid_status_code, |
|
22 | + // 'content' => $this->_transaction_status_legend(EEM_Transaction::overpaid_status_code), |
|
23 | + // 'options' => array( |
|
24 | + // 'position' => array( |
|
25 | + // 'target' => 'mouse', |
|
26 | + // ), |
|
27 | + // ), |
|
28 | + // ), |
|
29 | + // 1 => array( |
|
30 | + // 'content_id' => 'transaction-status-' . EEM_Transaction::complete_status_code, |
|
31 | + // 'target' => '.txn-status-' . EEM_Transaction::complete_status_code, |
|
32 | + // 'content' => $this->_transaction_status_legend(EEM_Transaction::complete_status_code), |
|
33 | + // 'options' => array( |
|
34 | + // 'position' => array( |
|
35 | + // 'target' => 'mouse', |
|
36 | + // ), |
|
37 | + // ), |
|
38 | + // ), |
|
39 | + // 2 => array( |
|
40 | + // 'content_id' => 'transaction-status-' . EEM_Transaction::incomplete_status_code, |
|
41 | + // 'target' => '.txn-status-' . EEM_Transaction::incomplete_status_code, |
|
42 | + // 'content' => $this->_transaction_status_legend(EEM_Transaction::incomplete_status_code), |
|
43 | + // 'options' => array( |
|
44 | + // 'position' => array( |
|
45 | + // 'target' => 'mouse', |
|
46 | + // ), |
|
47 | + // ), |
|
48 | + // ), |
|
49 | + // 3 => array( |
|
50 | + // 'content_id' => 'transaction-status-' . EEM_Transaction::failed_status_code, |
|
51 | + // 'target' => '.txn-status-' . EEM_Transaction::failed_status_code, |
|
52 | + // 'content' => $this->_transaction_status_legend(EEM_Transaction::failed_status_code), |
|
53 | + // 'options' => array( |
|
54 | + // 'position' => array( |
|
55 | + // 'target' => 'mouse', |
|
56 | + // ), |
|
57 | + // ), |
|
58 | + // ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * output the relevant ee-status-legend with the designated status highlighted. |
|
65 | - * |
|
66 | - * @param EEM_Transaction constant $status What status is set (by class) |
|
67 | - * @return string The status legend with the related status highlighted |
|
68 | - */ |
|
69 | - private function _transaction_status_legend($status) |
|
70 | - { |
|
63 | + /** |
|
64 | + * output the relevant ee-status-legend with the designated status highlighted. |
|
65 | + * |
|
66 | + * @param EEM_Transaction constant $status What status is set (by class) |
|
67 | + * @return string The status legend with the related status highlighted |
|
68 | + */ |
|
69 | + private function _transaction_status_legend($status) |
|
70 | + { |
|
71 | 71 | |
72 | - $status_array = array( |
|
73 | - 'overpaid' => EEM_Transaction::overpaid_status_code, |
|
74 | - 'complete' => EEM_Transaction::complete_status_code, |
|
75 | - 'incomplete' => EEM_Transaction::incomplete_status_code, |
|
76 | - 'failed' => EEM_Transaction::failed_status_code, |
|
77 | - ); |
|
72 | + $status_array = array( |
|
73 | + 'overpaid' => EEM_Transaction::overpaid_status_code, |
|
74 | + 'complete' => EEM_Transaction::complete_status_code, |
|
75 | + 'incomplete' => EEM_Transaction::incomplete_status_code, |
|
76 | + 'failed' => EEM_Transaction::failed_status_code, |
|
77 | + ); |
|
78 | 78 | |
79 | - return EEH_Template::status_legend($status_array, $status); |
|
80 | - } |
|
79 | + return EEH_Template::status_legend($status_array, $status); |
|
80 | + } |
|
81 | 81 | } |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
110 | 110 | // the incoming template pack reference. |
111 | 111 | $class_name = |
112 | - 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
112 | + 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
113 | 113 | |
114 | - if (! class_exists($class_name)) { |
|
114 | + if ( ! class_exists($class_name)) { |
|
115 | 115 | EE_Error::add_error( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | $template_pack = 'default'; |
158 | 158 | // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
159 | - if (! empty($this->_GRP_ID)) { |
|
159 | + if ( ! empty($this->_GRP_ID)) { |
|
160 | 160 | $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
161 | 161 | $template_pack = $message_template_group instanceof EE_Message_Template_Group |
162 | 162 | ? $message_template_group->get_template_pack_name() |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | if ($field != 'extra') { |
208 | 208 | $template_data['MTP_context'] = $context; |
209 | 209 | $template_data['MTP_template_field'] = $field; |
210 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
210 | + $template_data['MTP_content'] = $this->_templates[$context][$field]; |
|
211 | 211 | |
212 | 212 | $MTP = $this->_message_template_model->insert($template_data); |
213 | - if (! $MTP) { |
|
213 | + if ( ! $MTP) { |
|
214 | 214 | EE_Error::add_error( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -11,231 +11,231 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Messages_Template_Defaults extends EE_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Used for holding the EE_Message_Template GRP_ID field value. |
|
16 | - * |
|
17 | - * @var [type] |
|
18 | - */ |
|
19 | - protected $_GRP_ID; |
|
20 | - |
|
21 | - /** |
|
22 | - * holds the messenger object |
|
23 | - * |
|
24 | - * @var EE_messenger |
|
25 | - */ |
|
26 | - protected $_messenger; |
|
27 | - |
|
28 | - /** |
|
29 | - * holds the message type object |
|
30 | - * |
|
31 | - * @var EE_message_type |
|
32 | - */ |
|
33 | - protected $_message_type; |
|
34 | - |
|
35 | - /** |
|
36 | - * holds the fields used (this is retrieved from the messenger) |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $_fields; |
|
41 | - |
|
42 | - /** |
|
43 | - * holds the assembled template (with defaults) for creation in the database |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $_templates; |
|
48 | - |
|
49 | - /** |
|
50 | - * holds the contexts used (this is retrieved from the message type) |
|
51 | - * |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $_contexts; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EEM_Message_Template_Group |
|
59 | - */ |
|
60 | - protected $_message_template_group_model; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @var EEM_Message_Template |
|
65 | - */ |
|
66 | - protected $_message_template_model; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * EE_Messages_Template_Defaults constructor. |
|
71 | - * |
|
72 | - * @param EE_messenger $messenger |
|
73 | - * @param EE_message_type $message_type |
|
74 | - * @param int|null $GRP_ID Optional. If included then we're just |
|
75 | - * regenerating the template fields for the given |
|
76 | - * group not the message template group itself |
|
77 | - * @param EEM_Message_Template_Group|null $message_template_group_model |
|
78 | - * @param EEM_Message_Template|null $message_template_model |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - EE_messenger $messenger, |
|
83 | - EE_message_type $message_type, |
|
84 | - ?int $GRP_ID, |
|
85 | - ?EEM_Message_Template_Group $message_template_group_model, |
|
86 | - ?EEM_Message_Template $message_template_model |
|
87 | - ) { |
|
88 | - $this->_messenger = $messenger; |
|
89 | - $this->_message_type = $message_type; |
|
90 | - $this->_GRP_ID = $GRP_ID ?? 0; |
|
91 | - // set the model object |
|
92 | - $this->_message_template_group_model = $message_template_group_model ?? EEM_Message_Template_Group::instance(); |
|
93 | - $this->_message_template_model = $message_template_model ?? EEM_Message_Template::instance(); |
|
94 | - $this->_fields = $this->_messenger->get_template_fields(); |
|
95 | - $this->_contexts = $this->_message_type->get_contexts(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Setup the _template_data property. |
|
101 | - * This method sets the _templates property array before templates are created. |
|
102 | - * |
|
103 | - * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
104 | - * about where to obtain the templates. |
|
105 | - * |
|
106 | - */ |
|
107 | - private function _set_templates(string $template_pack) |
|
108 | - { |
|
109 | - // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
110 | - // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
111 | - // the incoming template pack reference. |
|
112 | - $class_name = |
|
113 | - 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
114 | - |
|
115 | - if (! class_exists($class_name)) { |
|
116 | - EE_Error::add_error( |
|
117 | - sprintf( |
|
118 | - esc_html__( |
|
119 | - 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
120 | - 'event_espresso' |
|
121 | - ), |
|
122 | - $class_name |
|
123 | - ), |
|
124 | - __FILE__, |
|
125 | - __FUNCTION__, |
|
126 | - __LINE__ |
|
127 | - ); |
|
128 | - $class_name = 'EE_Messages_Template_Pack_Default'; |
|
129 | - } |
|
130 | - /** @type EE_Messages_Template_Pack $template_pack */ |
|
131 | - $template_pack = new $class_name(); |
|
132 | - |
|
133 | - // get all the templates from the template pack. |
|
134 | - $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Return the contexts for the message type as cached on this instance. |
|
140 | - * |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public function get_contexts(): array |
|
144 | - { |
|
145 | - return $this->_contexts; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * public facing create new templates method |
|
151 | - * |
|
152 | - * @return array|false|int|string success array or false. |
|
153 | - * @throws EE_Error |
|
154 | - * @throws ReflectionException |
|
155 | - */ |
|
156 | - public function create_new_templates() |
|
157 | - { |
|
158 | - $template_pack = 'default'; |
|
159 | - // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
160 | - if (! empty($this->_GRP_ID)) { |
|
161 | - $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
162 | - $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
163 | - ? $message_template_group->get_template_pack_name() |
|
164 | - : 'default'; |
|
165 | - // we also need to reset the template variation to default |
|
166 | - $message_template_group->set_template_pack_variation('default'); |
|
167 | - } |
|
168 | - return $this->_create_new_templates($template_pack); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Handles creating new default templates. |
|
174 | - * |
|
175 | - * @param string $template_pack This corresponds to a template pack class reference |
|
176 | - * which will contain information about where to obtain the templates. |
|
177 | - * @return array|bool success array or false. |
|
178 | - * @throws EE_Error |
|
179 | - * @throws ReflectionException |
|
180 | - */ |
|
181 | - protected function _create_new_templates(string $template_pack) |
|
182 | - { |
|
183 | - $this->_set_templates($template_pack); |
|
184 | - |
|
185 | - // necessary properties are set, let's save the default templates |
|
186 | - if (empty($this->_GRP_ID)) { |
|
187 | - $main_template_data = [ |
|
188 | - 'MTP_messenger' => $this->_messenger->name, |
|
189 | - 'MTP_message_type' => $this->_message_type->name, |
|
190 | - 'MTP_is_override' => 0, |
|
191 | - 'MTP_deleted' => 0, |
|
192 | - 'MTP_is_global' => 1, |
|
193 | - 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
194 | - 'MTP_is_active' => 1, |
|
195 | - ]; |
|
196 | - // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
197 | - $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
198 | - if (empty($grp_id)) { |
|
199 | - return $grp_id; |
|
200 | - } |
|
201 | - $this->_GRP_ID = $grp_id; |
|
202 | - } |
|
203 | - |
|
204 | - $template_data = ['GRP_ID' => $this->_GRP_ID]; |
|
205 | - |
|
206 | - foreach ($this->_contexts as $context => $details) { |
|
207 | - foreach ($this->_fields as $field => $field_type) { |
|
208 | - if ($field != 'extra') { |
|
209 | - $template_data['MTP_context'] = $context; |
|
210 | - $template_data['MTP_template_field'] = $field; |
|
211 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
212 | - |
|
213 | - $MTP = $this->_message_template_model->insert($template_data); |
|
214 | - if (! $MTP) { |
|
215 | - EE_Error::add_error( |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $this->_messenger->name, |
|
222 | - $this->_message_type->name, |
|
223 | - $context, |
|
224 | - $field |
|
225 | - ), |
|
226 | - __FILE__, |
|
227 | - __FUNCTION__, |
|
228 | - __LINE__ |
|
229 | - ); |
|
230 | - return false; |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - return [ |
|
237 | - 'GRP_ID' => $this->_GRP_ID, |
|
238 | - 'MTP_context' => key($this->_contexts), |
|
239 | - ]; |
|
240 | - } |
|
14 | + /** |
|
15 | + * Used for holding the EE_Message_Template GRP_ID field value. |
|
16 | + * |
|
17 | + * @var [type] |
|
18 | + */ |
|
19 | + protected $_GRP_ID; |
|
20 | + |
|
21 | + /** |
|
22 | + * holds the messenger object |
|
23 | + * |
|
24 | + * @var EE_messenger |
|
25 | + */ |
|
26 | + protected $_messenger; |
|
27 | + |
|
28 | + /** |
|
29 | + * holds the message type object |
|
30 | + * |
|
31 | + * @var EE_message_type |
|
32 | + */ |
|
33 | + protected $_message_type; |
|
34 | + |
|
35 | + /** |
|
36 | + * holds the fields used (this is retrieved from the messenger) |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $_fields; |
|
41 | + |
|
42 | + /** |
|
43 | + * holds the assembled template (with defaults) for creation in the database |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $_templates; |
|
48 | + |
|
49 | + /** |
|
50 | + * holds the contexts used (this is retrieved from the message type) |
|
51 | + * |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $_contexts; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EEM_Message_Template_Group |
|
59 | + */ |
|
60 | + protected $_message_template_group_model; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @var EEM_Message_Template |
|
65 | + */ |
|
66 | + protected $_message_template_model; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * EE_Messages_Template_Defaults constructor. |
|
71 | + * |
|
72 | + * @param EE_messenger $messenger |
|
73 | + * @param EE_message_type $message_type |
|
74 | + * @param int|null $GRP_ID Optional. If included then we're just |
|
75 | + * regenerating the template fields for the given |
|
76 | + * group not the message template group itself |
|
77 | + * @param EEM_Message_Template_Group|null $message_template_group_model |
|
78 | + * @param EEM_Message_Template|null $message_template_model |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + EE_messenger $messenger, |
|
83 | + EE_message_type $message_type, |
|
84 | + ?int $GRP_ID, |
|
85 | + ?EEM_Message_Template_Group $message_template_group_model, |
|
86 | + ?EEM_Message_Template $message_template_model |
|
87 | + ) { |
|
88 | + $this->_messenger = $messenger; |
|
89 | + $this->_message_type = $message_type; |
|
90 | + $this->_GRP_ID = $GRP_ID ?? 0; |
|
91 | + // set the model object |
|
92 | + $this->_message_template_group_model = $message_template_group_model ?? EEM_Message_Template_Group::instance(); |
|
93 | + $this->_message_template_model = $message_template_model ?? EEM_Message_Template::instance(); |
|
94 | + $this->_fields = $this->_messenger->get_template_fields(); |
|
95 | + $this->_contexts = $this->_message_type->get_contexts(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Setup the _template_data property. |
|
101 | + * This method sets the _templates property array before templates are created. |
|
102 | + * |
|
103 | + * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
104 | + * about where to obtain the templates. |
|
105 | + * |
|
106 | + */ |
|
107 | + private function _set_templates(string $template_pack) |
|
108 | + { |
|
109 | + // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
110 | + // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
111 | + // the incoming template pack reference. |
|
112 | + $class_name = |
|
113 | + 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
114 | + |
|
115 | + if (! class_exists($class_name)) { |
|
116 | + EE_Error::add_error( |
|
117 | + sprintf( |
|
118 | + esc_html__( |
|
119 | + 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
120 | + 'event_espresso' |
|
121 | + ), |
|
122 | + $class_name |
|
123 | + ), |
|
124 | + __FILE__, |
|
125 | + __FUNCTION__, |
|
126 | + __LINE__ |
|
127 | + ); |
|
128 | + $class_name = 'EE_Messages_Template_Pack_Default'; |
|
129 | + } |
|
130 | + /** @type EE_Messages_Template_Pack $template_pack */ |
|
131 | + $template_pack = new $class_name(); |
|
132 | + |
|
133 | + // get all the templates from the template pack. |
|
134 | + $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Return the contexts for the message type as cached on this instance. |
|
140 | + * |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public function get_contexts(): array |
|
144 | + { |
|
145 | + return $this->_contexts; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * public facing create new templates method |
|
151 | + * |
|
152 | + * @return array|false|int|string success array or false. |
|
153 | + * @throws EE_Error |
|
154 | + * @throws ReflectionException |
|
155 | + */ |
|
156 | + public function create_new_templates() |
|
157 | + { |
|
158 | + $template_pack = 'default'; |
|
159 | + // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
160 | + if (! empty($this->_GRP_ID)) { |
|
161 | + $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
162 | + $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
163 | + ? $message_template_group->get_template_pack_name() |
|
164 | + : 'default'; |
|
165 | + // we also need to reset the template variation to default |
|
166 | + $message_template_group->set_template_pack_variation('default'); |
|
167 | + } |
|
168 | + return $this->_create_new_templates($template_pack); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Handles creating new default templates. |
|
174 | + * |
|
175 | + * @param string $template_pack This corresponds to a template pack class reference |
|
176 | + * which will contain information about where to obtain the templates. |
|
177 | + * @return array|bool success array or false. |
|
178 | + * @throws EE_Error |
|
179 | + * @throws ReflectionException |
|
180 | + */ |
|
181 | + protected function _create_new_templates(string $template_pack) |
|
182 | + { |
|
183 | + $this->_set_templates($template_pack); |
|
184 | + |
|
185 | + // necessary properties are set, let's save the default templates |
|
186 | + if (empty($this->_GRP_ID)) { |
|
187 | + $main_template_data = [ |
|
188 | + 'MTP_messenger' => $this->_messenger->name, |
|
189 | + 'MTP_message_type' => $this->_message_type->name, |
|
190 | + 'MTP_is_override' => 0, |
|
191 | + 'MTP_deleted' => 0, |
|
192 | + 'MTP_is_global' => 1, |
|
193 | + 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
194 | + 'MTP_is_active' => 1, |
|
195 | + ]; |
|
196 | + // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
197 | + $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
198 | + if (empty($grp_id)) { |
|
199 | + return $grp_id; |
|
200 | + } |
|
201 | + $this->_GRP_ID = $grp_id; |
|
202 | + } |
|
203 | + |
|
204 | + $template_data = ['GRP_ID' => $this->_GRP_ID]; |
|
205 | + |
|
206 | + foreach ($this->_contexts as $context => $details) { |
|
207 | + foreach ($this->_fields as $field => $field_type) { |
|
208 | + if ($field != 'extra') { |
|
209 | + $template_data['MTP_context'] = $context; |
|
210 | + $template_data['MTP_template_field'] = $field; |
|
211 | + $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
212 | + |
|
213 | + $MTP = $this->_message_template_model->insert($template_data); |
|
214 | + if (! $MTP) { |
|
215 | + EE_Error::add_error( |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $this->_messenger->name, |
|
222 | + $this->_message_type->name, |
|
223 | + $context, |
|
224 | + $field |
|
225 | + ), |
|
226 | + __FILE__, |
|
227 | + __FUNCTION__, |
|
228 | + __LINE__ |
|
229 | + ); |
|
230 | + return false; |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + return [ |
|
237 | + 'GRP_ID' => $this->_GRP_ID, |
|
238 | + 'MTP_context' => key($this->_contexts), |
|
239 | + ]; |
|
240 | + } |
|
241 | 241 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | 'This messenger outputs a message to a browser for display.', |
41 | 41 | 'event_espresso' |
42 | 42 | ); |
43 | - $this->label = [ |
|
43 | + $this->label = [ |
|
44 | 44 | 'singular' => esc_html__('html', 'event_espresso'), |
45 | 45 | 'plural' => esc_html__('html', 'event_espresso'), |
46 | 46 | ]; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | ], |
313 | 313 | 'ticket_line_item_no_pms' => [ |
314 | 314 | 'input' => 'textarea', |
315 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
315 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
316 | 316 | 'Ticket Line Item List with no Price Modifiers', |
317 | 317 | 'event_espresso' |
318 | 318 | ), |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ], |
327 | 327 | 'ticket_line_item_pms' => [ |
328 | 328 | 'input' => 'textarea', |
329 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
329 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
330 | 330 | 'Ticket Line Item List with Price Modifiers', |
331 | 331 | 'event_espresso' |
332 | 332 | ), |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | 'aln-cntr', |
552 | 552 | '', |
553 | 553 | ['utm_content' => 'messages_system'] |
554 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
554 | + ).EEH_HTML::div(EEH_HTML::p(' ')); |
|
555 | 555 | } |
556 | 556 | return $content; |
557 | 557 | } |
@@ -12,550 +12,550 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Html_messenger extends EE_messenger |
14 | 14 | { |
15 | - /** |
|
16 | - * The following are the properties that this messenger requires for displaying the html |
|
17 | - */ |
|
18 | - /** |
|
19 | - * This is the html body generated by the template via the message type. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_content = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
27 | - * equivalent to the "subject" of the page. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_subject = ''; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * EE_Html_messenger constructor. |
|
36 | - */ |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - // set properties |
|
40 | - $this->name = 'html'; |
|
41 | - $this->description = esc_html__( |
|
42 | - 'This messenger outputs a message to a browser for display.', |
|
43 | - 'event_espresso' |
|
44 | - ); |
|
45 | - $this->label = [ |
|
46 | - 'singular' => esc_html__('html', 'event_espresso'), |
|
47 | - 'plural' => esc_html__('html', 'event_espresso'), |
|
48 | - ]; |
|
49 | - $this->activate_on_install = true; |
|
50 | - // add the "powered by EE" credit link to the HTML receipt and invoice |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
53 | - [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
54 | - 10, |
|
55 | - 3 |
|
56 | - ); |
|
57 | - parent::__construct(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * HTML Messenger desires execution immediately. |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - * @since 4.9.0 |
|
66 | - * @see parent::send_now() for documentation. |
|
67 | - */ |
|
68 | - public function send_now(): bool |
|
69 | - { |
|
70 | - return true; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * HTML Messenger allows an empty to field. |
|
76 | - * |
|
77 | - * @return bool |
|
78 | - * @since 4.9.0 |
|
79 | - * @see parent::allow_empty_to_field() for documentation |
|
80 | - */ |
|
81 | - public function allow_empty_to_field(): bool |
|
82 | - { |
|
83 | - return true; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @see abstract declaration in EE_messenger for details. |
|
89 | - */ |
|
90 | - protected function _set_admin_pages() |
|
91 | - { |
|
92 | - $this->admin_registered_pages = ['events_edit' => true]; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @see abstract declaration in EE_messenger for details. |
|
98 | - */ |
|
99 | - protected function _set_valid_shortcodes() |
|
100 | - { |
|
101 | - $this->_valid_shortcodes = []; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @see abstract declaration in EE_messenger for details. |
|
107 | - */ |
|
108 | - protected function _set_validator_config() |
|
109 | - { |
|
110 | - $this->_validator_config = [ |
|
111 | - 'subject' => [ |
|
112 | - 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
113 | - ], |
|
114 | - 'content' => [ |
|
115 | - 'shortcodes' => [ |
|
116 | - 'organization', |
|
117 | - 'primary_registration_list', |
|
118 | - 'primary_registration_details', |
|
119 | - 'email', |
|
120 | - 'transaction', |
|
121 | - 'event_list', |
|
122 | - 'payment_list', |
|
123 | - 'venue', |
|
124 | - 'line_item_list', |
|
125 | - 'messenger', |
|
126 | - 'ticket_list', |
|
127 | - ], |
|
128 | - ], |
|
129 | - 'event_list' => [ |
|
130 | - 'shortcodes' => [ |
|
131 | - 'event', |
|
132 | - 'ticket_list', |
|
133 | - 'venue', |
|
134 | - 'primary_registration_details', |
|
135 | - 'primary_registration_list', |
|
136 | - 'event_author', |
|
137 | - ], |
|
138 | - 'required' => ['[EVENT_LIST]'], |
|
139 | - ], |
|
140 | - 'ticket_list' => [ |
|
141 | - 'shortcodes' => [ |
|
142 | - 'attendee_list', |
|
143 | - 'ticket', |
|
144 | - 'datetime_list', |
|
145 | - 'primary_registration_details', |
|
146 | - 'line_item_list', |
|
147 | - 'venue', |
|
148 | - ], |
|
149 | - 'required' => ['[TICKET_LIST]'], |
|
150 | - ], |
|
151 | - 'ticket_line_item_no_pms' => [ |
|
152 | - 'shortcodes' => ['line_item', 'ticket'], |
|
153 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
154 | - ], |
|
155 | - 'ticket_line_item_pms' => [ |
|
156 | - 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
157 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
158 | - ], |
|
159 | - 'price_modifier_line_item_list' => [ |
|
160 | - 'shortcodes' => ['line_item'], |
|
161 | - 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
162 | - ], |
|
163 | - 'datetime_list' => [ |
|
164 | - 'shortcodes' => ['datetime'], |
|
165 | - 'required' => ['[DATETIME_LIST]'], |
|
166 | - ], |
|
167 | - 'attendee_list' => [ |
|
168 | - 'shortcodes' => ['attendee'], |
|
169 | - 'required' => ['[ATTENDEE_LIST]'], |
|
170 | - ], |
|
171 | - 'tax_line_item_list' => [ |
|
172 | - 'shortcodes' => ['line_item'], |
|
173 | - 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
174 | - ], |
|
175 | - 'additional_line_item_list' => [ |
|
176 | - 'shortcodes' => ['line_item'], |
|
177 | - 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
178 | - ], |
|
179 | - 'payment_list' => [ |
|
180 | - 'shortcodes' => ['payment'], |
|
181 | - 'required' => ['[PAYMENT_LIST_*]'], |
|
182 | - ], |
|
183 | - ]; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
189 | - * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
190 | - * (i.e. swap out css files or something else). |
|
191 | - * |
|
192 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
193 | - * @return void |
|
194 | - * @since 4.5.0 |
|
195 | - */ |
|
196 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
197 | - { |
|
198 | - if ($sending_messenger_name === 'pdf') { |
|
199 | - add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param $variation_path |
|
206 | - * @param EE_Messages_Template_Pack $template_pack |
|
207 | - * @param $messenger_name |
|
208 | - * @param $message_type_name |
|
209 | - * @param $url |
|
210 | - * @param $type |
|
211 | - * @param $variation |
|
212 | - * @param $skip_filters |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - public function add_html_css( |
|
216 | - $variation_path, |
|
217 | - EE_Messages_Template_Pack $template_pack, |
|
218 | - $messenger_name, |
|
219 | - $message_type_name, |
|
220 | - $url, |
|
221 | - $type, |
|
222 | - $variation, |
|
223 | - $skip_filters |
|
224 | - ): string { |
|
225 | - return $template_pack->get_variation( |
|
226 | - $this->name, |
|
227 | - $message_type_name, |
|
228 | - $type, |
|
229 | - $variation, |
|
230 | - $url, |
|
231 | - '.css', |
|
232 | - $skip_filters |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
239 | - * messenger can add their own js. |
|
240 | - * |
|
241 | - * @return void. |
|
242 | - */ |
|
243 | - public function enqueue_scripts_styles() |
|
244 | - { |
|
245 | - parent::enqueue_scripts_styles(); |
|
246 | - do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * _set_template_fields |
|
252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - protected function _set_template_fields() |
|
258 | - { |
|
259 | - // any extra template fields that are NOT used by the messenger |
|
260 | - // but will get used by a messenger field for shortcode replacement |
|
261 | - // get added to the 'extra' key in an associated array |
|
262 | - // indexed by the messenger field they relate to. |
|
263 | - // This is important for the Messages_admin to know what fields to display to the user. |
|
264 | - // Also, notice that the "values" are equal to the field type |
|
265 | - // that messages admin will use to know what kind of field to display. |
|
266 | - // The values ALSO have one index labeled "shortcode". |
|
267 | - // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
268 | - // is required in order for this extra field to be displayed. |
|
269 | - // If the required shortcode isn't part of the shortcodes array |
|
270 | - // then the field is not needed and will not be displayed/parsed. |
|
271 | - $this->_template_fields = [ |
|
272 | - 'subject' => [ |
|
273 | - 'input' => 'text', |
|
274 | - 'label' => esc_html__('Page Title', 'event_espresso'), |
|
275 | - 'type' => 'string', |
|
276 | - 'required' => true, |
|
277 | - 'validation' => true, |
|
278 | - 'css_class' => 'large-text', |
|
279 | - 'format' => '%s', |
|
280 | - ], |
|
281 | - 'content' => '', |
|
282 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
283 | - 'extra' => [ |
|
284 | - 'content' => [ |
|
285 | - 'main' => [ |
|
286 | - 'input' => 'wp_editor', |
|
287 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
288 | - 'type' => 'string', |
|
289 | - 'required' => false, |
|
290 | - 'validation' => true, |
|
291 | - 'format' => '%s', |
|
292 | - 'rows' => '15', |
|
293 | - ], |
|
294 | - 'event_list' => [ |
|
295 | - 'input' => 'wp_editor', |
|
296 | - 'label' => '[EVENT_LIST]', |
|
297 | - 'type' => 'string', |
|
298 | - 'required' => false, |
|
299 | - 'validation' => true, |
|
300 | - 'format' => '%s', |
|
301 | - 'rows' => '15', |
|
302 | - 'shortcodes_required' => ['[EVENT_LIST]'], |
|
303 | - ], |
|
304 | - 'ticket_list' => [ |
|
305 | - 'input' => 'textarea', |
|
306 | - 'label' => '[TICKET_LIST]', |
|
307 | - 'type' => 'string', |
|
308 | - 'required' => false, |
|
309 | - 'validation' => true, |
|
310 | - 'format' => '%s', |
|
311 | - 'css_class' => 'large-text', |
|
312 | - 'rows' => '10', |
|
313 | - 'shortcodes_required' => ['[TICKET_LIST]'], |
|
314 | - ], |
|
315 | - 'ticket_line_item_no_pms' => [ |
|
316 | - 'input' => 'textarea', |
|
317 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
318 | - 'Ticket Line Item List with no Price Modifiers', |
|
319 | - 'event_espresso' |
|
320 | - ), |
|
321 | - 'type' => 'string', |
|
322 | - 'required' => false, |
|
323 | - 'validation' => true, |
|
324 | - 'format' => '%s', |
|
325 | - 'css_class' => 'large-text', |
|
326 | - 'rows' => '5', |
|
327 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
328 | - ], |
|
329 | - 'ticket_line_item_pms' => [ |
|
330 | - 'input' => 'textarea', |
|
331 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
332 | - 'Ticket Line Item List with Price Modifiers', |
|
333 | - 'event_espresso' |
|
334 | - ), |
|
335 | - 'type' => 'string', |
|
336 | - 'required' => false, |
|
337 | - 'validation' => true, |
|
338 | - 'format' => '%s', |
|
339 | - 'css_class' => 'large-text', |
|
340 | - 'rows' => '5', |
|
341 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
342 | - ], |
|
343 | - 'price_modifier_line_item_list' => [ |
|
344 | - 'input' => 'textarea', |
|
345 | - 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
346 | - 'type' => 'string', |
|
347 | - 'required' => false, |
|
348 | - 'validation' => true, |
|
349 | - 'format' => '%s', |
|
350 | - 'css_class' => 'large-text', |
|
351 | - 'rows' => '5', |
|
352 | - 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
353 | - ], |
|
354 | - 'datetime_list' => [ |
|
355 | - 'input' => 'textarea', |
|
356 | - 'label' => '[DATETIME_LIST]', |
|
357 | - 'type' => 'string', |
|
358 | - 'required' => false, |
|
359 | - 'validation' => true, |
|
360 | - 'format' => '%s', |
|
361 | - 'css_class' => 'large-text', |
|
362 | - 'rows' => '5', |
|
363 | - 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
364 | - ], |
|
365 | - 'attendee_list' => [ |
|
366 | - 'input' => 'textarea', |
|
367 | - 'label' => '[ATTENDEE_LIST]', |
|
368 | - 'type' => 'string', |
|
369 | - 'required' => false, |
|
370 | - 'validation' => true, |
|
371 | - 'format' => '%s', |
|
372 | - 'css_class' => 'large-text', |
|
373 | - 'rows' => '5', |
|
374 | - 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
375 | - ], |
|
376 | - 'tax_line_item_list' => [ |
|
377 | - 'input' => 'textarea', |
|
378 | - 'label' => '[TAX_LINE_ITEM_LIST]', |
|
379 | - 'type' => 'string', |
|
380 | - 'required' => false, |
|
381 | - 'validation' => true, |
|
382 | - 'format' => '%s', |
|
383 | - 'css_class' => 'large-text', |
|
384 | - 'rows' => '5', |
|
385 | - 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
386 | - ], |
|
387 | - 'additional_line_item_list' => [ |
|
388 | - 'input' => 'textarea', |
|
389 | - 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
390 | - 'type' => 'string', |
|
391 | - 'required' => false, |
|
392 | - 'validation' => true, |
|
393 | - 'format' => '%s', |
|
394 | - 'css_class' => 'large-text', |
|
395 | - 'rows' => '5', |
|
396 | - 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
397 | - ], |
|
398 | - 'payment_list' => [ |
|
399 | - 'input' => 'textarea', |
|
400 | - 'label' => '[PAYMENT_LIST]', |
|
401 | - 'type' => 'string', |
|
402 | - 'required' => false, |
|
403 | - 'validation' => true, |
|
404 | - 'format' => '%s', |
|
405 | - 'css_class' => 'large-text', |
|
406 | - 'rows' => '5', |
|
407 | - 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
408 | - ], |
|
409 | - ], |
|
410 | - ], |
|
411 | - ]; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @see definition of this method in parent |
|
417 | - * @since 4.5.0 |
|
418 | - */ |
|
419 | - protected function _set_default_message_types() |
|
420 | - { |
|
421 | - $this->_default_message_types = ['receipt', 'invoice']; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @see definition of this method in parent |
|
427 | - * @since 4.5.0 |
|
428 | - */ |
|
429 | - protected function _set_valid_message_types() |
|
430 | - { |
|
431 | - $this->_valid_message_types = ['receipt', 'invoice']; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Displays the message in the browser. |
|
437 | - * |
|
438 | - * @return void. |
|
439 | - * @since 4.5.0 |
|
440 | - */ |
|
441 | - protected function _send_message() |
|
442 | - { |
|
443 | - $this->_template_args = [ |
|
444 | - 'page_title' => $this->_subject, |
|
445 | - 'base_css' => $this->get_variation( |
|
446 | - $this->_tmp_pack, |
|
447 | - $this->_incoming_message_type->name, |
|
448 | - true, |
|
449 | - 'base', |
|
450 | - $this->_variation |
|
451 | - ), |
|
452 | - 'print_css' => $this->get_variation( |
|
453 | - $this->_tmp_pack, |
|
454 | - $this->_incoming_message_type->name, |
|
455 | - true, |
|
456 | - 'print', |
|
457 | - $this->_variation |
|
458 | - ), |
|
459 | - 'main_css' => $this->get_variation( |
|
460 | - $this->_tmp_pack, |
|
461 | - $this->_incoming_message_type->name, |
|
462 | - true, |
|
463 | - 'main', |
|
464 | - $this->_variation |
|
465 | - ), |
|
466 | - 'main_body' => wpautop( |
|
467 | - apply_filters( |
|
468 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
469 | - (string) $this->_content, |
|
470 | - (string) $this->_content, |
|
471 | - $this->_incoming_message_type |
|
472 | - ), |
|
473 | - false |
|
474 | - ), |
|
475 | - ]; |
|
476 | - $this->_deregister_wp_hooks(); |
|
477 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
478 | - echo ($this->_get_main_template()); |
|
479 | - exit(); |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
485 | - * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
486 | - * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
487 | - * |
|
488 | - * @return void |
|
489 | - * @since 4.5.0 |
|
490 | - */ |
|
491 | - protected function _deregister_wp_hooks() |
|
492 | - { |
|
493 | - remove_all_actions('wp_head'); |
|
494 | - remove_all_actions('wp_footer'); |
|
495 | - remove_all_actions('wp_print_footer_scripts'); |
|
496 | - remove_all_actions('wp_enqueue_scripts'); |
|
497 | - global $wp_scripts, $wp_styles; |
|
498 | - $wp_scripts = $wp_styles = []; |
|
499 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
500 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
501 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
502 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Overwrite parent _get_main_template for display_html purposes. |
|
508 | - * |
|
509 | - * @param bool $preview |
|
510 | - * @return string |
|
511 | - * @since 4.5.0 |
|
512 | - */ |
|
513 | - protected function _get_main_template($preview = false): string |
|
514 | - { |
|
515 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
516 | - // include message type as a template arg |
|
517 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
518 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @return void |
|
524 | - */ |
|
525 | - protected function _preview() |
|
526 | - { |
|
527 | - $this->_send_message(); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - protected function _set_admin_settings_fields() |
|
532 | - { |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * add the "powered by EE" credit link to the HTML receipt and invoice |
|
538 | - * |
|
539 | - * @param string|null $content |
|
540 | - * @param string|null $content_again |
|
541 | - * @param EE_message_type $incoming_message_type |
|
542 | - * @return string |
|
543 | - */ |
|
544 | - public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
545 | - ?string $content, |
|
546 | - ?string $content_again, |
|
547 | - EE_message_type $incoming_message_type |
|
548 | - ): string { |
|
549 | - if ( |
|
550 | - ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
551 | - && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
552 | - ) { |
|
553 | - $content .= EEH_Template::powered_by_event_espresso( |
|
554 | - 'aln-cntr', |
|
555 | - '', |
|
556 | - ['utm_content' => 'messages_system'] |
|
557 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
558 | - } |
|
559 | - return $content; |
|
560 | - } |
|
15 | + /** |
|
16 | + * The following are the properties that this messenger requires for displaying the html |
|
17 | + */ |
|
18 | + /** |
|
19 | + * This is the html body generated by the template via the message type. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_content = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
27 | + * equivalent to the "subject" of the page. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_subject = ''; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * EE_Html_messenger constructor. |
|
36 | + */ |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + // set properties |
|
40 | + $this->name = 'html'; |
|
41 | + $this->description = esc_html__( |
|
42 | + 'This messenger outputs a message to a browser for display.', |
|
43 | + 'event_espresso' |
|
44 | + ); |
|
45 | + $this->label = [ |
|
46 | + 'singular' => esc_html__('html', 'event_espresso'), |
|
47 | + 'plural' => esc_html__('html', 'event_espresso'), |
|
48 | + ]; |
|
49 | + $this->activate_on_install = true; |
|
50 | + // add the "powered by EE" credit link to the HTML receipt and invoice |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
53 | + [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
54 | + 10, |
|
55 | + 3 |
|
56 | + ); |
|
57 | + parent::__construct(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * HTML Messenger desires execution immediately. |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + * @since 4.9.0 |
|
66 | + * @see parent::send_now() for documentation. |
|
67 | + */ |
|
68 | + public function send_now(): bool |
|
69 | + { |
|
70 | + return true; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * HTML Messenger allows an empty to field. |
|
76 | + * |
|
77 | + * @return bool |
|
78 | + * @since 4.9.0 |
|
79 | + * @see parent::allow_empty_to_field() for documentation |
|
80 | + */ |
|
81 | + public function allow_empty_to_field(): bool |
|
82 | + { |
|
83 | + return true; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @see abstract declaration in EE_messenger for details. |
|
89 | + */ |
|
90 | + protected function _set_admin_pages() |
|
91 | + { |
|
92 | + $this->admin_registered_pages = ['events_edit' => true]; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @see abstract declaration in EE_messenger for details. |
|
98 | + */ |
|
99 | + protected function _set_valid_shortcodes() |
|
100 | + { |
|
101 | + $this->_valid_shortcodes = []; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @see abstract declaration in EE_messenger for details. |
|
107 | + */ |
|
108 | + protected function _set_validator_config() |
|
109 | + { |
|
110 | + $this->_validator_config = [ |
|
111 | + 'subject' => [ |
|
112 | + 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
113 | + ], |
|
114 | + 'content' => [ |
|
115 | + 'shortcodes' => [ |
|
116 | + 'organization', |
|
117 | + 'primary_registration_list', |
|
118 | + 'primary_registration_details', |
|
119 | + 'email', |
|
120 | + 'transaction', |
|
121 | + 'event_list', |
|
122 | + 'payment_list', |
|
123 | + 'venue', |
|
124 | + 'line_item_list', |
|
125 | + 'messenger', |
|
126 | + 'ticket_list', |
|
127 | + ], |
|
128 | + ], |
|
129 | + 'event_list' => [ |
|
130 | + 'shortcodes' => [ |
|
131 | + 'event', |
|
132 | + 'ticket_list', |
|
133 | + 'venue', |
|
134 | + 'primary_registration_details', |
|
135 | + 'primary_registration_list', |
|
136 | + 'event_author', |
|
137 | + ], |
|
138 | + 'required' => ['[EVENT_LIST]'], |
|
139 | + ], |
|
140 | + 'ticket_list' => [ |
|
141 | + 'shortcodes' => [ |
|
142 | + 'attendee_list', |
|
143 | + 'ticket', |
|
144 | + 'datetime_list', |
|
145 | + 'primary_registration_details', |
|
146 | + 'line_item_list', |
|
147 | + 'venue', |
|
148 | + ], |
|
149 | + 'required' => ['[TICKET_LIST]'], |
|
150 | + ], |
|
151 | + 'ticket_line_item_no_pms' => [ |
|
152 | + 'shortcodes' => ['line_item', 'ticket'], |
|
153 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
154 | + ], |
|
155 | + 'ticket_line_item_pms' => [ |
|
156 | + 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
157 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
158 | + ], |
|
159 | + 'price_modifier_line_item_list' => [ |
|
160 | + 'shortcodes' => ['line_item'], |
|
161 | + 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
162 | + ], |
|
163 | + 'datetime_list' => [ |
|
164 | + 'shortcodes' => ['datetime'], |
|
165 | + 'required' => ['[DATETIME_LIST]'], |
|
166 | + ], |
|
167 | + 'attendee_list' => [ |
|
168 | + 'shortcodes' => ['attendee'], |
|
169 | + 'required' => ['[ATTENDEE_LIST]'], |
|
170 | + ], |
|
171 | + 'tax_line_item_list' => [ |
|
172 | + 'shortcodes' => ['line_item'], |
|
173 | + 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
174 | + ], |
|
175 | + 'additional_line_item_list' => [ |
|
176 | + 'shortcodes' => ['line_item'], |
|
177 | + 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
178 | + ], |
|
179 | + 'payment_list' => [ |
|
180 | + 'shortcodes' => ['payment'], |
|
181 | + 'required' => ['[PAYMENT_LIST_*]'], |
|
182 | + ], |
|
183 | + ]; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
189 | + * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
190 | + * (i.e. swap out css files or something else). |
|
191 | + * |
|
192 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
193 | + * @return void |
|
194 | + * @since 4.5.0 |
|
195 | + */ |
|
196 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
197 | + { |
|
198 | + if ($sending_messenger_name === 'pdf') { |
|
199 | + add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param $variation_path |
|
206 | + * @param EE_Messages_Template_Pack $template_pack |
|
207 | + * @param $messenger_name |
|
208 | + * @param $message_type_name |
|
209 | + * @param $url |
|
210 | + * @param $type |
|
211 | + * @param $variation |
|
212 | + * @param $skip_filters |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + public function add_html_css( |
|
216 | + $variation_path, |
|
217 | + EE_Messages_Template_Pack $template_pack, |
|
218 | + $messenger_name, |
|
219 | + $message_type_name, |
|
220 | + $url, |
|
221 | + $type, |
|
222 | + $variation, |
|
223 | + $skip_filters |
|
224 | + ): string { |
|
225 | + return $template_pack->get_variation( |
|
226 | + $this->name, |
|
227 | + $message_type_name, |
|
228 | + $type, |
|
229 | + $variation, |
|
230 | + $url, |
|
231 | + '.css', |
|
232 | + $skip_filters |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
239 | + * messenger can add their own js. |
|
240 | + * |
|
241 | + * @return void. |
|
242 | + */ |
|
243 | + public function enqueue_scripts_styles() |
|
244 | + { |
|
245 | + parent::enqueue_scripts_styles(); |
|
246 | + do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * _set_template_fields |
|
252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + protected function _set_template_fields() |
|
258 | + { |
|
259 | + // any extra template fields that are NOT used by the messenger |
|
260 | + // but will get used by a messenger field for shortcode replacement |
|
261 | + // get added to the 'extra' key in an associated array |
|
262 | + // indexed by the messenger field they relate to. |
|
263 | + // This is important for the Messages_admin to know what fields to display to the user. |
|
264 | + // Also, notice that the "values" are equal to the field type |
|
265 | + // that messages admin will use to know what kind of field to display. |
|
266 | + // The values ALSO have one index labeled "shortcode". |
|
267 | + // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
268 | + // is required in order for this extra field to be displayed. |
|
269 | + // If the required shortcode isn't part of the shortcodes array |
|
270 | + // then the field is not needed and will not be displayed/parsed. |
|
271 | + $this->_template_fields = [ |
|
272 | + 'subject' => [ |
|
273 | + 'input' => 'text', |
|
274 | + 'label' => esc_html__('Page Title', 'event_espresso'), |
|
275 | + 'type' => 'string', |
|
276 | + 'required' => true, |
|
277 | + 'validation' => true, |
|
278 | + 'css_class' => 'large-text', |
|
279 | + 'format' => '%s', |
|
280 | + ], |
|
281 | + 'content' => '', |
|
282 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
283 | + 'extra' => [ |
|
284 | + 'content' => [ |
|
285 | + 'main' => [ |
|
286 | + 'input' => 'wp_editor', |
|
287 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
288 | + 'type' => 'string', |
|
289 | + 'required' => false, |
|
290 | + 'validation' => true, |
|
291 | + 'format' => '%s', |
|
292 | + 'rows' => '15', |
|
293 | + ], |
|
294 | + 'event_list' => [ |
|
295 | + 'input' => 'wp_editor', |
|
296 | + 'label' => '[EVENT_LIST]', |
|
297 | + 'type' => 'string', |
|
298 | + 'required' => false, |
|
299 | + 'validation' => true, |
|
300 | + 'format' => '%s', |
|
301 | + 'rows' => '15', |
|
302 | + 'shortcodes_required' => ['[EVENT_LIST]'], |
|
303 | + ], |
|
304 | + 'ticket_list' => [ |
|
305 | + 'input' => 'textarea', |
|
306 | + 'label' => '[TICKET_LIST]', |
|
307 | + 'type' => 'string', |
|
308 | + 'required' => false, |
|
309 | + 'validation' => true, |
|
310 | + 'format' => '%s', |
|
311 | + 'css_class' => 'large-text', |
|
312 | + 'rows' => '10', |
|
313 | + 'shortcodes_required' => ['[TICKET_LIST]'], |
|
314 | + ], |
|
315 | + 'ticket_line_item_no_pms' => [ |
|
316 | + 'input' => 'textarea', |
|
317 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
318 | + 'Ticket Line Item List with no Price Modifiers', |
|
319 | + 'event_espresso' |
|
320 | + ), |
|
321 | + 'type' => 'string', |
|
322 | + 'required' => false, |
|
323 | + 'validation' => true, |
|
324 | + 'format' => '%s', |
|
325 | + 'css_class' => 'large-text', |
|
326 | + 'rows' => '5', |
|
327 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
328 | + ], |
|
329 | + 'ticket_line_item_pms' => [ |
|
330 | + 'input' => 'textarea', |
|
331 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
332 | + 'Ticket Line Item List with Price Modifiers', |
|
333 | + 'event_espresso' |
|
334 | + ), |
|
335 | + 'type' => 'string', |
|
336 | + 'required' => false, |
|
337 | + 'validation' => true, |
|
338 | + 'format' => '%s', |
|
339 | + 'css_class' => 'large-text', |
|
340 | + 'rows' => '5', |
|
341 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
342 | + ], |
|
343 | + 'price_modifier_line_item_list' => [ |
|
344 | + 'input' => 'textarea', |
|
345 | + 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
346 | + 'type' => 'string', |
|
347 | + 'required' => false, |
|
348 | + 'validation' => true, |
|
349 | + 'format' => '%s', |
|
350 | + 'css_class' => 'large-text', |
|
351 | + 'rows' => '5', |
|
352 | + 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
353 | + ], |
|
354 | + 'datetime_list' => [ |
|
355 | + 'input' => 'textarea', |
|
356 | + 'label' => '[DATETIME_LIST]', |
|
357 | + 'type' => 'string', |
|
358 | + 'required' => false, |
|
359 | + 'validation' => true, |
|
360 | + 'format' => '%s', |
|
361 | + 'css_class' => 'large-text', |
|
362 | + 'rows' => '5', |
|
363 | + 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
364 | + ], |
|
365 | + 'attendee_list' => [ |
|
366 | + 'input' => 'textarea', |
|
367 | + 'label' => '[ATTENDEE_LIST]', |
|
368 | + 'type' => 'string', |
|
369 | + 'required' => false, |
|
370 | + 'validation' => true, |
|
371 | + 'format' => '%s', |
|
372 | + 'css_class' => 'large-text', |
|
373 | + 'rows' => '5', |
|
374 | + 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
375 | + ], |
|
376 | + 'tax_line_item_list' => [ |
|
377 | + 'input' => 'textarea', |
|
378 | + 'label' => '[TAX_LINE_ITEM_LIST]', |
|
379 | + 'type' => 'string', |
|
380 | + 'required' => false, |
|
381 | + 'validation' => true, |
|
382 | + 'format' => '%s', |
|
383 | + 'css_class' => 'large-text', |
|
384 | + 'rows' => '5', |
|
385 | + 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
386 | + ], |
|
387 | + 'additional_line_item_list' => [ |
|
388 | + 'input' => 'textarea', |
|
389 | + 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
390 | + 'type' => 'string', |
|
391 | + 'required' => false, |
|
392 | + 'validation' => true, |
|
393 | + 'format' => '%s', |
|
394 | + 'css_class' => 'large-text', |
|
395 | + 'rows' => '5', |
|
396 | + 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
397 | + ], |
|
398 | + 'payment_list' => [ |
|
399 | + 'input' => 'textarea', |
|
400 | + 'label' => '[PAYMENT_LIST]', |
|
401 | + 'type' => 'string', |
|
402 | + 'required' => false, |
|
403 | + 'validation' => true, |
|
404 | + 'format' => '%s', |
|
405 | + 'css_class' => 'large-text', |
|
406 | + 'rows' => '5', |
|
407 | + 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
408 | + ], |
|
409 | + ], |
|
410 | + ], |
|
411 | + ]; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @see definition of this method in parent |
|
417 | + * @since 4.5.0 |
|
418 | + */ |
|
419 | + protected function _set_default_message_types() |
|
420 | + { |
|
421 | + $this->_default_message_types = ['receipt', 'invoice']; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @see definition of this method in parent |
|
427 | + * @since 4.5.0 |
|
428 | + */ |
|
429 | + protected function _set_valid_message_types() |
|
430 | + { |
|
431 | + $this->_valid_message_types = ['receipt', 'invoice']; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Displays the message in the browser. |
|
437 | + * |
|
438 | + * @return void. |
|
439 | + * @since 4.5.0 |
|
440 | + */ |
|
441 | + protected function _send_message() |
|
442 | + { |
|
443 | + $this->_template_args = [ |
|
444 | + 'page_title' => $this->_subject, |
|
445 | + 'base_css' => $this->get_variation( |
|
446 | + $this->_tmp_pack, |
|
447 | + $this->_incoming_message_type->name, |
|
448 | + true, |
|
449 | + 'base', |
|
450 | + $this->_variation |
|
451 | + ), |
|
452 | + 'print_css' => $this->get_variation( |
|
453 | + $this->_tmp_pack, |
|
454 | + $this->_incoming_message_type->name, |
|
455 | + true, |
|
456 | + 'print', |
|
457 | + $this->_variation |
|
458 | + ), |
|
459 | + 'main_css' => $this->get_variation( |
|
460 | + $this->_tmp_pack, |
|
461 | + $this->_incoming_message_type->name, |
|
462 | + true, |
|
463 | + 'main', |
|
464 | + $this->_variation |
|
465 | + ), |
|
466 | + 'main_body' => wpautop( |
|
467 | + apply_filters( |
|
468 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
469 | + (string) $this->_content, |
|
470 | + (string) $this->_content, |
|
471 | + $this->_incoming_message_type |
|
472 | + ), |
|
473 | + false |
|
474 | + ), |
|
475 | + ]; |
|
476 | + $this->_deregister_wp_hooks(); |
|
477 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
478 | + echo ($this->_get_main_template()); |
|
479 | + exit(); |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
485 | + * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
486 | + * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
487 | + * |
|
488 | + * @return void |
|
489 | + * @since 4.5.0 |
|
490 | + */ |
|
491 | + protected function _deregister_wp_hooks() |
|
492 | + { |
|
493 | + remove_all_actions('wp_head'); |
|
494 | + remove_all_actions('wp_footer'); |
|
495 | + remove_all_actions('wp_print_footer_scripts'); |
|
496 | + remove_all_actions('wp_enqueue_scripts'); |
|
497 | + global $wp_scripts, $wp_styles; |
|
498 | + $wp_scripts = $wp_styles = []; |
|
499 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
500 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
501 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
502 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Overwrite parent _get_main_template for display_html purposes. |
|
508 | + * |
|
509 | + * @param bool $preview |
|
510 | + * @return string |
|
511 | + * @since 4.5.0 |
|
512 | + */ |
|
513 | + protected function _get_main_template($preview = false): string |
|
514 | + { |
|
515 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
516 | + // include message type as a template arg |
|
517 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
518 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @return void |
|
524 | + */ |
|
525 | + protected function _preview() |
|
526 | + { |
|
527 | + $this->_send_message(); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + protected function _set_admin_settings_fields() |
|
532 | + { |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * add the "powered by EE" credit link to the HTML receipt and invoice |
|
538 | + * |
|
539 | + * @param string|null $content |
|
540 | + * @param string|null $content_again |
|
541 | + * @param EE_message_type $incoming_message_type |
|
542 | + * @return string |
|
543 | + */ |
|
544 | + public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
545 | + ?string $content, |
|
546 | + ?string $content_again, |
|
547 | + EE_message_type $incoming_message_type |
|
548 | + ): string { |
|
549 | + if ( |
|
550 | + ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
551 | + && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
552 | + ) { |
|
553 | + $content .= EEH_Template::powered_by_event_espresso( |
|
554 | + 'aln-cntr', |
|
555 | + '', |
|
556 | + ['utm_content' => 'messages_system'] |
|
557 | + ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
558 | + } |
|
559 | + return $content; |
|
560 | + } |
|
561 | 561 | } |
@@ -13,55 +13,55 @@ |
||
13 | 13 | */ |
14 | 14 | interface EEI_Collection |
15 | 15 | { |
16 | - /** |
|
17 | - * attaches an object to the Collection |
|
18 | - * and sets any supplied data associated with the current iterator entry |
|
19 | - * by calling EEI_Collection::set_info() |
|
20 | - * |
|
21 | - * @param object $object |
|
22 | - * @param array|int|string $info |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - public function add($object, $info = ''): bool; |
|
16 | + /** |
|
17 | + * attaches an object to the Collection |
|
18 | + * and sets any supplied data associated with the current iterator entry |
|
19 | + * by calling EEI_Collection::set_info() |
|
20 | + * |
|
21 | + * @param object $object |
|
22 | + * @param array|int|string $info |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + public function add($object, $info = ''): bool; |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Sets the info associated with an object in the Collection |
|
31 | - * |
|
32 | - * @param object $object |
|
33 | - * @param array|int|string $info |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function set_info($object, $info = ''): bool; |
|
29 | + /** |
|
30 | + * Sets the info associated with an object in the Collection |
|
31 | + * |
|
32 | + * @param object $object |
|
33 | + * @param array|int|string $info |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function set_info($object, $info = ''): bool; |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * finds and returns an object in the Collection based on the info that was set using set_info() or add() |
|
42 | - * |
|
43 | - * @param array|int|string $info |
|
44 | - * @return null | object |
|
45 | - */ |
|
46 | - public function get_by_info($info = ''); |
|
40 | + /** |
|
41 | + * finds and returns an object in the Collection based on the info that was set using set_info() or add() |
|
42 | + * |
|
43 | + * @param array|int|string $info |
|
44 | + * @return null | object |
|
45 | + */ |
|
46 | + public function get_by_info($info = ''); |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
52 | - * |
|
53 | - * @param object $object |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function has($object): bool; |
|
50 | + /** |
|
51 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
52 | + * |
|
53 | + * @param object $object |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function has($object): bool; |
|
57 | 57 | |
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * detaches an object from the Collection |
|
62 | - * |
|
63 | - * @param $object |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function remove($object); |
|
60 | + /** |
|
61 | + * detaches an object from the Collection |
|
62 | + * |
|
63 | + * @param $object |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function remove($object); |
|
67 | 67 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | DbSafeDateTime::db_safe_timestamp_format, |
75 | 75 | $this->_datetime_string |
76 | 76 | ); |
77 | - if (! $date instanceof DateTime) { |
|
77 | + if ( ! $date instanceof DateTime) { |
|
78 | 78 | try { |
79 | 79 | // we want a stack trace to determine where the malformed date came from, so... |
80 | 80 | throw new DomainException(''); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | DbSafeDateTime::db_safe_timestamp_format, |
119 | 119 | $this->_datetime_string |
120 | 120 | ); |
121 | - if (! $date instanceof DateTime) { |
|
121 | + if ( ! $date instanceof DateTime) { |
|
122 | 122 | $this->writeToErrorLog( |
123 | 123 | sprintf( |
124 | 124 | esc_html__( |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private function writeToErrorLog(string $message) |
202 | 202 | { |
203 | - if (! empty($this->_error_log_dir)) { |
|
203 | + if ( ! empty($this->_error_log_dir)) { |
|
204 | 204 | /** @noinspection ForgottenDebugOutputInspection */ |
205 | 205 | error_log($message, 3, $this->_error_log_dir); |
206 | 206 | } else { |
@@ -19,195 +19,195 @@ |
||
19 | 19 | */ |
20 | 20 | class DbSafeDateTime extends DateTime |
21 | 21 | { |
22 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
23 | - /** |
|
24 | - * @type string db_safe_timestamp_format |
|
25 | - */ |
|
26 | - const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
27 | - |
|
28 | - // phpcs:enable |
|
29 | - |
|
30 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
31 | - /** |
|
32 | - * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
33 | - * |
|
34 | - * @type string $_datetime_string |
|
35 | - */ |
|
36 | - protected $_datetime_string = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * where to write the error log to |
|
40 | - * |
|
41 | - * @type string $_error_log_dir |
|
42 | - */ |
|
43 | - protected $_error_log_dir = ''; |
|
44 | - |
|
45 | - // phpcs:enable |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param string $error_log_dir |
|
50 | - */ |
|
51 | - public function setErrorLogDir(string $error_log_dir): void |
|
52 | - { |
|
53 | - // if the folder path is writable, then except the path + filename, else keep empty |
|
54 | - $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
55 | - ? $error_log_dir |
|
56 | - : ''; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function __toString(): string |
|
64 | - { |
|
65 | - return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - public function __sleep(): array |
|
73 | - { |
|
74 | - $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
75 | - $date = DateTime::createFromFormat( |
|
76 | - DbSafeDateTime::db_safe_timestamp_format, |
|
77 | - $this->_datetime_string |
|
78 | - ); |
|
79 | - if (! $date instanceof DateTime) { |
|
80 | - try { |
|
81 | - // we want a stack trace to determine where the malformed date came from, so... |
|
82 | - throw new DomainException(''); |
|
83 | - } catch (DomainException $e) { |
|
84 | - $stack_trace = $e->getTraceAsString(); |
|
85 | - } |
|
86 | - $this->writeToErrorLog( |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - $this->_datetime_string, |
|
93 | - '<br />', |
|
94 | - print_r(DateTime::getLastErrors(), true), |
|
95 | - PHP_VERSION, |
|
96 | - $stack_trace |
|
97 | - ) |
|
98 | - ); |
|
99 | - } |
|
100 | - return ['_datetime_string']; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * if an empty or null value got saved to the db for a datetime, |
|
106 | - * then some servers and/or PHP itself will incorrectly convert that date string |
|
107 | - * resulting in "-0001-11-30" for the year-month-day. |
|
108 | - * see the Notes section |
|
109 | - * |
|
110 | - * @link http://php.net/manual/en/datetime.formats.date.php |
|
111 | - * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
112 | - * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
113 | - * so we're no better off, but at least things won't go fatal on us. |
|
114 | - * @throws Exception |
|
115 | - */ |
|
116 | - public function __wakeup(): void |
|
117 | - { |
|
118 | - $date = self::createFromFormat( |
|
119 | - DbSafeDateTime::db_safe_timestamp_format, |
|
120 | - $this->_datetime_string |
|
121 | - ); |
|
122 | - if (! $date instanceof DateTime) { |
|
123 | - $this->writeToErrorLog( |
|
124 | - sprintf( |
|
125 | - esc_html__( |
|
126 | - 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
127 | - 'event_espresso' |
|
128 | - ), |
|
129 | - $this->_datetime_string, |
|
130 | - '<br />', |
|
131 | - print_r(DateTime::getLastErrors(), true), |
|
132 | - PHP_VERSION |
|
133 | - ) |
|
134 | - ); |
|
135 | - } else { |
|
136 | - $this->__construct( |
|
137 | - $date->format(EE_Datetime_Field::mysql_timestamp_format), |
|
138 | - new DateTimeZone($date->format('e')) |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Normalizes incoming date string so that it is a bit more stable for use. |
|
146 | - * |
|
147 | - * @param string $date_string |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public static function normalizeInvalidDate(string $date_string): string |
|
151 | - { |
|
152 | - return str_replace( |
|
153 | - ['-0001-11-29', '-0001-11-30', '0000-00-00'], |
|
154 | - '0000-01-03', |
|
155 | - $date_string |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Creates a DbSafeDateTime from ye old DateTime |
|
162 | - * |
|
163 | - * @param DateTime $datetime |
|
164 | - * @return DbSafeDateTime |
|
165 | - * @throws Exception |
|
166 | - */ |
|
167 | - public static function createFromDateTime(DateTime $datetime): DbSafeDateTime |
|
168 | - { |
|
169 | - return new DbSafeDateTime( |
|
170 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format), |
|
171 | - new DateTimeZone($datetime->format('e')) |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Parse a string into a new DateTime object according to the specified format |
|
178 | - * |
|
179 | - * @param string $format Format accepted by date(). |
|
180 | - * @param string $time String representing the time. |
|
181 | - * @param DateTimeZone|null $timezone A DateTimeZone object representing the desired time zone. |
|
182 | - * @return DbSafeDateTime|boolean |
|
183 | - * @throws Exception |
|
184 | - * @link https://php.net/manual/en/datetime.createfromformat.php |
|
185 | - */ |
|
186 | - #[\ReturnTypeWillChange] |
|
187 | - public static function createFromFormat($format, $time, ?DateTimeZone $timezone = null) |
|
188 | - { |
|
189 | - $time = self::normalizeInvalidDate($time); |
|
190 | - // Various php versions handle the third argument differently. This conditional accounts for that. |
|
191 | - $DateTime = $timezone instanceof DateTimeZone |
|
192 | - ? parent::createFromFormat($format, $time, $timezone) |
|
193 | - : parent::createFromFormat($format, $time); |
|
194 | - return $DateTime instanceof DateTime |
|
195 | - ? self::createFromDateTime($DateTime) |
|
196 | - : $DateTime; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $message |
|
202 | - */ |
|
203 | - private function writeToErrorLog(string $message) |
|
204 | - { |
|
205 | - if (! empty($this->_error_log_dir)) { |
|
206 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
207 | - error_log($message, 3, $this->_error_log_dir); |
|
208 | - } else { |
|
209 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
210 | - error_log($message); |
|
211 | - } |
|
212 | - } |
|
22 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
23 | + /** |
|
24 | + * @type string db_safe_timestamp_format |
|
25 | + */ |
|
26 | + const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
27 | + |
|
28 | + // phpcs:enable |
|
29 | + |
|
30 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
31 | + /** |
|
32 | + * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
33 | + * |
|
34 | + * @type string $_datetime_string |
|
35 | + */ |
|
36 | + protected $_datetime_string = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * where to write the error log to |
|
40 | + * |
|
41 | + * @type string $_error_log_dir |
|
42 | + */ |
|
43 | + protected $_error_log_dir = ''; |
|
44 | + |
|
45 | + // phpcs:enable |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param string $error_log_dir |
|
50 | + */ |
|
51 | + public function setErrorLogDir(string $error_log_dir): void |
|
52 | + { |
|
53 | + // if the folder path is writable, then except the path + filename, else keep empty |
|
54 | + $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
55 | + ? $error_log_dir |
|
56 | + : ''; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function __toString(): string |
|
64 | + { |
|
65 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + public function __sleep(): array |
|
73 | + { |
|
74 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
75 | + $date = DateTime::createFromFormat( |
|
76 | + DbSafeDateTime::db_safe_timestamp_format, |
|
77 | + $this->_datetime_string |
|
78 | + ); |
|
79 | + if (! $date instanceof DateTime) { |
|
80 | + try { |
|
81 | + // we want a stack trace to determine where the malformed date came from, so... |
|
82 | + throw new DomainException(''); |
|
83 | + } catch (DomainException $e) { |
|
84 | + $stack_trace = $e->getTraceAsString(); |
|
85 | + } |
|
86 | + $this->writeToErrorLog( |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + $this->_datetime_string, |
|
93 | + '<br />', |
|
94 | + print_r(DateTime::getLastErrors(), true), |
|
95 | + PHP_VERSION, |
|
96 | + $stack_trace |
|
97 | + ) |
|
98 | + ); |
|
99 | + } |
|
100 | + return ['_datetime_string']; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * if an empty or null value got saved to the db for a datetime, |
|
106 | + * then some servers and/or PHP itself will incorrectly convert that date string |
|
107 | + * resulting in "-0001-11-30" for the year-month-day. |
|
108 | + * see the Notes section |
|
109 | + * |
|
110 | + * @link http://php.net/manual/en/datetime.formats.date.php |
|
111 | + * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
112 | + * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
113 | + * so we're no better off, but at least things won't go fatal on us. |
|
114 | + * @throws Exception |
|
115 | + */ |
|
116 | + public function __wakeup(): void |
|
117 | + { |
|
118 | + $date = self::createFromFormat( |
|
119 | + DbSafeDateTime::db_safe_timestamp_format, |
|
120 | + $this->_datetime_string |
|
121 | + ); |
|
122 | + if (! $date instanceof DateTime) { |
|
123 | + $this->writeToErrorLog( |
|
124 | + sprintf( |
|
125 | + esc_html__( |
|
126 | + 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
127 | + 'event_espresso' |
|
128 | + ), |
|
129 | + $this->_datetime_string, |
|
130 | + '<br />', |
|
131 | + print_r(DateTime::getLastErrors(), true), |
|
132 | + PHP_VERSION |
|
133 | + ) |
|
134 | + ); |
|
135 | + } else { |
|
136 | + $this->__construct( |
|
137 | + $date->format(EE_Datetime_Field::mysql_timestamp_format), |
|
138 | + new DateTimeZone($date->format('e')) |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Normalizes incoming date string so that it is a bit more stable for use. |
|
146 | + * |
|
147 | + * @param string $date_string |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public static function normalizeInvalidDate(string $date_string): string |
|
151 | + { |
|
152 | + return str_replace( |
|
153 | + ['-0001-11-29', '-0001-11-30', '0000-00-00'], |
|
154 | + '0000-01-03', |
|
155 | + $date_string |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Creates a DbSafeDateTime from ye old DateTime |
|
162 | + * |
|
163 | + * @param DateTime $datetime |
|
164 | + * @return DbSafeDateTime |
|
165 | + * @throws Exception |
|
166 | + */ |
|
167 | + public static function createFromDateTime(DateTime $datetime): DbSafeDateTime |
|
168 | + { |
|
169 | + return new DbSafeDateTime( |
|
170 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format), |
|
171 | + new DateTimeZone($datetime->format('e')) |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Parse a string into a new DateTime object according to the specified format |
|
178 | + * |
|
179 | + * @param string $format Format accepted by date(). |
|
180 | + * @param string $time String representing the time. |
|
181 | + * @param DateTimeZone|null $timezone A DateTimeZone object representing the desired time zone. |
|
182 | + * @return DbSafeDateTime|boolean |
|
183 | + * @throws Exception |
|
184 | + * @link https://php.net/manual/en/datetime.createfromformat.php |
|
185 | + */ |
|
186 | + #[\ReturnTypeWillChange] |
|
187 | + public static function createFromFormat($format, $time, ?DateTimeZone $timezone = null) |
|
188 | + { |
|
189 | + $time = self::normalizeInvalidDate($time); |
|
190 | + // Various php versions handle the third argument differently. This conditional accounts for that. |
|
191 | + $DateTime = $timezone instanceof DateTimeZone |
|
192 | + ? parent::createFromFormat($format, $time, $timezone) |
|
193 | + : parent::createFromFormat($format, $time); |
|
194 | + return $DateTime instanceof DateTime |
|
195 | + ? self::createFromDateTime($DateTime) |
|
196 | + : $DateTime; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $message |
|
202 | + */ |
|
203 | + private function writeToErrorLog(string $message) |
|
204 | + { |
|
205 | + if (! empty($this->_error_log_dir)) { |
|
206 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
207 | + error_log($message, 3, $this->_error_log_dir); |
|
208 | + } else { |
|
209 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
210 | + error_log($message); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -10,243 +10,243 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Message_Repository extends EE_Base_Class_Repository |
12 | 12 | { |
13 | - /** |
|
14 | - * EE_Message_Repository constructor |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - $this->interface = 'EE_Message'; |
|
19 | - parent::__construct(); |
|
20 | - } |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Add the EE_Message to the repository. |
|
25 | - * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
26 | - * |
|
27 | - * @param EE_Message $message |
|
28 | - * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function add($message, $info = ''): bool |
|
32 | - { |
|
33 | - // ensure $info is an array if not already |
|
34 | - $info = (array) $info; |
|
35 | - $attached = parent::add($message); |
|
36 | - $data = $this->_init_data($info, $attached, $message); |
|
37 | - if ($attached) { |
|
38 | - $this->set_info($message, $data); |
|
39 | - } |
|
40 | - return $attached; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Initializes the data from the incoming info. |
|
46 | - * |
|
47 | - * @param array $info incoming data. |
|
48 | - * @param bool $attached Indicates whether the object was attached successfully. |
|
49 | - * @param EE_Message $message |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function _init_data(array $info, bool $attached, EE_Message $message): array |
|
53 | - { |
|
54 | - $data = [ |
|
55 | - 'test_send' => false, |
|
56 | - 'preview' => false, |
|
57 | - 'data_handler_class_name' => '', |
|
58 | - 'data' => [ |
|
59 | - 'MSG_generation_data' => [], |
|
60 | - ], |
|
61 | - ]; |
|
62 | - if (isset($info['preview'])) { |
|
63 | - $data['preview'] = $info['preview']; |
|
64 | - unset($info['preview']); |
|
65 | - } |
|
66 | - if (isset($info['test_send'])) { |
|
67 | - $data['test_send'] = $info['test_send']; |
|
68 | - unset($info['test_send']); |
|
69 | - } |
|
70 | - if (isset($info['data_handler_class_name'])) { |
|
71 | - $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
72 | - unset($info['data_handler_class_name']); |
|
73 | - } |
|
74 | - if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
75 | - $generation_data = $info['MSG_generation_data'] ?? []; |
|
76 | - // if data isn't in $info...let's see if its available via the message object |
|
77 | - $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
78 | - // still empty then let's just use info |
|
79 | - $generation_data = ! $generation_data ? $info : $generation_data; |
|
80 | - $data['data']['MSG_generation_data'] = $generation_data; |
|
81 | - } |
|
82 | - return $data; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Save all EE_Message objects to the db. |
|
88 | - * |
|
89 | - * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
90 | - * @return array [ |
|
91 | - * 'updated' => 0, // count of how many messages updated |
|
92 | - * 'notupdated' => 0, // count of how many messages not updated. |
|
93 | - * 'errors' => array( $token ), // message object tokens that had errors in saving |
|
94 | - * ] |
|
95 | - */ |
|
96 | - public function saveAll(bool $do_hooks_only = false): array |
|
97 | - { |
|
98 | - $save_tracking = ['updated' => 0, 'notupdated' => 0, 'errors' => []]; |
|
99 | - |
|
100 | - if (! $do_hooks_only) { |
|
101 | - $this->rewind(); |
|
102 | - // exit early if there is nothing to save. |
|
103 | - if ($this->count() < 1) { |
|
104 | - return $save_tracking; |
|
105 | - } |
|
106 | - |
|
107 | - while ($this->valid()) { |
|
108 | - $saved = $this->current()->save(); |
|
109 | - if ($saved === false) { |
|
110 | - $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
111 | - } elseif ($saved) { |
|
112 | - $save_tracking['updated']++; |
|
113 | - } else { |
|
114 | - $save_tracking['notupdated']++; |
|
115 | - } |
|
116 | - // maybe persist generation data if this is an incomplete EE_Message. |
|
117 | - $this->_maybe_persist_attached_data(); |
|
118 | - |
|
119 | - $this->next(); |
|
120 | - } |
|
121 | - } |
|
122 | - do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
123 | - return $save_tracking; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Retrieves a EE_Message from the repository that matches the given token. |
|
129 | - * |
|
130 | - * @param string $token Token. |
|
131 | - * @return EE_Message | null |
|
132 | - */ |
|
133 | - public function getMessageByToken(string $token): ?EE_Message |
|
134 | - { |
|
135 | - $this->rewind(); |
|
136 | - while ($this->valid()) { |
|
137 | - if ($this->current()->MSG_token() === $token) { |
|
138 | - $message = $this->current(); |
|
139 | - $this->rewind(); |
|
140 | - return $message; |
|
141 | - } |
|
142 | - $this->next(); |
|
143 | - } |
|
144 | - return null; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
150 | - * |
|
151 | - * @return array(); |
|
152 | - */ |
|
153 | - public function get_generation_data(): array |
|
154 | - { |
|
155 | - // first verify we're at a valid iterator point. |
|
156 | - if (! $this->valid()) { |
|
157 | - return []; |
|
158 | - } |
|
159 | - $info = $this->getInfo(); |
|
160 | - return $info['data']['MSG_generation_data'] ?? []; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function get_data_handler(): string |
|
170 | - { |
|
171 | - if (! $this->valid()) { |
|
172 | - return ''; |
|
173 | - } |
|
174 | - $info = $this->getInfo(); |
|
175 | - return $info['data_handler_class_name'] ?? ''; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Returns whether this EE_Message is for a preview or not. |
|
181 | - * |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - public function is_preview(): bool |
|
185 | - { |
|
186 | - if (! $this->valid()) { |
|
187 | - return false; |
|
188 | - } |
|
189 | - $info = $this->getInfo(); |
|
190 | - return filter_var($info['preview'] ?? false, FILTER_VALIDATE_BOOLEAN); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Returns whether the current message pointed to is for a test send. |
|
196 | - * |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function is_test_send(): bool |
|
200 | - { |
|
201 | - if (! $this->valid()) { |
|
202 | - return false; |
|
203 | - } |
|
204 | - $info = $this->getInfo(); |
|
205 | - return filter_var($info['test_send'] ?? false, FILTER_VALIDATE_BOOLEAN); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
211 | - * data is attached for later retrieval (batch generation). |
|
212 | - */ |
|
213 | - protected function _maybe_persist_attached_data() |
|
214 | - { |
|
215 | - if (! $this->valid()) { |
|
216 | - return; |
|
217 | - } |
|
218 | - |
|
219 | - $info = $this->getInfo(); |
|
220 | - $data_handler_class_name = $info['data_handler_class_name'] ?? ''; |
|
221 | - $data = $info['data']['MSG_generation_data'] ?? []; |
|
222 | - if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
223 | - $this->current()->set_generation_data($data); |
|
224 | - $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * This method returns a count of messages in the repository that have a given priority. |
|
231 | - * |
|
232 | - * @param int $priority the priority that is being filtered for the count. |
|
233 | - * @param array|string|null $status the optional status(es) that will also be filtered by when priority matches. |
|
234 | - * @return int count of messages in the queue matching the conditions. |
|
235 | - */ |
|
236 | - public function count_by_priority_and_status(int $priority, $status = []): int |
|
237 | - { |
|
238 | - $count = 0; |
|
239 | - $status = is_array($status) ? $status : [$status]; |
|
240 | - $this->rewind(); |
|
241 | - while ($this->valid()) { |
|
242 | - if ( |
|
243 | - $this->current()->priority() === $priority |
|
244 | - && (empty($status) || in_array($this->current()->STS_ID(), $status)) |
|
245 | - ) { |
|
246 | - $count++; |
|
247 | - } |
|
248 | - $this->next(); |
|
249 | - } |
|
250 | - return $count; |
|
251 | - } |
|
13 | + /** |
|
14 | + * EE_Message_Repository constructor |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + $this->interface = 'EE_Message'; |
|
19 | + parent::__construct(); |
|
20 | + } |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Add the EE_Message to the repository. |
|
25 | + * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
26 | + * |
|
27 | + * @param EE_Message $message |
|
28 | + * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function add($message, $info = ''): bool |
|
32 | + { |
|
33 | + // ensure $info is an array if not already |
|
34 | + $info = (array) $info; |
|
35 | + $attached = parent::add($message); |
|
36 | + $data = $this->_init_data($info, $attached, $message); |
|
37 | + if ($attached) { |
|
38 | + $this->set_info($message, $data); |
|
39 | + } |
|
40 | + return $attached; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Initializes the data from the incoming info. |
|
46 | + * |
|
47 | + * @param array $info incoming data. |
|
48 | + * @param bool $attached Indicates whether the object was attached successfully. |
|
49 | + * @param EE_Message $message |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function _init_data(array $info, bool $attached, EE_Message $message): array |
|
53 | + { |
|
54 | + $data = [ |
|
55 | + 'test_send' => false, |
|
56 | + 'preview' => false, |
|
57 | + 'data_handler_class_name' => '', |
|
58 | + 'data' => [ |
|
59 | + 'MSG_generation_data' => [], |
|
60 | + ], |
|
61 | + ]; |
|
62 | + if (isset($info['preview'])) { |
|
63 | + $data['preview'] = $info['preview']; |
|
64 | + unset($info['preview']); |
|
65 | + } |
|
66 | + if (isset($info['test_send'])) { |
|
67 | + $data['test_send'] = $info['test_send']; |
|
68 | + unset($info['test_send']); |
|
69 | + } |
|
70 | + if (isset($info['data_handler_class_name'])) { |
|
71 | + $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
72 | + unset($info['data_handler_class_name']); |
|
73 | + } |
|
74 | + if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
75 | + $generation_data = $info['MSG_generation_data'] ?? []; |
|
76 | + // if data isn't in $info...let's see if its available via the message object |
|
77 | + $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
78 | + // still empty then let's just use info |
|
79 | + $generation_data = ! $generation_data ? $info : $generation_data; |
|
80 | + $data['data']['MSG_generation_data'] = $generation_data; |
|
81 | + } |
|
82 | + return $data; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Save all EE_Message objects to the db. |
|
88 | + * |
|
89 | + * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
90 | + * @return array [ |
|
91 | + * 'updated' => 0, // count of how many messages updated |
|
92 | + * 'notupdated' => 0, // count of how many messages not updated. |
|
93 | + * 'errors' => array( $token ), // message object tokens that had errors in saving |
|
94 | + * ] |
|
95 | + */ |
|
96 | + public function saveAll(bool $do_hooks_only = false): array |
|
97 | + { |
|
98 | + $save_tracking = ['updated' => 0, 'notupdated' => 0, 'errors' => []]; |
|
99 | + |
|
100 | + if (! $do_hooks_only) { |
|
101 | + $this->rewind(); |
|
102 | + // exit early if there is nothing to save. |
|
103 | + if ($this->count() < 1) { |
|
104 | + return $save_tracking; |
|
105 | + } |
|
106 | + |
|
107 | + while ($this->valid()) { |
|
108 | + $saved = $this->current()->save(); |
|
109 | + if ($saved === false) { |
|
110 | + $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
111 | + } elseif ($saved) { |
|
112 | + $save_tracking['updated']++; |
|
113 | + } else { |
|
114 | + $save_tracking['notupdated']++; |
|
115 | + } |
|
116 | + // maybe persist generation data if this is an incomplete EE_Message. |
|
117 | + $this->_maybe_persist_attached_data(); |
|
118 | + |
|
119 | + $this->next(); |
|
120 | + } |
|
121 | + } |
|
122 | + do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
123 | + return $save_tracking; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Retrieves a EE_Message from the repository that matches the given token. |
|
129 | + * |
|
130 | + * @param string $token Token. |
|
131 | + * @return EE_Message | null |
|
132 | + */ |
|
133 | + public function getMessageByToken(string $token): ?EE_Message |
|
134 | + { |
|
135 | + $this->rewind(); |
|
136 | + while ($this->valid()) { |
|
137 | + if ($this->current()->MSG_token() === $token) { |
|
138 | + $message = $this->current(); |
|
139 | + $this->rewind(); |
|
140 | + return $message; |
|
141 | + } |
|
142 | + $this->next(); |
|
143 | + } |
|
144 | + return null; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
150 | + * |
|
151 | + * @return array(); |
|
152 | + */ |
|
153 | + public function get_generation_data(): array |
|
154 | + { |
|
155 | + // first verify we're at a valid iterator point. |
|
156 | + if (! $this->valid()) { |
|
157 | + return []; |
|
158 | + } |
|
159 | + $info = $this->getInfo(); |
|
160 | + return $info['data']['MSG_generation_data'] ?? []; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function get_data_handler(): string |
|
170 | + { |
|
171 | + if (! $this->valid()) { |
|
172 | + return ''; |
|
173 | + } |
|
174 | + $info = $this->getInfo(); |
|
175 | + return $info['data_handler_class_name'] ?? ''; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Returns whether this EE_Message is for a preview or not. |
|
181 | + * |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + public function is_preview(): bool |
|
185 | + { |
|
186 | + if (! $this->valid()) { |
|
187 | + return false; |
|
188 | + } |
|
189 | + $info = $this->getInfo(); |
|
190 | + return filter_var($info['preview'] ?? false, FILTER_VALIDATE_BOOLEAN); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Returns whether the current message pointed to is for a test send. |
|
196 | + * |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function is_test_send(): bool |
|
200 | + { |
|
201 | + if (! $this->valid()) { |
|
202 | + return false; |
|
203 | + } |
|
204 | + $info = $this->getInfo(); |
|
205 | + return filter_var($info['test_send'] ?? false, FILTER_VALIDATE_BOOLEAN); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
211 | + * data is attached for later retrieval (batch generation). |
|
212 | + */ |
|
213 | + protected function _maybe_persist_attached_data() |
|
214 | + { |
|
215 | + if (! $this->valid()) { |
|
216 | + return; |
|
217 | + } |
|
218 | + |
|
219 | + $info = $this->getInfo(); |
|
220 | + $data_handler_class_name = $info['data_handler_class_name'] ?? ''; |
|
221 | + $data = $info['data']['MSG_generation_data'] ?? []; |
|
222 | + if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
223 | + $this->current()->set_generation_data($data); |
|
224 | + $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * This method returns a count of messages in the repository that have a given priority. |
|
231 | + * |
|
232 | + * @param int $priority the priority that is being filtered for the count. |
|
233 | + * @param array|string|null $status the optional status(es) that will also be filtered by when priority matches. |
|
234 | + * @return int count of messages in the queue matching the conditions. |
|
235 | + */ |
|
236 | + public function count_by_priority_and_status(int $priority, $status = []): int |
|
237 | + { |
|
238 | + $count = 0; |
|
239 | + $status = is_array($status) ? $status : [$status]; |
|
240 | + $this->rewind(); |
|
241 | + while ($this->valid()) { |
|
242 | + if ( |
|
243 | + $this->current()->priority() === $priority |
|
244 | + && (empty($status) || in_array($this->current()->STS_ID(), $status)) |
|
245 | + ) { |
|
246 | + $count++; |
|
247 | + } |
|
248 | + $this->next(); |
|
249 | + } |
|
250 | + return $count; |
|
251 | + } |
|
252 | 252 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | $save_tracking = ['updated' => 0, 'notupdated' => 0, 'errors' => []]; |
99 | 99 | |
100 | - if (! $do_hooks_only) { |
|
100 | + if ( ! $do_hooks_only) { |
|
101 | 101 | $this->rewind(); |
102 | 102 | // exit early if there is nothing to save. |
103 | 103 | if ($this->count() < 1) { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | public function get_generation_data(): array |
154 | 154 | { |
155 | 155 | // first verify we're at a valid iterator point. |
156 | - if (! $this->valid()) { |
|
156 | + if ( ! $this->valid()) { |
|
157 | 157 | return []; |
158 | 158 | } |
159 | 159 | $info = $this->getInfo(); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function get_data_handler(): string |
170 | 170 | { |
171 | - if (! $this->valid()) { |
|
171 | + if ( ! $this->valid()) { |
|
172 | 172 | return ''; |
173 | 173 | } |
174 | 174 | $info = $this->getInfo(); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function is_preview(): bool |
185 | 185 | { |
186 | - if (! $this->valid()) { |
|
186 | + if ( ! $this->valid()) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | $info = $this->getInfo(); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function is_test_send(): bool |
200 | 200 | { |
201 | - if (! $this->valid()) { |
|
201 | + if ( ! $this->valid()) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | $info = $this->getInfo(); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function _maybe_persist_attached_data() |
214 | 214 | { |
215 | - if (! $this->valid()) { |
|
215 | + if ( ! $this->valid()) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 |