@@ -12,85 +12,85 @@ |
||
12 | 12 | */ |
13 | 13 | interface EncryptionKeyManagerInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * add an encryption key |
|
17 | - * |
|
18 | - * @param string $encryption_key_identifier - name of the encryption key to use |
|
19 | - * @param string $encryption_key - cryptographically secure passphrase. will generate if necessary |
|
20 | - * @param bool $overwrite - prevents accidental overwriting of an existing key which would be bad |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false); |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * returns true if encryption key has already been generated |
|
28 | - * |
|
29 | - * @param string $encryption_key_identifier - encryption key name |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function encryptionKeyExists($encryption_key_identifier = ''); |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * returns cryptographically secure passphrase. will use default if necessary |
|
37 | - * |
|
38 | - * @param string $encryption_key_identifier - encryption key name. will use default if necessary |
|
39 | - * @param bool $generate - will generate a new key if the requested one does not exist |
|
40 | - * @param bool $throw_exception - if TRUE (default), will throw an exception if key is not found |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function getEncryptionKey($encryption_key_identifier = '', $generate = false, $throw_exception = true); |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * creates a new encryption key |
|
48 | - * |
|
49 | - * @param bool $strong if true (default) will attempt to generate a cryptographically secure key |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function generateEncryptionKey($strong = true); |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - public function bitDepth(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @param int $bit_depth options are 64, 128, 192, or 256 |
|
63 | - */ |
|
64 | - public function setBitDepth($bit_depth); |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function keyLength(); |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param int $key_length |
|
75 | - */ |
|
76 | - public function setKeyLength($key_length); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * deletes ALL existing encryption keys from the db |
|
81 | - * |
|
82 | - * @return bool true if keys successfully deleted, false otherwise. |
|
83 | - */ |
|
84 | - public function removeAllEncryptionKeys(); |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * deletes an existing encryption key from those saved in the db |
|
89 | - * |
|
90 | - * @param string $encryption_key_identifier encryption key name |
|
91 | - * @return int 1: key removed successfully. |
|
92 | - * 0: key did not exist. |
|
93 | - * -1: failed to remove key |
|
94 | - */ |
|
95 | - public function removeEncryptionKey($encryption_key_identifier = ''); |
|
15 | + /** |
|
16 | + * add an encryption key |
|
17 | + * |
|
18 | + * @param string $encryption_key_identifier - name of the encryption key to use |
|
19 | + * @param string $encryption_key - cryptographically secure passphrase. will generate if necessary |
|
20 | + * @param bool $overwrite - prevents accidental overwriting of an existing key which would be bad |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false); |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * returns true if encryption key has already been generated |
|
28 | + * |
|
29 | + * @param string $encryption_key_identifier - encryption key name |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function encryptionKeyExists($encryption_key_identifier = ''); |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * returns cryptographically secure passphrase. will use default if necessary |
|
37 | + * |
|
38 | + * @param string $encryption_key_identifier - encryption key name. will use default if necessary |
|
39 | + * @param bool $generate - will generate a new key if the requested one does not exist |
|
40 | + * @param bool $throw_exception - if TRUE (default), will throw an exception if key is not found |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function getEncryptionKey($encryption_key_identifier = '', $generate = false, $throw_exception = true); |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * creates a new encryption key |
|
48 | + * |
|
49 | + * @param bool $strong if true (default) will attempt to generate a cryptographically secure key |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function generateEncryptionKey($strong = true); |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + public function bitDepth(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @param int $bit_depth options are 64, 128, 192, or 256 |
|
63 | + */ |
|
64 | + public function setBitDepth($bit_depth); |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function keyLength(); |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param int $key_length |
|
75 | + */ |
|
76 | + public function setKeyLength($key_length); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * deletes ALL existing encryption keys from the db |
|
81 | + * |
|
82 | + * @return bool true if keys successfully deleted, false otherwise. |
|
83 | + */ |
|
84 | + public function removeAllEncryptionKeys(); |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * deletes an existing encryption key from those saved in the db |
|
89 | + * |
|
90 | + * @param string $encryption_key_identifier encryption key name |
|
91 | + * @return int 1: key removed successfully. |
|
92 | + * 0: key did not exist. |
|
93 | + * -1: failed to remove key |
|
94 | + */ |
|
95 | + public function removeEncryptionKey($encryption_key_identifier = ''); |
|
96 | 96 | } |
@@ -16,301 +16,301 @@ |
||
16 | 16 | */ |
17 | 17 | class EncryptionKeyManager implements EncryptionKeyManagerInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Base64Encoder |
|
21 | - */ |
|
22 | - protected $base64_encoder; |
|
23 | - |
|
24 | - /** |
|
25 | - * name used for a default encryption key in case no others are set |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private $default_encryption_key_id; |
|
30 | - |
|
31 | - /** |
|
32 | - * name used for saving encryption keys to the wp_options table |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $encryption_keys_option_name; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - private $encryption_keys = null; |
|
42 | - |
|
43 | - /** |
|
44 | - * number of bits used when generating cryptographically secure keys |
|
45 | - * |
|
46 | - * @var int |
|
47 | - */ |
|
48 | - private $bit_depth = 128; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var int[] |
|
52 | - */ |
|
53 | - private $bit_depth_options = [64, 128, 192, 256]; |
|
54 | - |
|
55 | - /** |
|
56 | - * number of characters used when generating cryptographically weak keys |
|
57 | - * |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - private $key_length = 40; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param Base64Encoder $base64_encoder |
|
65 | - * @param string $default_encryption_key_id |
|
66 | - * @param string $encryption_keys_option_name |
|
67 | - */ |
|
68 | - public function __construct(Base64Encoder $base64_encoder, $default_encryption_key_id, $encryption_keys_option_name) |
|
69 | - { |
|
70 | - $this->base64_encoder = $base64_encoder; |
|
71 | - $this->default_encryption_key_id = $default_encryption_key_id; |
|
72 | - $this->encryption_keys_option_name = $encryption_keys_option_name; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * add an encryption key |
|
78 | - * |
|
79 | - * @param string $encryption_key_identifier - name of the encryption key to use |
|
80 | - * @param string $encryption_key - cryptographically secure passphrase. will generate if necessary |
|
81 | - * @param bool $overwrite - prevents accidental overwriting of an existing key which would be bad |
|
82 | - * @return bool |
|
83 | - * @throws Exception |
|
84 | - */ |
|
85 | - public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false) |
|
86 | - { |
|
87 | - $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id; |
|
88 | - if ($this->encryptionKeyExists($encryption_key_identifier) && ! $overwrite) { |
|
89 | - // WOAH!!! that key already exists and we don't want to overwrite it |
|
90 | - throw new RuntimeException( |
|
91 | - sprintf( |
|
92 | - esc_html__( |
|
93 | - 'The "%1$s" encryption key already exists and can not be overwritten because previously encrypted values would no longer be capable of being decrypted.', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - $encryption_key_identifier |
|
97 | - ) |
|
98 | - ); |
|
99 | - } |
|
100 | - $this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey(); |
|
101 | - return $this->saveEncryptionKeys(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * returns true if encryption key has already been generated |
|
107 | - * |
|
108 | - * @param string $encryption_key_identifier - encryption key name |
|
109 | - * @return bool |
|
110 | - * @throws Exception |
|
111 | - * @throws OutOfBoundsException |
|
112 | - */ |
|
113 | - public function encryptionKeyExists($encryption_key_identifier = '') |
|
114 | - { |
|
115 | - // ensure keys are loaded |
|
116 | - $this->retrieveEncryptionKeys(); |
|
117 | - return isset($this->encryption_keys[ $encryption_key_identifier ]); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * returns cryptographically secure passphrase. will use default if necessary |
|
123 | - * |
|
124 | - * @param string $encryption_key_identifier - encryption key name. will use default if necessary |
|
125 | - * @param bool $generate - will generate a new key if the requested one does not exist |
|
126 | - * @param bool $throw_exception - if TRUE (default), will throw an exception if key is not found |
|
127 | - * @return string |
|
128 | - * @throws Exception |
|
129 | - */ |
|
130 | - public function getEncryptionKey($encryption_key_identifier = '', $generate = true, $throw_exception = true) |
|
131 | - { |
|
132 | - $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id; |
|
133 | - // if encryption key has not been set |
|
134 | - if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
135 | - if ($generate) { |
|
136 | - $this->addEncryptionKey($encryption_key_identifier); |
|
137 | - } else { |
|
138 | - if (! $throw_exception) { |
|
139 | - return ''; |
|
140 | - } |
|
141 | - throw new OutOfBoundsException( |
|
142 | - sprintf( |
|
143 | - esc_html__('The "%1$s" encryption key was not found or is invalid.', 'event_espresso'), |
|
144 | - $encryption_key_identifier |
|
145 | - ) |
|
146 | - ); |
|
147 | - } |
|
148 | - } |
|
149 | - return $this->encryption_keys[ $encryption_key_identifier ]; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * creates a new encryption key |
|
155 | - * |
|
156 | - * @param bool $strong if true (default) will attempt to generate a cryptographically secure key |
|
157 | - * @return string |
|
158 | - * @throws Exception |
|
159 | - */ |
|
160 | - public function generateEncryptionKey($strong = true) |
|
161 | - { |
|
162 | - return $strong && PHP_VERSION_ID >= 70100 |
|
163 | - ? $this->generateStrongEncryptionKey() |
|
164 | - : $this->generateWeakEncryptionKey(); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * creates a new cryptographically secure encryption key |
|
170 | - * |
|
171 | - * @return string |
|
172 | - * @throws Exception |
|
173 | - */ |
|
174 | - protected function generateStrongEncryptionKey() |
|
175 | - { |
|
176 | - // bit_depth needs to be divided by 8 to convert to bytes |
|
177 | - return $this->base64_encoder->encodeString(random_bytes($this->bit_depth / 8)); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * creates a new encryption key that should not be trusted to be cryptographically secure |
|
183 | - * |
|
184 | - * @return string |
|
185 | - * @throws Exception |
|
186 | - */ |
|
187 | - protected function generateWeakEncryptionKey() |
|
188 | - { |
|
189 | - // @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
190 | - $iterations = ceil($this->key_length / 40); |
|
191 | - $random_string = ''; |
|
192 | - for ($i = 0; $i < $iterations; $i++) { |
|
193 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
194 | - } |
|
195 | - $random_string = (string) substr($random_string, 0, $this->key_length); |
|
196 | - return $this->base64_encoder->encodeString($random_string); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return int |
|
202 | - */ |
|
203 | - public function bitDepth() |
|
204 | - { |
|
205 | - return $this->bit_depth; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @param int $bit_depth options are 64, 128, 192, or 256 |
|
211 | - */ |
|
212 | - public function setBitDepth($bit_depth) |
|
213 | - { |
|
214 | - $bit_depth = absint($bit_depth); |
|
215 | - $this->bit_depth = in_array($bit_depth, $this->bit_depth_options, true) ? $bit_depth : 128; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @return int |
|
221 | - */ |
|
222 | - public function keyLength() |
|
223 | - { |
|
224 | - return $this->key_length; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @param int $key_length |
|
230 | - */ |
|
231 | - public function setKeyLength($key_length) |
|
232 | - { |
|
233 | - // let's not let the key length go below 8 or above 128 |
|
234 | - $this->key_length = min(max(absint($key_length), 8), 128); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * deletes ALL existing encryption keys from the db |
|
240 | - * |
|
241 | - * @return bool true if keys successfully deleted, false otherwise. |
|
242 | - */ |
|
243 | - public function removeAllEncryptionKeys() |
|
244 | - { |
|
245 | - return delete_option($this->encryption_keys_option_name); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * deletes an existing encryption key from those saved in the db |
|
251 | - * |
|
252 | - * @param string $encryption_key_identifier encryption key name |
|
253 | - * @return int 1: key removed successfully. |
|
254 | - * 0: key did not exist. |
|
255 | - * -1: failed to remove key |
|
256 | - * @throws Exception |
|
257 | - */ |
|
258 | - public function removeEncryptionKey($encryption_key_identifier = '') |
|
259 | - { |
|
260 | - // if encryption key has not been set |
|
261 | - if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
262 | - return 0; |
|
263 | - } |
|
264 | - unset($this->encryption_keys[ $encryption_key_identifier ]); |
|
265 | - return $this->saveEncryptionKeys() ? 1 : -1; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * retrieves encryption keys from db |
|
271 | - * |
|
272 | - * @return array |
|
273 | - * @throws Exception |
|
274 | - * @throws RuntimeException |
|
275 | - */ |
|
276 | - protected function retrieveEncryptionKeys() |
|
277 | - { |
|
278 | - // if encryption key has not been set |
|
279 | - if (empty($this->encryption_keys)) { |
|
280 | - // retrieve encryption_key from db |
|
281 | - $this->encryption_keys = get_option($this->encryption_keys_option_name, null); |
|
282 | - // WHAT?? No encryption keys in the db ?? |
|
283 | - if ($this->encryption_keys === null) { |
|
284 | - $this->encryption_keys = []; |
|
285 | - // let's create the default key and save it |
|
286 | - $new_key = $this->generateEncryptionKey(); |
|
287 | - $this->encryption_keys[ $this->default_encryption_key_id ] = $new_key; |
|
288 | - if (! $this->saveEncryptionKeys(true)) { |
|
289 | - throw new RuntimeException( |
|
290 | - sprintf( |
|
291 | - esc_html__( |
|
292 | - 'Failed to save the "%1$s" encryption keys array to the database.', |
|
293 | - 'event_espresso' |
|
294 | - ), |
|
295 | - $this->encryption_keys_option_name |
|
296 | - ) |
|
297 | - ); |
|
298 | - } |
|
299 | - } |
|
300 | - } |
|
301 | - return $this->encryption_keys; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * saves encryption keys from db |
|
307 | - * |
|
308 | - * @return bool |
|
309 | - */ |
|
310 | - protected function saveEncryptionKeys($initialize = false) |
|
311 | - { |
|
312 | - return $initialize |
|
313 | - ? add_option($this->encryption_keys_option_name, $this->encryption_keys, '', false) |
|
314 | - : update_option($this->encryption_keys_option_name, $this->encryption_keys, false); |
|
315 | - } |
|
19 | + /** |
|
20 | + * @var Base64Encoder |
|
21 | + */ |
|
22 | + protected $base64_encoder; |
|
23 | + |
|
24 | + /** |
|
25 | + * name used for a default encryption key in case no others are set |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private $default_encryption_key_id; |
|
30 | + |
|
31 | + /** |
|
32 | + * name used for saving encryption keys to the wp_options table |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $encryption_keys_option_name; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + private $encryption_keys = null; |
|
42 | + |
|
43 | + /** |
|
44 | + * number of bits used when generating cryptographically secure keys |
|
45 | + * |
|
46 | + * @var int |
|
47 | + */ |
|
48 | + private $bit_depth = 128; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var int[] |
|
52 | + */ |
|
53 | + private $bit_depth_options = [64, 128, 192, 256]; |
|
54 | + |
|
55 | + /** |
|
56 | + * number of characters used when generating cryptographically weak keys |
|
57 | + * |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + private $key_length = 40; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param Base64Encoder $base64_encoder |
|
65 | + * @param string $default_encryption_key_id |
|
66 | + * @param string $encryption_keys_option_name |
|
67 | + */ |
|
68 | + public function __construct(Base64Encoder $base64_encoder, $default_encryption_key_id, $encryption_keys_option_name) |
|
69 | + { |
|
70 | + $this->base64_encoder = $base64_encoder; |
|
71 | + $this->default_encryption_key_id = $default_encryption_key_id; |
|
72 | + $this->encryption_keys_option_name = $encryption_keys_option_name; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * add an encryption key |
|
78 | + * |
|
79 | + * @param string $encryption_key_identifier - name of the encryption key to use |
|
80 | + * @param string $encryption_key - cryptographically secure passphrase. will generate if necessary |
|
81 | + * @param bool $overwrite - prevents accidental overwriting of an existing key which would be bad |
|
82 | + * @return bool |
|
83 | + * @throws Exception |
|
84 | + */ |
|
85 | + public function addEncryptionKey($encryption_key_identifier, $encryption_key = '', $overwrite = false) |
|
86 | + { |
|
87 | + $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id; |
|
88 | + if ($this->encryptionKeyExists($encryption_key_identifier) && ! $overwrite) { |
|
89 | + // WOAH!!! that key already exists and we don't want to overwrite it |
|
90 | + throw new RuntimeException( |
|
91 | + sprintf( |
|
92 | + esc_html__( |
|
93 | + 'The "%1$s" encryption key already exists and can not be overwritten because previously encrypted values would no longer be capable of being decrypted.', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + $encryption_key_identifier |
|
97 | + ) |
|
98 | + ); |
|
99 | + } |
|
100 | + $this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey(); |
|
101 | + return $this->saveEncryptionKeys(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * returns true if encryption key has already been generated |
|
107 | + * |
|
108 | + * @param string $encryption_key_identifier - encryption key name |
|
109 | + * @return bool |
|
110 | + * @throws Exception |
|
111 | + * @throws OutOfBoundsException |
|
112 | + */ |
|
113 | + public function encryptionKeyExists($encryption_key_identifier = '') |
|
114 | + { |
|
115 | + // ensure keys are loaded |
|
116 | + $this->retrieveEncryptionKeys(); |
|
117 | + return isset($this->encryption_keys[ $encryption_key_identifier ]); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * returns cryptographically secure passphrase. will use default if necessary |
|
123 | + * |
|
124 | + * @param string $encryption_key_identifier - encryption key name. will use default if necessary |
|
125 | + * @param bool $generate - will generate a new key if the requested one does not exist |
|
126 | + * @param bool $throw_exception - if TRUE (default), will throw an exception if key is not found |
|
127 | + * @return string |
|
128 | + * @throws Exception |
|
129 | + */ |
|
130 | + public function getEncryptionKey($encryption_key_identifier = '', $generate = true, $throw_exception = true) |
|
131 | + { |
|
132 | + $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id; |
|
133 | + // if encryption key has not been set |
|
134 | + if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
135 | + if ($generate) { |
|
136 | + $this->addEncryptionKey($encryption_key_identifier); |
|
137 | + } else { |
|
138 | + if (! $throw_exception) { |
|
139 | + return ''; |
|
140 | + } |
|
141 | + throw new OutOfBoundsException( |
|
142 | + sprintf( |
|
143 | + esc_html__('The "%1$s" encryption key was not found or is invalid.', 'event_espresso'), |
|
144 | + $encryption_key_identifier |
|
145 | + ) |
|
146 | + ); |
|
147 | + } |
|
148 | + } |
|
149 | + return $this->encryption_keys[ $encryption_key_identifier ]; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * creates a new encryption key |
|
155 | + * |
|
156 | + * @param bool $strong if true (default) will attempt to generate a cryptographically secure key |
|
157 | + * @return string |
|
158 | + * @throws Exception |
|
159 | + */ |
|
160 | + public function generateEncryptionKey($strong = true) |
|
161 | + { |
|
162 | + return $strong && PHP_VERSION_ID >= 70100 |
|
163 | + ? $this->generateStrongEncryptionKey() |
|
164 | + : $this->generateWeakEncryptionKey(); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * creates a new cryptographically secure encryption key |
|
170 | + * |
|
171 | + * @return string |
|
172 | + * @throws Exception |
|
173 | + */ |
|
174 | + protected function generateStrongEncryptionKey() |
|
175 | + { |
|
176 | + // bit_depth needs to be divided by 8 to convert to bytes |
|
177 | + return $this->base64_encoder->encodeString(random_bytes($this->bit_depth / 8)); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * creates a new encryption key that should not be trusted to be cryptographically secure |
|
183 | + * |
|
184 | + * @return string |
|
185 | + * @throws Exception |
|
186 | + */ |
|
187 | + protected function generateWeakEncryptionKey() |
|
188 | + { |
|
189 | + // @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
190 | + $iterations = ceil($this->key_length / 40); |
|
191 | + $random_string = ''; |
|
192 | + for ($i = 0; $i < $iterations; $i++) { |
|
193 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
194 | + } |
|
195 | + $random_string = (string) substr($random_string, 0, $this->key_length); |
|
196 | + return $this->base64_encoder->encodeString($random_string); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return int |
|
202 | + */ |
|
203 | + public function bitDepth() |
|
204 | + { |
|
205 | + return $this->bit_depth; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @param int $bit_depth options are 64, 128, 192, or 256 |
|
211 | + */ |
|
212 | + public function setBitDepth($bit_depth) |
|
213 | + { |
|
214 | + $bit_depth = absint($bit_depth); |
|
215 | + $this->bit_depth = in_array($bit_depth, $this->bit_depth_options, true) ? $bit_depth : 128; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @return int |
|
221 | + */ |
|
222 | + public function keyLength() |
|
223 | + { |
|
224 | + return $this->key_length; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @param int $key_length |
|
230 | + */ |
|
231 | + public function setKeyLength($key_length) |
|
232 | + { |
|
233 | + // let's not let the key length go below 8 or above 128 |
|
234 | + $this->key_length = min(max(absint($key_length), 8), 128); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * deletes ALL existing encryption keys from the db |
|
240 | + * |
|
241 | + * @return bool true if keys successfully deleted, false otherwise. |
|
242 | + */ |
|
243 | + public function removeAllEncryptionKeys() |
|
244 | + { |
|
245 | + return delete_option($this->encryption_keys_option_name); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * deletes an existing encryption key from those saved in the db |
|
251 | + * |
|
252 | + * @param string $encryption_key_identifier encryption key name |
|
253 | + * @return int 1: key removed successfully. |
|
254 | + * 0: key did not exist. |
|
255 | + * -1: failed to remove key |
|
256 | + * @throws Exception |
|
257 | + */ |
|
258 | + public function removeEncryptionKey($encryption_key_identifier = '') |
|
259 | + { |
|
260 | + // if encryption key has not been set |
|
261 | + if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
262 | + return 0; |
|
263 | + } |
|
264 | + unset($this->encryption_keys[ $encryption_key_identifier ]); |
|
265 | + return $this->saveEncryptionKeys() ? 1 : -1; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * retrieves encryption keys from db |
|
271 | + * |
|
272 | + * @return array |
|
273 | + * @throws Exception |
|
274 | + * @throws RuntimeException |
|
275 | + */ |
|
276 | + protected function retrieveEncryptionKeys() |
|
277 | + { |
|
278 | + // if encryption key has not been set |
|
279 | + if (empty($this->encryption_keys)) { |
|
280 | + // retrieve encryption_key from db |
|
281 | + $this->encryption_keys = get_option($this->encryption_keys_option_name, null); |
|
282 | + // WHAT?? No encryption keys in the db ?? |
|
283 | + if ($this->encryption_keys === null) { |
|
284 | + $this->encryption_keys = []; |
|
285 | + // let's create the default key and save it |
|
286 | + $new_key = $this->generateEncryptionKey(); |
|
287 | + $this->encryption_keys[ $this->default_encryption_key_id ] = $new_key; |
|
288 | + if (! $this->saveEncryptionKeys(true)) { |
|
289 | + throw new RuntimeException( |
|
290 | + sprintf( |
|
291 | + esc_html__( |
|
292 | + 'Failed to save the "%1$s" encryption keys array to the database.', |
|
293 | + 'event_espresso' |
|
294 | + ), |
|
295 | + $this->encryption_keys_option_name |
|
296 | + ) |
|
297 | + ); |
|
298 | + } |
|
299 | + } |
|
300 | + } |
|
301 | + return $this->encryption_keys; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * saves encryption keys from db |
|
307 | + * |
|
308 | + * @return bool |
|
309 | + */ |
|
310 | + protected function saveEncryptionKeys($initialize = false) |
|
311 | + { |
|
312 | + return $initialize |
|
313 | + ? add_option($this->encryption_keys_option_name, $this->encryption_keys, '', false) |
|
314 | + : update_option($this->encryption_keys_option_name, $this->encryption_keys, false); |
|
315 | + } |
|
316 | 316 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | } |
100 | - $this->encryption_keys[ $encryption_key_identifier ] = $encryption_key ?: $this->generateEncryptionKey(); |
|
100 | + $this->encryption_keys[$encryption_key_identifier] = $encryption_key ?: $this->generateEncryptionKey(); |
|
101 | 101 | return $this->saveEncryptionKeys(); |
102 | 102 | } |
103 | 103 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | { |
115 | 115 | // ensure keys are loaded |
116 | 116 | $this->retrieveEncryptionKeys(); |
117 | - return isset($this->encryption_keys[ $encryption_key_identifier ]); |
|
117 | + return isset($this->encryption_keys[$encryption_key_identifier]); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | { |
132 | 132 | $encryption_key_identifier = $encryption_key_identifier ?: $this->default_encryption_key_id; |
133 | 133 | // if encryption key has not been set |
134 | - if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
134 | + if ( ! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
135 | 135 | if ($generate) { |
136 | 136 | $this->addEncryptionKey($encryption_key_identifier); |
137 | 137 | } else { |
138 | - if (! $throw_exception) { |
|
138 | + if ( ! $throw_exception) { |
|
139 | 139 | return ''; |
140 | 140 | } |
141 | 141 | throw new OutOfBoundsException( |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | } |
149 | - return $this->encryption_keys[ $encryption_key_identifier ]; |
|
149 | + return $this->encryption_keys[$encryption_key_identifier]; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $iterations = ceil($this->key_length / 40); |
191 | 191 | $random_string = ''; |
192 | 192 | for ($i = 0; $i < $iterations; $i++) { |
193 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
193 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
194 | 194 | } |
195 | 195 | $random_string = (string) substr($random_string, 0, $this->key_length); |
196 | 196 | return $this->base64_encoder->encodeString($random_string); |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | public function removeEncryptionKey($encryption_key_identifier = '') |
259 | 259 | { |
260 | 260 | // if encryption key has not been set |
261 | - if (! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
261 | + if ( ! $this->encryptionKeyExists($encryption_key_identifier)) { |
|
262 | 262 | return 0; |
263 | 263 | } |
264 | - unset($this->encryption_keys[ $encryption_key_identifier ]); |
|
264 | + unset($this->encryption_keys[$encryption_key_identifier]); |
|
265 | 265 | return $this->saveEncryptionKeys() ? 1 : -1; |
266 | 266 | } |
267 | 267 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | $this->encryption_keys = []; |
285 | 285 | // let's create the default key and save it |
286 | 286 | $new_key = $this->generateEncryptionKey(); |
287 | - $this->encryption_keys[ $this->default_encryption_key_id ] = $new_key; |
|
288 | - if (! $this->saveEncryptionKeys(true)) { |
|
287 | + $this->encryption_keys[$this->default_encryption_key_id] = $new_key; |
|
288 | + if ( ! $this->saveEncryptionKeys(true)) { |
|
289 | 289 | throw new RuntimeException( |
290 | 290 | sprintf( |
291 | 291 | esc_html__( |
@@ -13,20 +13,20 @@ |
||
13 | 13 | <?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?> |
14 | 14 | <span class="comments-link"> |
15 | 15 | <?php comments_popup_link( |
16 | - esc_html__( 'Leave a comment', 'event_espresso' ), |
|
17 | - esc_html__( '1 Comment', 'event_espresso' ), |
|
18 | - esc_html__( '% Comments', 'event_espresso' ) |
|
19 | - ); ?> |
|
16 | + esc_html__( 'Leave a comment', 'event_espresso' ), |
|
17 | + esc_html__( '1 Comment', 'event_espresso' ), |
|
18 | + esc_html__( '% Comments', 'event_espresso' ) |
|
19 | + ); ?> |
|
20 | 20 | </span> |
21 | 21 | |
22 | 22 | <?php |
23 | - endif; |
|
24 | - edit_post_link( |
|
25 | - esc_html__( 'Edit', 'event_espresso' ), |
|
26 | - '<span class="edit-link">', |
|
27 | - '</span>' |
|
28 | - ); |
|
29 | - ?> |
|
23 | + endif; |
|
24 | + edit_post_link( |
|
25 | + esc_html__( 'Edit', 'event_espresso' ), |
|
26 | + '<span class="edit-link">', |
|
27 | + '</span>' |
|
28 | + ); |
|
29 | + ?> |
|
30 | 30 | </div> |
31 | 31 | |
32 | 32 | <?php endif; |
@@ -4,27 +4,27 @@ discard block |
||
4 | 4 | <div class="event-content"> |
5 | 5 | <?php use EventEspresso\core\services\request\sanitizers\AllowedTags; |
6 | 6 | |
7 | -if ( apply_filters( 'FHEE__content_espresso_events_details_template__display_entry_meta', TRUE )): ?> |
|
7 | +if (apply_filters('FHEE__content_espresso_events_details_template__display_entry_meta', TRUE)): ?> |
|
8 | 8 | |
9 | 9 | <div class="entry-meta"> |
10 | 10 | |
11 | 11 | <span class="tags-links"> |
12 | - <?php espresso_event_categories( $post->ID, TRUE, TRUE ); ?> |
|
12 | + <?php espresso_event_categories($post->ID, TRUE, TRUE); ?> |
|
13 | 13 | </span> |
14 | 14 | |
15 | - <?php if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?> |
|
15 | + <?php if ( ! post_password_required() && (comments_open() || get_comments_number())) : ?> |
|
16 | 16 | <span class="comments-link"> |
17 | 17 | <?php comments_popup_link( |
18 | - esc_html__( 'Leave a comment', 'event_espresso' ), |
|
19 | - esc_html__( '1 Comment', 'event_espresso' ), |
|
20 | - esc_html__( '% Comments', 'event_espresso' ) |
|
18 | + esc_html__('Leave a comment', 'event_espresso'), |
|
19 | + esc_html__('1 Comment', 'event_espresso'), |
|
20 | + esc_html__('% Comments', 'event_espresso') |
|
21 | 21 | ); ?> |
22 | 22 | </span> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | endif; |
26 | 26 | edit_post_link( |
27 | - esc_html__( 'Edit', 'event_espresso' ), |
|
27 | + esc_html__('Edit', 'event_espresso'), |
|
28 | 28 | '<span class="edit-link">', |
29 | 29 | '</span>' |
30 | 30 | ); |
@@ -32,25 +32,25 @@ discard block |
||
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <?php endif; |
35 | - $event_phone = espresso_event_phone( $post->ID, FALSE ); |
|
35 | + $event_phone = espresso_event_phone($post->ID, FALSE); |
|
36 | 36 | |
37 | - if ( $event_phone != '' ) : ?> |
|
37 | + if ($event_phone != '') : ?> |
|
38 | 38 | <p class="event-phone"> |
39 | 39 | <span class="small-text"> |
40 | - <strong><?php esc_html_e( 'Event Phone:', 'event_espresso' ); ?> </strong> |
|
40 | + <strong><?php esc_html_e('Event Phone:', 'event_espresso'); ?> </strong> |
|
41 | 41 | </span> |
42 | 42 | <?php echo wp_kses($event_phone, AllowedTags::getAllowedTags()); ?> |
43 | 43 | </p> |
44 | -<?php endif; ?> |
|
44 | +<?php endif; ?> |
|
45 | 45 | |
46 | 46 | <?php |
47 | - if ( apply_filters( 'FHEE__content_espresso_events_details_template__display_the_content', true ) ) { |
|
48 | - do_action( 'AHEE_event_details_before_the_content', $post ); |
|
47 | + if (apply_filters('FHEE__content_espresso_events_details_template__display_the_content', true)) { |
|
48 | + do_action('AHEE_event_details_before_the_content', $post); |
|
49 | 49 | echo apply_filters( |
50 | 50 | 'FHEE__content_espresso_events_details_template__the_content', |
51 | - espresso_event_content_or_excerpt( 55, null, false ) |
|
51 | + espresso_event_content_or_excerpt(55, null, false) |
|
52 | 52 | ); |
53 | - do_action( 'AHEE_event_details_after_the_content', $post ); |
|
53 | + do_action('AHEE_event_details_after_the_content', $post); |
|
54 | 54 | } |
55 | 55 | ?> |
56 | 56 | </div> |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php //echo '<h1>' . __FILE__ . '</h1>'; |
2 | 2 | global $post; |
3 | -if ( espresso_venue_has_address( $post->ID )) : |
|
3 | +if (espresso_venue_has_address($post->ID)) : |
|
4 | 4 | ?> |
5 | 5 | <div class="venue-location"> |
6 | 6 | |
7 | 7 | <h3 class="venue-address-h3 ee-venue-h3"> |
8 | - <span class="dashicons dashicons-location-alt"></span><?php esc_html_e( 'Location', 'event_espresso' ); ?> |
|
8 | + <span class="dashicons dashicons-location-alt"></span><?php esc_html_e('Location', 'event_espresso'); ?> |
|
9 | 9 | </h3> |
10 | - <span class="small-text"><strong><?php esc_html_e( 'Address:', 'event_espresso' ); ?></strong></span><?php espresso_venue_address( 'inline', $post->ID ); ?> |
|
10 | + <span class="small-text"><strong><?php esc_html_e('Address:', 'event_espresso'); ?></strong></span><?php espresso_venue_address('inline', $post->ID); ?> |
|
11 | 11 | <div class="clear"></div> |
12 | 12 | |
13 | - <div class="venue-gmap"><?php espresso_venue_gmap( $post->ID ); ?></div> |
|
13 | + <div class="venue-gmap"><?php espresso_venue_gmap($post->ID); ?></div> |
|
14 | 14 | <div class="clear"></div> |
15 | 15 | |
16 | 16 | </div> |
@@ -51,8 +51,11 @@ discard block |
||
51 | 51 | <?php echo do_shortcode( $venue_description ); ?> |
52 | 52 | </p> |
53 | 53 | <?php endif; ?> |
54 | - <?php else : ?> |
|
55 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
54 | + <?php else { |
|
55 | + : ?> |
|
56 | + <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); |
|
57 | +} |
|
58 | +?> |
|
56 | 59 | <?php if ( $venue_excerpt ) : ?> |
57 | 60 | <p> |
58 | 61 | <strong><?php esc_html_e( 'Description:', 'event_espresso' ); ?></strong><br/> |
@@ -64,12 +67,15 @@ discard block |
||
64 | 67 | <!-- .espresso-venue-dv --> |
65 | 68 | <?php |
66 | 69 | do_action( 'AHEE_event_details_after_venue_details', $post ); |
67 | -else : |
|
70 | +else { |
|
71 | + : |
|
68 | 72 | if ( espresso_venue_is_password_protected() ) : |
69 | 73 | ?> |
70 | 74 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
71 | 75 | <h3 class="event-venues-h3 ee-event-h3"> |
72 | - <?php esc_html_e( 'Location', 'event_espresso' );?> |
|
76 | + <?php esc_html_e( 'Location', 'event_espresso' ); |
|
77 | +} |
|
78 | +?> |
|
73 | 79 | </h3> |
74 | 80 | <?php echo espresso_password_protected_venue_form(); ?> |
75 | 81 | </div> |
@@ -3,75 +3,75 @@ |
||
3 | 3 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
4 | 4 | |
5 | 5 | if ( |
6 | - ( is_single() && espresso_display_venue_in_event_details() ) |
|
7 | - || ( is_archive() && espresso_display_venue_in_event_list() ) |
|
6 | + (is_single() && espresso_display_venue_in_event_details()) |
|
7 | + || (is_archive() && espresso_display_venue_in_event_list()) |
|
8 | 8 | ) : |
9 | 9 | global $post; |
10 | - do_action( 'AHEE_event_details_before_venue_details', $post ); |
|
11 | - $venue_name = espresso_venue_name( 0, 'details', FALSE ); |
|
12 | - if ( empty( $venue_name ) && espresso_is_venue_private() ) { |
|
13 | - do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
10 | + do_action('AHEE_event_details_before_venue_details', $post); |
|
11 | + $venue_name = espresso_venue_name(0, 'details', FALSE); |
|
12 | + if (empty($venue_name) && espresso_is_venue_private()) { |
|
13 | + do_action('AHEE_event_details_after_venue_details', $post); |
|
14 | 14 | return ''; |
15 | 15 | } |
16 | 16 | ?> |
17 | 17 | |
18 | 18 | <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>"> |
19 | 19 | <h4> |
20 | - <strong><?php esc_html_e( 'Venue:', 'event_espresso' ); ?></strong> |
|
20 | + <strong><?php esc_html_e('Venue:', 'event_espresso'); ?></strong> |
|
21 | 21 | <strong> <?php echo wp_kses($venue_name, AllowedTags::getAllowedTags()); ?></strong> |
22 | 22 | </h4> |
23 | 23 | <p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p> |
24 | -<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?> |
|
24 | +<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?> |
|
25 | 25 | <p> |
26 | 26 | <span class="small-text"> |
27 | - <strong><?php esc_html_e( 'Venue Phone:', 'event_espresso' ); ?></strong> |
|
27 | + <strong><?php esc_html_e('Venue Phone:', 'event_espresso'); ?></strong> |
|
28 | 28 | </span> |
29 | 29 | <?php echo wp_kses($venue_phone, AllowedTags::getAllowedTags()); ?> |
30 | 30 | </p> |
31 | -<?php endif; ?> |
|
32 | -<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?> |
|
31 | +<?php endif; ?> |
|
32 | +<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?> |
|
33 | 33 | <p> |
34 | 34 | <span class="small-text"> |
35 | - <strong><?php esc_html_e( 'Venue Website:', 'event_espresso' ); ?></strong> |
|
35 | + <strong><?php esc_html_e('Venue Website:', 'event_espresso'); ?></strong> |
|
36 | 36 | </span> |
37 | 37 | <?php echo wp_kses($venue_website, AllowedTags::getAllowedTags()); ?> |
38 | 38 | </p> |
39 | 39 | <?php endif; ?> |
40 | -<?php if ( espresso_venue_has_address( $post->ID )) : ?> |
|
41 | - <strong><span class="dashicons dashicons-location-alt"></span><?php esc_html_e( 'Address:', 'event_espresso' ); ?></strong> |
|
42 | - <?php espresso_venue_address( 'inline' ); // already escaped ?> |
|
43 | - <?php espresso_venue_gmap( $post->ID ); // already escaped ?> |
|
40 | +<?php if (espresso_venue_has_address($post->ID)) : ?> |
|
41 | + <strong><span class="dashicons dashicons-location-alt"></span><?php esc_html_e('Address:', 'event_espresso'); ?></strong> |
|
42 | + <?php espresso_venue_address('inline'); // already escaped ?> |
|
43 | + <?php espresso_venue_gmap($post->ID); // already escaped ?> |
|
44 | 44 | <div class="clear"><br/></div> |
45 | -<?php endif; ?> |
|
45 | +<?php endif; ?> |
|
46 | 46 | |
47 | - <?php $VNU_ID = espresso_venue_id( $post->ID ); ?> |
|
48 | - <?php if ( is_single() ) : ?> |
|
49 | - <?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?> |
|
50 | - <?php if ( $venue_description ) : ?> |
|
47 | + <?php $VNU_ID = espresso_venue_id($post->ID); ?> |
|
48 | + <?php if (is_single()) : ?> |
|
49 | + <?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?> |
|
50 | + <?php if ($venue_description) : ?> |
|
51 | 51 | <p> |
52 | - <strong><?php esc_html_e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
53 | - <?php echo do_shortcode( $venue_description ); ?> |
|
52 | + <strong><?php esc_html_e('Description:', 'event_espresso'); ?></strong><br/> |
|
53 | + <?php echo do_shortcode($venue_description); ?> |
|
54 | 54 | </p> |
55 | - <?php endif; ?> |
|
55 | + <?php endif; ?> |
|
56 | 56 | <?php else : ?> |
57 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
58 | - <?php if ( $venue_excerpt ) : ?> |
|
57 | + <?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?> |
|
58 | + <?php if ($venue_excerpt) : ?> |
|
59 | 59 | <p> |
60 | - <strong><?php esc_html_e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
60 | + <strong><?php esc_html_e('Description:', 'event_espresso'); ?></strong><br/> |
|
61 | 61 | <?php echo wp_kses($venue_excerpt, AllowedTags::getAllowedTags()); ?> |
62 | 62 | </p> |
63 | - <?php endif; ?> |
|
64 | - <?php endif; ?> |
|
63 | + <?php endif; ?> |
|
64 | + <?php endif; ?> |
|
65 | 65 | </div> |
66 | 66 | <!-- .espresso-venue-dv --> |
67 | 67 | <?php |
68 | -do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
68 | +do_action('AHEE_event_details_after_venue_details', $post); |
|
69 | 69 | else : |
70 | - if ( espresso_venue_is_password_protected() ) : |
|
70 | + if (espresso_venue_is_password_protected()) : |
|
71 | 71 | ?> |
72 | 72 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
73 | 73 | <h3 class="event-venues-h3 ee-event-h3"> |
74 | - <?php esc_html_e( 'Location', 'event_espresso' );?> |
|
74 | + <?php esc_html_e('Location', 'event_espresso'); ?> |
|
75 | 75 | </h3> |
76 | 76 | <?php echo espresso_password_protected_venue_form(); ?> |
77 | 77 | </div> |
@@ -7,10 +7,10 @@ |
||
7 | 7 | <?php echo "<{$tag} id=\"event-details-{$tag}-{$post->ID}\" class=\"entry-title\">"; ?> |
8 | 8 | <a class="ee-event-header-lnk" |
9 | 9 | href="<?php the_permalink(); ?>" |
10 | - <?php echo \EED_Events_Archive::link_target();?> |
|
10 | + <?php echo \EED_Events_Archive::link_target(); ?> |
|
11 | 11 | > |
12 | 12 | <?php the_title(); ?> |
13 | 13 | </a> |
14 | 14 | <?php echo "</{$tag}>"; ?> |
15 | - <?php if ( ! is_archive() && has_excerpt( $post->ID )): the_excerpt(); endif;?> |
|
15 | + <?php if ( ! is_archive() && has_excerpt($post->ID)): the_excerpt(); endif; ?> |
|
16 | 16 | </header> |
@@ -13,25 +13,25 @@ discard block |
||
13 | 13 | <div id="ee-block-event-attendees" class="ee-core-blocks event-espresso-blocks event-attendees"> |
14 | 14 | <ul> |
15 | 15 | <?php |
16 | - foreach ($attendees as $attendee) { |
|
17 | - $attendee_name = esc_html($attendee->full_name()); |
|
16 | + foreach ($attendees as $attendee) { |
|
17 | + $attendee_name = esc_html($attendee->full_name()); |
|
18 | 18 | |
19 | - $gravatar = $attributes['showGravatar'] |
|
20 | - ? get_avatar_url( |
|
21 | - $attendee->email(), |
|
22 | - array( |
|
23 | - 'width' => $attributes['avatarSize'], |
|
24 | - 'height' => $attributes['avatarSize'] |
|
25 | - ) |
|
26 | - ) |
|
27 | - : ''; |
|
19 | + $gravatar = $attributes['showGravatar'] |
|
20 | + ? get_avatar_url( |
|
21 | + $attendee->email(), |
|
22 | + array( |
|
23 | + 'width' => $attributes['avatarSize'], |
|
24 | + 'height' => $attributes['avatarSize'] |
|
25 | + ) |
|
26 | + ) |
|
27 | + : ''; |
|
28 | 28 | |
29 | - $gravatar_class = $attributes['avatarClass'] |
|
30 | - ? $attributes['avatarClass'] . ' contact-avatar-img avatar' |
|
31 | - : 'contact-avatar-img avatar'; |
|
29 | + $gravatar_class = $attributes['avatarClass'] |
|
30 | + ? $attributes['avatarClass'] . ' contact-avatar-img avatar' |
|
31 | + : 'contact-avatar-img avatar'; |
|
32 | 32 | |
33 | - $gravatar = $gravatar !== '' |
|
34 | - ? ' |
|
33 | + $gravatar = $gravatar !== '' |
|
34 | + ? ' |
|
35 | 35 | <div class="contact-image-wrap-div"> |
36 | 36 | <img class="' . esc_attr($gravatar_class) . '" |
37 | 37 | width="' . esc_attr($attributes['avatarSize']) . '" |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | alt="contact avatar" |
41 | 41 | > |
42 | 42 | </div>' |
43 | - : ''; |
|
43 | + : ''; |
|
44 | 44 | |
45 | - echo " |
|
45 | + echo " |
|
46 | 46 | <li> |
47 | 47 | {$gravatar}<span>{$attendee_name}</span> |
48 | 48 | </li>"; |
49 | - } |
|
50 | - ?> |
|
49 | + } |
|
50 | + ?> |
|
51 | 51 | </ul> |
52 | 52 | </div> |
@@ -27,16 +27,16 @@ |
||
27 | 27 | : ''; |
28 | 28 | |
29 | 29 | $gravatar_class = $attributes['avatarClass'] |
30 | - ? $attributes['avatarClass'] . ' contact-avatar-img avatar' |
|
30 | + ? $attributes['avatarClass'].' contact-avatar-img avatar' |
|
31 | 31 | : 'contact-avatar-img avatar'; |
32 | 32 | |
33 | 33 | $gravatar = $gravatar !== '' |
34 | 34 | ? ' |
35 | 35 | <div class="contact-image-wrap-div"> |
36 | - <img class="' . esc_attr($gravatar_class) . '" |
|
37 | - width="' . esc_attr($attributes['avatarSize']) . '" |
|
38 | - height="' . esc_attr($attributes['avatarSize']) . '" |
|
39 | - src="' . esc_url_raw($gravatar) . '" |
|
36 | + <img class="' . esc_attr($gravatar_class).'" |
|
37 | + width="' . esc_attr($attributes['avatarSize']).'" |
|
38 | + height="' . esc_attr($attributes['avatarSize']).'" |
|
39 | + src="' . esc_url_raw($gravatar).'" |
|
40 | 40 | alt="contact avatar" |
41 | 41 | > |
42 | 42 | </div>' |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | protected function setId($id = '') |
123 | 123 | { |
124 | - if (! is_string($id)) { |
|
124 | + if ( ! is_string($id)) { |
|
125 | 125 | throw new InvalidDataTypeException('$id', $id, 'string'); |
126 | 126 | } |
127 | 127 | $this->id = $id; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | protected function setOrder($order = 0) |
146 | 146 | { |
147 | - if (! is_int($order)) { |
|
147 | + if ( ! is_int($order)) { |
|
148 | 148 | throw new InvalidDataTypeException('$order', $order, 'integer'); |
149 | 149 | } |
150 | 150 | $this->order = absint($order); |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | */ |
174 | 174 | protected function setHtmlClass($html_class) |
175 | 175 | { |
176 | - if (! is_string($html_class)) { |
|
176 | + if ( ! is_string($html_class)) { |
|
177 | 177 | throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
178 | 178 | } |
179 | 179 | if (strpos($html_class, 'progress-step-') === false) { |
180 | - $html_class = 'progress-step-' . $html_class; |
|
180 | + $html_class = 'progress-step-'.$html_class; |
|
181 | 181 | } |
182 | 182 | $this->html_class = $html_class; |
183 | 183 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function setText($text) |
201 | 201 | { |
202 | - if (! is_string($text)) { |
|
202 | + if ( ! is_string($text)) { |
|
203 | 203 | throw new InvalidDataTypeException('$text', $text, 'string'); |
204 | 204 | } |
205 | 205 | $this->text = sanitize_text_field($text); |
@@ -16,190 +16,190 @@ |
||
16 | 16 | */ |
17 | 17 | class ProgressStep implements ProgressStepInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @var boolean $current |
|
21 | - */ |
|
22 | - private $current = false; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var boolean $completed |
|
27 | - */ |
|
28 | - private $completed = false; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $html_class |
|
33 | - */ |
|
34 | - private $html_class; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $id |
|
38 | - */ |
|
39 | - private $id = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int $order |
|
43 | - */ |
|
44 | - private $order = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $text |
|
48 | - */ |
|
49 | - private $text = ''; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * ProgressStep constructor |
|
54 | - * |
|
55 | - * @param int $order |
|
56 | - * @param string $id |
|
57 | - * @param string $html_class |
|
58 | - * @param string $text |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
61 | - public function __construct($order, $id, $html_class, $text) |
|
62 | - { |
|
63 | - $this->setOrder($order); |
|
64 | - $this->setId($id); |
|
65 | - $this->setHtmlClass($html_class); |
|
66 | - $this->setText($text); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return boolean |
|
72 | - */ |
|
73 | - public function isCurrent() |
|
74 | - { |
|
75 | - return $this->current; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param boolean $current |
|
81 | - */ |
|
82 | - public function setIsCurrent($current = true) |
|
83 | - { |
|
84 | - $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @return boolean |
|
90 | - */ |
|
91 | - public function isCompleted() |
|
92 | - { |
|
93 | - return $this->completed; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param boolean $completed |
|
99 | - */ |
|
100 | - public function setIsCompleted($completed = true) |
|
101 | - { |
|
102 | - $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function id() |
|
110 | - { |
|
111 | - return $this->id; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @access protected |
|
117 | - * @param string $id |
|
118 | - * @throws InvalidDataTypeException |
|
119 | - */ |
|
120 | - protected function setId($id = '') |
|
121 | - { |
|
122 | - if (! is_string($id)) { |
|
123 | - throw new InvalidDataTypeException('$id', $id, 'string'); |
|
124 | - } |
|
125 | - $this->id = $id; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return int |
|
131 | - */ |
|
132 | - public function order() |
|
133 | - { |
|
134 | - return $this->order; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @access protected |
|
140 | - * @param int $order |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - */ |
|
143 | - protected function setOrder($order = 0) |
|
144 | - { |
|
145 | - if (! is_int($order)) { |
|
146 | - throw new InvalidDataTypeException('$order', $order, 'integer'); |
|
147 | - } |
|
148 | - $this->order = absint($order); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function htmlClass() |
|
156 | - { |
|
157 | - $html_class = $this->html_class; |
|
158 | - if ($this->isCurrent()) { |
|
159 | - $html_class .= ' progress-step-active'; |
|
160 | - } elseif ($this->isCompleted()) { |
|
161 | - $html_class .= ' progress-step-completed'; |
|
162 | - } |
|
163 | - return $html_class; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @access protected |
|
169 | - * @param string $html_class |
|
170 | - * @throws InvalidDataTypeException |
|
171 | - */ |
|
172 | - protected function setHtmlClass($html_class) |
|
173 | - { |
|
174 | - if (! is_string($html_class)) { |
|
175 | - throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
|
176 | - } |
|
177 | - if (strpos($html_class, 'progress-step-') === false) { |
|
178 | - $html_class = 'progress-step-' . $html_class; |
|
179 | - } |
|
180 | - $this->html_class = $html_class; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function text() |
|
188 | - { |
|
189 | - return $this->text; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @access protected |
|
195 | - * @param string $text |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - */ |
|
198 | - protected function setText($text) |
|
199 | - { |
|
200 | - if (! is_string($text)) { |
|
201 | - throw new InvalidDataTypeException('$text', $text, 'string'); |
|
202 | - } |
|
203 | - $this->text = sanitize_text_field($text); |
|
204 | - } |
|
19 | + /** |
|
20 | + * @var boolean $current |
|
21 | + */ |
|
22 | + private $current = false; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var boolean $completed |
|
27 | + */ |
|
28 | + private $completed = false; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $html_class |
|
33 | + */ |
|
34 | + private $html_class; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $id |
|
38 | + */ |
|
39 | + private $id = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int $order |
|
43 | + */ |
|
44 | + private $order = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $text |
|
48 | + */ |
|
49 | + private $text = ''; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * ProgressStep constructor |
|
54 | + * |
|
55 | + * @param int $order |
|
56 | + * @param string $id |
|
57 | + * @param string $html_class |
|
58 | + * @param string $text |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | + public function __construct($order, $id, $html_class, $text) |
|
62 | + { |
|
63 | + $this->setOrder($order); |
|
64 | + $this->setId($id); |
|
65 | + $this->setHtmlClass($html_class); |
|
66 | + $this->setText($text); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return boolean |
|
72 | + */ |
|
73 | + public function isCurrent() |
|
74 | + { |
|
75 | + return $this->current; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param boolean $current |
|
81 | + */ |
|
82 | + public function setIsCurrent($current = true) |
|
83 | + { |
|
84 | + $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @return boolean |
|
90 | + */ |
|
91 | + public function isCompleted() |
|
92 | + { |
|
93 | + return $this->completed; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param boolean $completed |
|
99 | + */ |
|
100 | + public function setIsCompleted($completed = true) |
|
101 | + { |
|
102 | + $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function id() |
|
110 | + { |
|
111 | + return $this->id; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @access protected |
|
117 | + * @param string $id |
|
118 | + * @throws InvalidDataTypeException |
|
119 | + */ |
|
120 | + protected function setId($id = '') |
|
121 | + { |
|
122 | + if (! is_string($id)) { |
|
123 | + throw new InvalidDataTypeException('$id', $id, 'string'); |
|
124 | + } |
|
125 | + $this->id = $id; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return int |
|
131 | + */ |
|
132 | + public function order() |
|
133 | + { |
|
134 | + return $this->order; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @access protected |
|
140 | + * @param int $order |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + */ |
|
143 | + protected function setOrder($order = 0) |
|
144 | + { |
|
145 | + if (! is_int($order)) { |
|
146 | + throw new InvalidDataTypeException('$order', $order, 'integer'); |
|
147 | + } |
|
148 | + $this->order = absint($order); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function htmlClass() |
|
156 | + { |
|
157 | + $html_class = $this->html_class; |
|
158 | + if ($this->isCurrent()) { |
|
159 | + $html_class .= ' progress-step-active'; |
|
160 | + } elseif ($this->isCompleted()) { |
|
161 | + $html_class .= ' progress-step-completed'; |
|
162 | + } |
|
163 | + return $html_class; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @access protected |
|
169 | + * @param string $html_class |
|
170 | + * @throws InvalidDataTypeException |
|
171 | + */ |
|
172 | + protected function setHtmlClass($html_class) |
|
173 | + { |
|
174 | + if (! is_string($html_class)) { |
|
175 | + throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
|
176 | + } |
|
177 | + if (strpos($html_class, 'progress-step-') === false) { |
|
178 | + $html_class = 'progress-step-' . $html_class; |
|
179 | + } |
|
180 | + $this->html_class = $html_class; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function text() |
|
188 | + { |
|
189 | + return $this->text; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @access protected |
|
195 | + * @param string $text |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + */ |
|
198 | + protected function setText($text) |
|
199 | + { |
|
200 | + if (! is_string($text)) { |
|
201 | + throw new InvalidDataTypeException('$text', $text, 'string'); |
|
202 | + } |
|
203 | + $this->text = sanitize_text_field($text); |
|
204 | + } |
|
205 | 205 | } |
@@ -174,7 +174,7 @@ |
||
174 | 174 | $this->rewind(); |
175 | 175 | while ($this->valid()) { |
176 | 176 | echo '<h5 style="color:#2EA2CC;"> |
177 | - ' . __CLASS__ . ' class : <span style="color:#E76700">' . esc_html($this->getInfo()) . '</span> |
|
177 | + ' . __CLASS__.' class : <span style="color:#E76700">'.esc_html($this->getInfo()).'</span> |
|
178 | 178 | </h5>'; |
179 | 179 | $this->next(); |
180 | 180 | } |
@@ -13,143 +13,143 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Message_Type_Collection extends EE_Object_Collection |
15 | 15 | { |
16 | - /** |
|
17 | - * EE_Message_Type_Collection constructor. |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->interface = 'EE_message_type'; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * attaches an object to the Collection |
|
28 | - * and sets any supplied data associated with the current iterator entry |
|
29 | - * by calling EE_Object_Collection::set_info() |
|
30 | - * |
|
31 | - * @param object $object |
|
32 | - * @param mixed $info |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function add($object, $info = ''): bool |
|
36 | - { |
|
37 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
38 | - return parent::add($object, $info); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Sets the data associated with an object in the Collection |
|
45 | - * if no $info is supplied, then the spl_object_hash() is used |
|
46 | - * |
|
47 | - * @param object $object |
|
48 | - * @param mixed $info |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function set_info($object, $info = ''): bool |
|
52 | - { |
|
53 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
54 | - return parent::set_info($object, $info); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * finds and returns an object in the Collection based on the info that was set using addObject() |
|
61 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
62 | - * |
|
63 | - * @param mixed |
|
64 | - * @return null | object |
|
65 | - */ |
|
66 | - public function get_by_info($info = '') |
|
67 | - { |
|
68 | - return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
75 | - * |
|
76 | - * @param object $object |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function has($object): bool |
|
80 | - { |
|
81 | - return parent::has($object); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
88 | - * |
|
89 | - * @param string $message_type_name |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function has_by_name(string $message_type_name): bool |
|
93 | - { |
|
94 | - return $this->get_by_info($message_type_name) instanceof $this->interface; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * detaches an object from the Collection |
|
101 | - * |
|
102 | - * @param $object |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public function remove($object): bool |
|
106 | - { |
|
107 | - return parent::remove($object); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * advances pointer to the provided object |
|
114 | - * |
|
115 | - * @param $object |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public function set_current($object) |
|
119 | - { |
|
120 | - parent::set_current($object); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * advances pointer to the object whose info matches that which was provided |
|
127 | - * |
|
128 | - * @param $info |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public function set_current_by_info($info) |
|
132 | - { |
|
133 | - parent::set_current_by_info($info); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * displays list of collection classes if WP_DEBUG is on |
|
140 | - * |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public function show_collection_classes() |
|
144 | - { |
|
145 | - if (WP_DEBUG) { |
|
146 | - $this->rewind(); |
|
147 | - while ($this->valid()) { |
|
148 | - echo '<h5 style="color:#2EA2CC;"> |
|
16 | + /** |
|
17 | + * EE_Message_Type_Collection constructor. |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->interface = 'EE_message_type'; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * attaches an object to the Collection |
|
28 | + * and sets any supplied data associated with the current iterator entry |
|
29 | + * by calling EE_Object_Collection::set_info() |
|
30 | + * |
|
31 | + * @param object $object |
|
32 | + * @param mixed $info |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function add($object, $info = ''): bool |
|
36 | + { |
|
37 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
38 | + return parent::add($object, $info); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Sets the data associated with an object in the Collection |
|
45 | + * if no $info is supplied, then the spl_object_hash() is used |
|
46 | + * |
|
47 | + * @param object $object |
|
48 | + * @param mixed $info |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function set_info($object, $info = ''): bool |
|
52 | + { |
|
53 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
54 | + return parent::set_info($object, $info); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * finds and returns an object in the Collection based on the info that was set using addObject() |
|
61 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
62 | + * |
|
63 | + * @param mixed |
|
64 | + * @return null | object |
|
65 | + */ |
|
66 | + public function get_by_info($info = '') |
|
67 | + { |
|
68 | + return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
75 | + * |
|
76 | + * @param object $object |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function has($object): bool |
|
80 | + { |
|
81 | + return parent::has($object); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
88 | + * |
|
89 | + * @param string $message_type_name |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function has_by_name(string $message_type_name): bool |
|
93 | + { |
|
94 | + return $this->get_by_info($message_type_name) instanceof $this->interface; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * detaches an object from the Collection |
|
101 | + * |
|
102 | + * @param $object |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public function remove($object): bool |
|
106 | + { |
|
107 | + return parent::remove($object); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * advances pointer to the provided object |
|
114 | + * |
|
115 | + * @param $object |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public function set_current($object) |
|
119 | + { |
|
120 | + parent::set_current($object); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * advances pointer to the object whose info matches that which was provided |
|
127 | + * |
|
128 | + * @param $info |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public function set_current_by_info($info) |
|
132 | + { |
|
133 | + parent::set_current_by_info($info); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * displays list of collection classes if WP_DEBUG is on |
|
140 | + * |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public function show_collection_classes() |
|
144 | + { |
|
145 | + if (WP_DEBUG) { |
|
146 | + $this->rewind(); |
|
147 | + while ($this->valid()) { |
|
148 | + echo '<h5 style="color:#2EA2CC;"> |
|
149 | 149 | ' . __CLASS__ . ' class : <span style="color:#E76700">' . esc_html($this->getInfo()) . '</span> |
150 | 150 | </h5>'; |
151 | - $this->next(); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
151 | + $this->next(); |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | 155 | } |