@@ -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__( |
@@ -3,12 +3,12 @@ discard block |
||
3 | 3 | |
4 | 4 | global $post; |
5 | 5 | |
6 | -do_action( 'AHEE__content_espresso_venues_template__before_featured_img', $post ); |
|
6 | +do_action('AHEE__content_espresso_venues_template__before_featured_img', $post); |
|
7 | 7 | |
8 | -if ( has_post_thumbnail( $post->ID )) : |
|
9 | - if ( $img_ID = get_post_thumbnail_id( $post->ID )) : |
|
10 | - if ( $featured_img = wp_get_attachment_image_src( $img_ID, 'large' )) : |
|
11 | - $caption = get_post( get_post( $img_ID ))->post_excerpt; |
|
8 | +if (has_post_thumbnail($post->ID)) : |
|
9 | + if ($img_ID = get_post_thumbnail_id($post->ID)) : |
|
10 | + if ($featured_img = wp_get_attachment_image_src($img_ID, 'large')) : |
|
11 | + $caption = get_post(get_post($img_ID))->post_excerpt; |
|
12 | 12 | $wrap_class .= ' has-img'; |
13 | 13 | ?> |
14 | 14 | <div id="ee-venue-img-dv-<?php echo esc_attr($post->ID); ?>" class="ee-venue-img-dv"> |
@@ -26,5 +26,5 @@ discard block |
||
26 | 26 | endif; |
27 | 27 | endif; |
28 | 28 | ?> |
29 | -<?php do_action( 'AHEE__content_espresso_venues_template__after_featured_img', $post );?> |
|
29 | +<?php do_action('AHEE__content_espresso_venues_template__after_featured_img', $post); ?> |
|
30 | 30 | <!-- .venue-content --> |
@@ -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>' |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <div id="espresso-ajax-loading" style="display:none;"> |
2 | 2 | <span class="ee-spinner ee-spin"></span><span style="display:none;"> |
3 | 3 | <?php esc_html_e( |
4 | - 'loading...', |
|
5 | - 'event_espresso' |
|
6 | - ); ?></span> |
|
4 | + 'loading...', |
|
5 | + 'event_espresso' |
|
6 | + ); ?></span> |
|
7 | 7 | </div> |
8 | 8 | |
9 | 9 | <div id="espresso-ajax-notices"> |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
102 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
102 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
103 | 103 | // sigh... pull it from the db |
104 | 104 | EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
105 | 105 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | public static function is_venue_private($VNU_ID = false) |
176 | 176 | { |
177 | 177 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
178 | - if (! $venue instanceof EE_Venue) { |
|
178 | + if ( ! $venue instanceof EE_Venue) { |
|
179 | 179 | return null; |
180 | 180 | } |
181 | 181 | |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
261 | 261 | if ($venue instanceof EE_Venue) { |
262 | 262 | $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
263 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
263 | + $venue_link = ' '.EEH_Venue_View::venue_details_link( |
|
264 | 264 | $venue->ID(), |
265 | - esc_html__('more', 'event_espresso') . '…' |
|
265 | + esc_html__('more', 'event_espresso').'…' |
|
266 | 266 | ); |
267 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
267 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
268 | 268 | } |
269 | 269 | return ''; |
270 | 270 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | )) |
300 | 300 | || ! $hide_uncategorized) |
301 | 301 | ) { |
302 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
302 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $venue_name = apply_filters( |
368 | 368 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
369 | 369 | EEH_Venue_View::is_venue_private() |
370 | - ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
370 | + ? EEH_Venue_View::$_venue->name()." ".esc_html__('(Private)', 'event_espresso') |
|
371 | 371 | : EEH_Venue_View::$_venue->name(), |
372 | 372 | EEH_Venue_View::$_venue |
373 | 373 | ); |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | $options = []; |
481 | 481 | |
482 | 482 | $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
483 | - ? $map_ID . '-' . $venue->ID() |
|
483 | + ? $map_ID.'-'.$venue->ID() |
|
484 | 484 | : $venue->ID(); |
485 | 485 | |
486 | 486 | $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
@@ -627,11 +627,11 @@ discard block |
||
627 | 627 | $post_type_obj = get_post_type_object('espresso_venues'); |
628 | 628 | // build final link html |
629 | 629 | $link = |
630 | - '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
630 | + '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr( |
|
631 | 631 | $post_type_obj->labels->edit_item |
632 | - ) . '">' . $link . '</a>'; |
|
632 | + ).'">'.$link.'</a>'; |
|
633 | 633 | // put it all together |
634 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
634 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | return ''; |
@@ -9,630 +9,630 @@ |
||
9 | 9 | */ |
10 | 10 | class EEH_Venue_View extends EEH_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @access private |
|
14 | - * @var EE_Venue |
|
15 | - */ |
|
16 | - private static $_venue = null; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * get_venue |
|
21 | - * attempts to retrieve an EE_Venue object any way it can |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @param int $VNU_ID |
|
25 | - * @param bool $look_in_event |
|
26 | - * @param bool $privacy_check Defaults to true. |
|
27 | - * When false, means even if the venue is private we return it regardless of access. |
|
28 | - * @param bool $password_check |
|
29 | - * @return EE_Venue|null |
|
30 | - * @throws EE_Error |
|
31 | - * @throws ReflectionException |
|
32 | - */ |
|
33 | - public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
34 | - { |
|
35 | - $VNU_ID = absint($VNU_ID); |
|
36 | - // do we already have the Venue you are looking for? |
|
37 | - if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
38 | - // If the Venue ID matches $VNU_ID, return the venue. |
|
39 | - if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
40 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
41 | - } |
|
42 | - // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
43 | - $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
44 | - if ($venue instanceof EE_Venue) { |
|
45 | - EEH_Venue_View::$_venue = $venue; |
|
46 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
47 | - } |
|
48 | - } |
|
49 | - // international newspaper? |
|
50 | - global $post; |
|
51 | - if ($post instanceof WP_Post) { |
|
52 | - switch ($post->post_type) { |
|
53 | - // if this is being called from an EE_Venue post, |
|
54 | - // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
55 | - // then we can try to just grab the attached EE_Venue object |
|
56 | - case 'espresso_venues': |
|
57 | - // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
58 | - // the requested Venue ID matches the post ID OR... |
|
59 | - // there was no specific Venue ID requested |
|
60 | - if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
61 | - // use existing related EE_Venue object |
|
62 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
63 | - } elseif ($VNU_ID) { |
|
64 | - // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
65 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
66 | - } else { |
|
67 | - // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
68 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
69 | - } |
|
70 | - break; |
|
71 | - |
|
72 | - case 'espresso_events': |
|
73 | - if ($look_in_event) { |
|
74 | - // grab the events related venues |
|
75 | - $venues = EEH_Venue_View::get_event_venues(); |
|
76 | - // make sure the result is an array |
|
77 | - $venues = is_array($venues) ? $venues : []; |
|
78 | - // do we have an ID for a specific venue? |
|
79 | - if ($VNU_ID) { |
|
80 | - // loop thru the related venues |
|
81 | - foreach ($venues as $venue) { |
|
82 | - if ($venue instanceof EE_Venue) { |
|
83 | - // until we find the venue we're looking for |
|
84 | - if ($venue->ID() == $VNU_ID) { |
|
85 | - EEH_Venue_View::$_venue = $venue; |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - // no venue ID ? |
|
91 | - // then the global post is an events post and this function was called with no argument |
|
92 | - } else { |
|
93 | - // just grab the first related event venue |
|
94 | - EEH_Venue_View::$_venue = reset($venues); |
|
95 | - } |
|
96 | - } |
|
97 | - break; |
|
98 | - } |
|
99 | - } |
|
100 | - // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
101 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
102 | - // sigh... pull it from the db |
|
103 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
104 | - } |
|
105 | - return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * return a single venue |
|
111 | - * |
|
112 | - * @param bool $privacy_check Defaults to true. |
|
113 | - * When false, means even if the venue is private we return it regardless of access. |
|
114 | - * @param bool $password_check |
|
115 | - * @return EE_Venue |
|
116 | - * @throws EE_Error |
|
117 | - * @throws ReflectionException |
|
118 | - */ |
|
119 | - protected static function _get_venue($privacy_check = true, $password_check = true) |
|
120 | - { |
|
121 | - // check for private venues. |
|
122 | - if ( |
|
123 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
124 | - && EEH_Venue_View::$_venue->status() == 'private' |
|
125 | - && $privacy_check |
|
126 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
127 | - ) { |
|
128 | - return null; |
|
129 | - } |
|
130 | - // check for password protected venues |
|
131 | - if ( |
|
132 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
133 | - && $password_check |
|
134 | - && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
135 | - ) { |
|
136 | - return null; |
|
137 | - } |
|
138 | - return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * get_event_venues |
|
144 | - * |
|
145 | - * @access public |
|
146 | - * @return EE_Venue[] |
|
147 | - * @throws EE_Error |
|
148 | - * @throws ReflectionException |
|
149 | - */ |
|
150 | - public static function get_event_venues() |
|
151 | - { |
|
152 | - global $post; |
|
153 | - if ($post->post_type == 'espresso_events') { |
|
154 | - if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
155 | - return $post->EE_Event->venues(); |
|
156 | - } |
|
157 | - } |
|
158 | - return []; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
164 | - * |
|
165 | - * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but |
|
166 | - * is not private. So it is important to do explicit boolean checks when using this conditional. |
|
167 | - * |
|
168 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
169 | - * |
|
170 | - * @return bool|null |
|
171 | - * @throws EE_Error |
|
172 | - * @throws ReflectionException |
|
173 | - */ |
|
174 | - public static function is_venue_private($VNU_ID = false) |
|
175 | - { |
|
176 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
177 | - if (! $venue instanceof EE_Venue) { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - return $venue->status() == 'private'; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * returns true or false if a venue is password protected or not |
|
187 | - * |
|
188 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public static function is_venue_password_protected($VNU_ID = false) |
|
194 | - { |
|
195 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
196 | - if ( |
|
197 | - $venue instanceof EE_Venue |
|
198 | - && post_password_required($venue->ID()) |
|
199 | - ) { |
|
200 | - return true; |
|
201 | - } |
|
202 | - return false; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * If a venue is password protected, this will return the password form for gaining access |
|
208 | - * returns an empty string otherwise |
|
209 | - * |
|
210 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
211 | - * |
|
212 | - * @return string |
|
213 | - * @throws EE_Error |
|
214 | - * @throws ReflectionException |
|
215 | - */ |
|
216 | - public static function password_protected_venue_form($VNU_ID = false) |
|
217 | - { |
|
218 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
219 | - if ( |
|
220 | - $venue instanceof EE_Venue |
|
221 | - && post_password_required($venue->ID()) |
|
222 | - ) { |
|
223 | - return get_the_password_form($venue->ID()); |
|
224 | - } |
|
225 | - return ''; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * venue_description |
|
231 | - * |
|
232 | - * @access public |
|
233 | - * @param int $VNU_ID |
|
234 | - * @return string |
|
235 | - * @throws EE_Error |
|
236 | - * @throws ReflectionException |
|
237 | - */ |
|
238 | - public static function venue_description($VNU_ID = 0) |
|
239 | - { |
|
240 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
241 | - if ($venue instanceof EE_Venue) { |
|
242 | - return $venue->get_pretty('VNU_desc'); |
|
243 | - } |
|
244 | - return ''; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * venue_excerpt |
|
250 | - * |
|
251 | - * @access public |
|
252 | - * @param int $VNU_ID |
|
253 | - * @return string |
|
254 | - * @throws EE_Error |
|
255 | - * @throws ReflectionException |
|
256 | - */ |
|
257 | - public static function venue_excerpt($VNU_ID = 0) |
|
258 | - { |
|
259 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
260 | - if ($venue instanceof EE_Venue) { |
|
261 | - $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
262 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
263 | - $venue->ID(), |
|
264 | - esc_html__('more', 'event_espresso') . '…' |
|
265 | - ); |
|
266 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
267 | - } |
|
268 | - return ''; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * venue_categories |
|
274 | - * |
|
275 | - * @access public |
|
276 | - * @param int $VNU_ID |
|
277 | - * @param bool $hide_uncategorized |
|
278 | - * @return string |
|
279 | - * @throws EE_Error |
|
280 | - * @throws ReflectionException |
|
281 | - */ |
|
282 | - public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
283 | - { |
|
284 | - $category_links = []; |
|
285 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
286 | - if ($venue instanceof EE_Venue) { |
|
287 | - // get category terms |
|
288 | - if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
289 | - // loop thru terms and create links |
|
290 | - foreach ($venue_categories as $term) { |
|
291 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
292 | - if ( |
|
293 | - ! is_wp_error($url) |
|
294 | - && (($hide_uncategorized |
|
295 | - && strtolower($term->name) != esc_html__( |
|
296 | - 'uncategorized', |
|
297 | - 'event_espresso' |
|
298 | - )) |
|
299 | - || ! $hide_uncategorized) |
|
300 | - ) { |
|
301 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
306 | - return implode(', ', $category_links); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * venue_address |
|
312 | - * |
|
313 | - * @access public |
|
314 | - * @param string $type |
|
315 | - * @param int $VNU_ID |
|
316 | - * @param bool $use_schema |
|
317 | - * @param bool $add_wrapper |
|
318 | - * @return string |
|
319 | - * @throws EE_Error |
|
320 | - * @throws ReflectionException |
|
321 | - */ |
|
322 | - public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
323 | - { |
|
324 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
325 | - if ($venue instanceof EE_Venue) { |
|
326 | - return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
327 | - } |
|
328 | - return ''; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * venue_has_address |
|
334 | - * |
|
335 | - * @access public |
|
336 | - * @param int $VNU_ID |
|
337 | - * @return bool|string |
|
338 | - * @throws EE_Error |
|
339 | - * @throws ReflectionException |
|
340 | - */ |
|
341 | - public static function venue_has_address($VNU_ID = 0) |
|
342 | - { |
|
343 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
344 | - if ($venue instanceof EE_Venue) { |
|
345 | - return EEH_Address::format($venue, 'inline', false, false); |
|
346 | - } |
|
347 | - return false; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * venue_name |
|
353 | - * |
|
354 | - * @access public |
|
355 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to |
|
356 | - * the Venue's details page or website |
|
357 | - * @param int $VNU_ID |
|
358 | - * @return string |
|
359 | - * @throws EE_Error |
|
360 | - * @throws ReflectionException |
|
361 | - */ |
|
362 | - public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
363 | - { |
|
364 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
365 | - if ($venue instanceof EE_Venue) { |
|
366 | - $venue_name = apply_filters( |
|
367 | - 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
368 | - EEH_Venue_View::is_venue_private() |
|
369 | - ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
370 | - : EEH_Venue_View::$_venue->name(), |
|
371 | - EEH_Venue_View::$_venue |
|
372 | - ); |
|
373 | - $venue_name = EEH_Schema::name($venue_name); |
|
374 | - |
|
375 | - // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
376 | - if ($venue->get('status') == 'trash') { |
|
377 | - $link_to = ''; |
|
378 | - } |
|
379 | - switch ($link_to) { |
|
380 | - case 'details': |
|
381 | - return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
382 | - |
|
383 | - case 'website': |
|
384 | - return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
385 | - |
|
386 | - default: |
|
387 | - return $venue_name; |
|
388 | - } |
|
389 | - } |
|
390 | - return ''; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * venue_details_link |
|
396 | - * |
|
397 | - * @access public |
|
398 | - * @param int $VNU_ID |
|
399 | - * @param string $text |
|
400 | - * @return string |
|
401 | - * @throws EE_Error |
|
402 | - * @throws ReflectionException |
|
403 | - */ |
|
404 | - public static function venue_details_link($VNU_ID = 0, $text = '') |
|
405 | - { |
|
406 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
407 | - if ($venue instanceof EE_Venue) { |
|
408 | - return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
409 | - } |
|
410 | - return ''; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * venue_website_link |
|
416 | - * |
|
417 | - * @access public |
|
418 | - * @param int $VNU_ID |
|
419 | - * @param string $text |
|
420 | - * @return string |
|
421 | - * @throws EE_Error |
|
422 | - * @throws ReflectionException |
|
423 | - */ |
|
424 | - public static function venue_website_link($VNU_ID = 0, $text = '') |
|
425 | - { |
|
426 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
427 | - if ($venue instanceof EE_Venue) { |
|
428 | - $url = $venue->venue_url(); |
|
429 | - $text = ! empty($text) ? $text : $url; |
|
430 | - return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : ''; |
|
431 | - } |
|
432 | - return ''; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * venue_phone |
|
438 | - * |
|
439 | - * @access public |
|
440 | - * @param int $VNU_ID |
|
441 | - * @return string |
|
442 | - * @throws EE_Error |
|
443 | - * @throws ReflectionException |
|
444 | - */ |
|
445 | - public static function venue_phone($VNU_ID = 0) |
|
446 | - { |
|
447 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
448 | - if ($venue instanceof EE_Venue) { |
|
449 | - return EEH_Schema::telephone($venue->phone()); |
|
450 | - } |
|
451 | - return ''; |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * venue_gmap |
|
457 | - * |
|
458 | - * @access public |
|
459 | - * @param int $VNU_ID |
|
460 | - * @param bool|string $map_ID a unique identifier for this map |
|
461 | - * @param array $gmap map options |
|
462 | - * @return string |
|
463 | - * @throws EE_Error |
|
464 | - * @throws ReflectionException |
|
465 | - */ |
|
466 | - public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = []) |
|
467 | - { |
|
468 | - |
|
469 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
470 | - if ($venue instanceof EE_Venue) { |
|
471 | - // check for global espresso_events post and use it's ID if no map_ID is set |
|
472 | - global $post; |
|
473 | - $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
474 | - // grab map settings |
|
475 | - $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
476 | - // are maps enabled ? |
|
477 | - if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
478 | - $details_page = is_single(); |
|
479 | - $options = []; |
|
480 | - |
|
481 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
|
482 | - ? $map_ID . '-' . $venue->ID() |
|
483 | - : $venue->ID(); |
|
484 | - |
|
485 | - $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
486 | - |
|
487 | - $options['ee_map_width'] = $details_page |
|
488 | - ? $map_cfg->event_details_map_width |
|
489 | - : $map_cfg->event_list_map_width; |
|
490 | - |
|
491 | - $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) |
|
492 | - ? $gmap['ee_map_width'] |
|
493 | - : $options['ee_map_width']; |
|
494 | - |
|
495 | - $options['ee_map_height'] = $details_page |
|
496 | - ? $map_cfg->event_details_map_height |
|
497 | - : $map_cfg->event_list_map_height; |
|
498 | - |
|
499 | - $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) |
|
500 | - ? $gmap['ee_map_height'] |
|
501 | - : $options['ee_map_height']; |
|
502 | - |
|
503 | - $options['ee_map_zoom'] = $details_page |
|
504 | - ? $map_cfg->event_details_map_zoom |
|
505 | - : $map_cfg->event_list_map_zoom; |
|
506 | - |
|
507 | - $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) |
|
508 | - ? $gmap['ee_map_zoom'] |
|
509 | - : $options['ee_map_zoom']; |
|
510 | - |
|
511 | - $options['ee_map_nav_display'] = $details_page |
|
512 | - ? $map_cfg->event_details_display_nav |
|
513 | - : $map_cfg->event_list_display_nav; |
|
514 | - |
|
515 | - $options['ee_map_nav_display'] = |
|
516 | - isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) |
|
517 | - ? 'true' |
|
518 | - : $options['ee_map_nav_display']; |
|
519 | - |
|
520 | - $options['ee_map_nav_size'] = $details_page |
|
521 | - ? $map_cfg->event_details_nav_size |
|
522 | - : $map_cfg->event_list_nav_size; |
|
523 | - |
|
524 | - $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) |
|
525 | - ? $gmap['ee_map_nav_size'] |
|
526 | - : $options['ee_map_nav_size']; |
|
527 | - |
|
528 | - $options['ee_map_type_control'] = $details_page |
|
529 | - ? $map_cfg->event_details_control_type |
|
530 | - : $map_cfg->event_list_control_type; |
|
531 | - |
|
532 | - $options['ee_map_type_control'] = |
|
533 | - isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) |
|
534 | - ? $gmap['ee_map_type_control'] |
|
535 | - : $options['ee_map_type_control']; |
|
536 | - |
|
537 | - $options['ee_map_align'] = $details_page |
|
538 | - ? $map_cfg->event_details_map_align |
|
539 | - : $map_cfg->event_list_map_align; |
|
540 | - |
|
541 | - $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) |
|
542 | - ? $gmap['ee_map_align'] |
|
543 | - : $options['ee_map_align']; |
|
544 | - |
|
545 | - $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) |
|
546 | - ? (bool) absint($gmap['ee_static_url']) |
|
547 | - : $venue->google_map_link(); |
|
548 | - |
|
549 | - return EEH_Maps::google_map($options); |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - return ''; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Gets the HTML to display a static map of the venue |
|
559 | - * |
|
560 | - * @param EE_Venue $venue |
|
561 | - * @param array $attributes like EEH_Maps::google_map_link |
|
562 | - * @return string |
|
563 | - * @throws EE_Error |
|
564 | - * @throws ReflectionException |
|
565 | - */ |
|
566 | - public static function espresso_google_static_map(EE_Venue $venue, $attributes = []) |
|
567 | - { |
|
568 | - $state = $venue->state_obj(); |
|
569 | - $country = $venue->country_obj(); |
|
570 | - $attributes = shortcode_atts( |
|
571 | - [ |
|
572 | - 'id' => $venue->ID(), |
|
573 | - 'address' => $venue->get('VNU_address'), |
|
574 | - 'city' => $venue->get('VNU_city'), |
|
575 | - 'state' => $state instanceof EE_State ? $state->name() : '', |
|
576 | - 'zip' => $venue->get('VNU_zip'), |
|
577 | - 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
578 | - 'type' => 'map', |
|
579 | - 'map_w' => 200, |
|
580 | - 'map_h' => 200, |
|
581 | - ], |
|
582 | - $attributes |
|
583 | - ); |
|
584 | - return EEH_Maps::google_map_link($attributes); |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * edit_venue_link |
|
590 | - * |
|
591 | - * @access public |
|
592 | - * @param int $VNU_ID |
|
593 | - * @param string $link |
|
594 | - * @param string $before |
|
595 | - * @param string $after |
|
596 | - * @return string |
|
597 | - * @throws EE_Error |
|
598 | - * @throws ReflectionException |
|
599 | - */ |
|
600 | - public static function edit_venue_link( |
|
601 | - $VNU_ID = 0, |
|
602 | - $link = '', |
|
603 | - $before = '<p class="edit-venue-lnk small-txt">', |
|
604 | - $after = '</p>' |
|
605 | - ) { |
|
606 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
607 | - if ($venue instanceof EE_Venue) { |
|
608 | - // can the user edit this post ? |
|
609 | - if (current_user_can('edit_post', $venue->ID())) { |
|
610 | - // set link text |
|
611 | - $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso'); |
|
612 | - // generate nonce |
|
613 | - $nonce = wp_create_nonce('edit_nonce'); |
|
614 | - // generate url to venue editor for this venue |
|
615 | - $url = |
|
616 | - add_query_arg( |
|
617 | - [ |
|
618 | - 'page' => 'espresso_venues', |
|
619 | - 'action' => 'edit', |
|
620 | - 'post' => $venue->ID(), |
|
621 | - 'edit_nonce' => $nonce, |
|
622 | - ], |
|
623 | - admin_url('admin.php') |
|
624 | - ); |
|
625 | - // get edit CPT text |
|
626 | - $post_type_obj = get_post_type_object('espresso_venues'); |
|
627 | - // build final link html |
|
628 | - $link = |
|
629 | - '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
630 | - $post_type_obj->labels->edit_item |
|
631 | - ) . '">' . $link . '</a>'; |
|
632 | - // put it all together |
|
633 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
634 | - } |
|
635 | - } |
|
636 | - return ''; |
|
637 | - } |
|
12 | + /** |
|
13 | + * @access private |
|
14 | + * @var EE_Venue |
|
15 | + */ |
|
16 | + private static $_venue = null; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * get_venue |
|
21 | + * attempts to retrieve an EE_Venue object any way it can |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @param int $VNU_ID |
|
25 | + * @param bool $look_in_event |
|
26 | + * @param bool $privacy_check Defaults to true. |
|
27 | + * When false, means even if the venue is private we return it regardless of access. |
|
28 | + * @param bool $password_check |
|
29 | + * @return EE_Venue|null |
|
30 | + * @throws EE_Error |
|
31 | + * @throws ReflectionException |
|
32 | + */ |
|
33 | + public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
34 | + { |
|
35 | + $VNU_ID = absint($VNU_ID); |
|
36 | + // do we already have the Venue you are looking for? |
|
37 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
38 | + // If the Venue ID matches $VNU_ID, return the venue. |
|
39 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
40 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
41 | + } |
|
42 | + // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
43 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
44 | + if ($venue instanceof EE_Venue) { |
|
45 | + EEH_Venue_View::$_venue = $venue; |
|
46 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
47 | + } |
|
48 | + } |
|
49 | + // international newspaper? |
|
50 | + global $post; |
|
51 | + if ($post instanceof WP_Post) { |
|
52 | + switch ($post->post_type) { |
|
53 | + // if this is being called from an EE_Venue post, |
|
54 | + // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
55 | + // then we can try to just grab the attached EE_Venue object |
|
56 | + case 'espresso_venues': |
|
57 | + // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
58 | + // the requested Venue ID matches the post ID OR... |
|
59 | + // there was no specific Venue ID requested |
|
60 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
61 | + // use existing related EE_Venue object |
|
62 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
63 | + } elseif ($VNU_ID) { |
|
64 | + // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
65 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
66 | + } else { |
|
67 | + // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
68 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
69 | + } |
|
70 | + break; |
|
71 | + |
|
72 | + case 'espresso_events': |
|
73 | + if ($look_in_event) { |
|
74 | + // grab the events related venues |
|
75 | + $venues = EEH_Venue_View::get_event_venues(); |
|
76 | + // make sure the result is an array |
|
77 | + $venues = is_array($venues) ? $venues : []; |
|
78 | + // do we have an ID for a specific venue? |
|
79 | + if ($VNU_ID) { |
|
80 | + // loop thru the related venues |
|
81 | + foreach ($venues as $venue) { |
|
82 | + if ($venue instanceof EE_Venue) { |
|
83 | + // until we find the venue we're looking for |
|
84 | + if ($venue->ID() == $VNU_ID) { |
|
85 | + EEH_Venue_View::$_venue = $venue; |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + // no venue ID ? |
|
91 | + // then the global post is an events post and this function was called with no argument |
|
92 | + } else { |
|
93 | + // just grab the first related event venue |
|
94 | + EEH_Venue_View::$_venue = reset($venues); |
|
95 | + } |
|
96 | + } |
|
97 | + break; |
|
98 | + } |
|
99 | + } |
|
100 | + // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
101 | + if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
102 | + // sigh... pull it from the db |
|
103 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
104 | + } |
|
105 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * return a single venue |
|
111 | + * |
|
112 | + * @param bool $privacy_check Defaults to true. |
|
113 | + * When false, means even if the venue is private we return it regardless of access. |
|
114 | + * @param bool $password_check |
|
115 | + * @return EE_Venue |
|
116 | + * @throws EE_Error |
|
117 | + * @throws ReflectionException |
|
118 | + */ |
|
119 | + protected static function _get_venue($privacy_check = true, $password_check = true) |
|
120 | + { |
|
121 | + // check for private venues. |
|
122 | + if ( |
|
123 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
124 | + && EEH_Venue_View::$_venue->status() == 'private' |
|
125 | + && $privacy_check |
|
126 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
127 | + ) { |
|
128 | + return null; |
|
129 | + } |
|
130 | + // check for password protected venues |
|
131 | + if ( |
|
132 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
133 | + && $password_check |
|
134 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
135 | + ) { |
|
136 | + return null; |
|
137 | + } |
|
138 | + return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * get_event_venues |
|
144 | + * |
|
145 | + * @access public |
|
146 | + * @return EE_Venue[] |
|
147 | + * @throws EE_Error |
|
148 | + * @throws ReflectionException |
|
149 | + */ |
|
150 | + public static function get_event_venues() |
|
151 | + { |
|
152 | + global $post; |
|
153 | + if ($post->post_type == 'espresso_events') { |
|
154 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
155 | + return $post->EE_Event->venues(); |
|
156 | + } |
|
157 | + } |
|
158 | + return []; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
164 | + * |
|
165 | + * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but |
|
166 | + * is not private. So it is important to do explicit boolean checks when using this conditional. |
|
167 | + * |
|
168 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
169 | + * |
|
170 | + * @return bool|null |
|
171 | + * @throws EE_Error |
|
172 | + * @throws ReflectionException |
|
173 | + */ |
|
174 | + public static function is_venue_private($VNU_ID = false) |
|
175 | + { |
|
176 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
177 | + if (! $venue instanceof EE_Venue) { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + return $venue->status() == 'private'; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * returns true or false if a venue is password protected or not |
|
187 | + * |
|
188 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public static function is_venue_password_protected($VNU_ID = false) |
|
194 | + { |
|
195 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
196 | + if ( |
|
197 | + $venue instanceof EE_Venue |
|
198 | + && post_password_required($venue->ID()) |
|
199 | + ) { |
|
200 | + return true; |
|
201 | + } |
|
202 | + return false; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * If a venue is password protected, this will return the password form for gaining access |
|
208 | + * returns an empty string otherwise |
|
209 | + * |
|
210 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
211 | + * |
|
212 | + * @return string |
|
213 | + * @throws EE_Error |
|
214 | + * @throws ReflectionException |
|
215 | + */ |
|
216 | + public static function password_protected_venue_form($VNU_ID = false) |
|
217 | + { |
|
218 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
219 | + if ( |
|
220 | + $venue instanceof EE_Venue |
|
221 | + && post_password_required($venue->ID()) |
|
222 | + ) { |
|
223 | + return get_the_password_form($venue->ID()); |
|
224 | + } |
|
225 | + return ''; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * venue_description |
|
231 | + * |
|
232 | + * @access public |
|
233 | + * @param int $VNU_ID |
|
234 | + * @return string |
|
235 | + * @throws EE_Error |
|
236 | + * @throws ReflectionException |
|
237 | + */ |
|
238 | + public static function venue_description($VNU_ID = 0) |
|
239 | + { |
|
240 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
241 | + if ($venue instanceof EE_Venue) { |
|
242 | + return $venue->get_pretty('VNU_desc'); |
|
243 | + } |
|
244 | + return ''; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * venue_excerpt |
|
250 | + * |
|
251 | + * @access public |
|
252 | + * @param int $VNU_ID |
|
253 | + * @return string |
|
254 | + * @throws EE_Error |
|
255 | + * @throws ReflectionException |
|
256 | + */ |
|
257 | + public static function venue_excerpt($VNU_ID = 0) |
|
258 | + { |
|
259 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
260 | + if ($venue instanceof EE_Venue) { |
|
261 | + $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
262 | + $venue_link = ' ' . EEH_Venue_View::venue_details_link( |
|
263 | + $venue->ID(), |
|
264 | + esc_html__('more', 'event_espresso') . '…' |
|
265 | + ); |
|
266 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
267 | + } |
|
268 | + return ''; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * venue_categories |
|
274 | + * |
|
275 | + * @access public |
|
276 | + * @param int $VNU_ID |
|
277 | + * @param bool $hide_uncategorized |
|
278 | + * @return string |
|
279 | + * @throws EE_Error |
|
280 | + * @throws ReflectionException |
|
281 | + */ |
|
282 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
283 | + { |
|
284 | + $category_links = []; |
|
285 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
286 | + if ($venue instanceof EE_Venue) { |
|
287 | + // get category terms |
|
288 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
289 | + // loop thru terms and create links |
|
290 | + foreach ($venue_categories as $term) { |
|
291 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
292 | + if ( |
|
293 | + ! is_wp_error($url) |
|
294 | + && (($hide_uncategorized |
|
295 | + && strtolower($term->name) != esc_html__( |
|
296 | + 'uncategorized', |
|
297 | + 'event_espresso' |
|
298 | + )) |
|
299 | + || ! $hide_uncategorized) |
|
300 | + ) { |
|
301 | + $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | + return implode(', ', $category_links); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * venue_address |
|
312 | + * |
|
313 | + * @access public |
|
314 | + * @param string $type |
|
315 | + * @param int $VNU_ID |
|
316 | + * @param bool $use_schema |
|
317 | + * @param bool $add_wrapper |
|
318 | + * @return string |
|
319 | + * @throws EE_Error |
|
320 | + * @throws ReflectionException |
|
321 | + */ |
|
322 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
323 | + { |
|
324 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
325 | + if ($venue instanceof EE_Venue) { |
|
326 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
327 | + } |
|
328 | + return ''; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * venue_has_address |
|
334 | + * |
|
335 | + * @access public |
|
336 | + * @param int $VNU_ID |
|
337 | + * @return bool|string |
|
338 | + * @throws EE_Error |
|
339 | + * @throws ReflectionException |
|
340 | + */ |
|
341 | + public static function venue_has_address($VNU_ID = 0) |
|
342 | + { |
|
343 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
344 | + if ($venue instanceof EE_Venue) { |
|
345 | + return EEH_Address::format($venue, 'inline', false, false); |
|
346 | + } |
|
347 | + return false; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * venue_name |
|
353 | + * |
|
354 | + * @access public |
|
355 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to |
|
356 | + * the Venue's details page or website |
|
357 | + * @param int $VNU_ID |
|
358 | + * @return string |
|
359 | + * @throws EE_Error |
|
360 | + * @throws ReflectionException |
|
361 | + */ |
|
362 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
363 | + { |
|
364 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
365 | + if ($venue instanceof EE_Venue) { |
|
366 | + $venue_name = apply_filters( |
|
367 | + 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
368 | + EEH_Venue_View::is_venue_private() |
|
369 | + ? EEH_Venue_View::$_venue->name() . " " . esc_html__('(Private)', 'event_espresso') |
|
370 | + : EEH_Venue_View::$_venue->name(), |
|
371 | + EEH_Venue_View::$_venue |
|
372 | + ); |
|
373 | + $venue_name = EEH_Schema::name($venue_name); |
|
374 | + |
|
375 | + // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
376 | + if ($venue->get('status') == 'trash') { |
|
377 | + $link_to = ''; |
|
378 | + } |
|
379 | + switch ($link_to) { |
|
380 | + case 'details': |
|
381 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
382 | + |
|
383 | + case 'website': |
|
384 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
385 | + |
|
386 | + default: |
|
387 | + return $venue_name; |
|
388 | + } |
|
389 | + } |
|
390 | + return ''; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * venue_details_link |
|
396 | + * |
|
397 | + * @access public |
|
398 | + * @param int $VNU_ID |
|
399 | + * @param string $text |
|
400 | + * @return string |
|
401 | + * @throws EE_Error |
|
402 | + * @throws ReflectionException |
|
403 | + */ |
|
404 | + public static function venue_details_link($VNU_ID = 0, $text = '') |
|
405 | + { |
|
406 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
407 | + if ($venue instanceof EE_Venue) { |
|
408 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
409 | + } |
|
410 | + return ''; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * venue_website_link |
|
416 | + * |
|
417 | + * @access public |
|
418 | + * @param int $VNU_ID |
|
419 | + * @param string $text |
|
420 | + * @return string |
|
421 | + * @throws EE_Error |
|
422 | + * @throws ReflectionException |
|
423 | + */ |
|
424 | + public static function venue_website_link($VNU_ID = 0, $text = '') |
|
425 | + { |
|
426 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
427 | + if ($venue instanceof EE_Venue) { |
|
428 | + $url = $venue->venue_url(); |
|
429 | + $text = ! empty($text) ? $text : $url; |
|
430 | + return ! empty($url) ? EEH_Schema::url($url, $text, ['target' => '_blank']) : ''; |
|
431 | + } |
|
432 | + return ''; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * venue_phone |
|
438 | + * |
|
439 | + * @access public |
|
440 | + * @param int $VNU_ID |
|
441 | + * @return string |
|
442 | + * @throws EE_Error |
|
443 | + * @throws ReflectionException |
|
444 | + */ |
|
445 | + public static function venue_phone($VNU_ID = 0) |
|
446 | + { |
|
447 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
448 | + if ($venue instanceof EE_Venue) { |
|
449 | + return EEH_Schema::telephone($venue->phone()); |
|
450 | + } |
|
451 | + return ''; |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * venue_gmap |
|
457 | + * |
|
458 | + * @access public |
|
459 | + * @param int $VNU_ID |
|
460 | + * @param bool|string $map_ID a unique identifier for this map |
|
461 | + * @param array $gmap map options |
|
462 | + * @return string |
|
463 | + * @throws EE_Error |
|
464 | + * @throws ReflectionException |
|
465 | + */ |
|
466 | + public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = []) |
|
467 | + { |
|
468 | + |
|
469 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
470 | + if ($venue instanceof EE_Venue) { |
|
471 | + // check for global espresso_events post and use it's ID if no map_ID is set |
|
472 | + global $post; |
|
473 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
474 | + // grab map settings |
|
475 | + $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
476 | + // are maps enabled ? |
|
477 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
478 | + $details_page = is_single(); |
|
479 | + $options = []; |
|
480 | + |
|
481 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() |
|
482 | + ? $map_ID . '-' . $venue->ID() |
|
483 | + : $venue->ID(); |
|
484 | + |
|
485 | + $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
486 | + |
|
487 | + $options['ee_map_width'] = $details_page |
|
488 | + ? $map_cfg->event_details_map_width |
|
489 | + : $map_cfg->event_list_map_width; |
|
490 | + |
|
491 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) |
|
492 | + ? $gmap['ee_map_width'] |
|
493 | + : $options['ee_map_width']; |
|
494 | + |
|
495 | + $options['ee_map_height'] = $details_page |
|
496 | + ? $map_cfg->event_details_map_height |
|
497 | + : $map_cfg->event_list_map_height; |
|
498 | + |
|
499 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) |
|
500 | + ? $gmap['ee_map_height'] |
|
501 | + : $options['ee_map_height']; |
|
502 | + |
|
503 | + $options['ee_map_zoom'] = $details_page |
|
504 | + ? $map_cfg->event_details_map_zoom |
|
505 | + : $map_cfg->event_list_map_zoom; |
|
506 | + |
|
507 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) |
|
508 | + ? $gmap['ee_map_zoom'] |
|
509 | + : $options['ee_map_zoom']; |
|
510 | + |
|
511 | + $options['ee_map_nav_display'] = $details_page |
|
512 | + ? $map_cfg->event_details_display_nav |
|
513 | + : $map_cfg->event_list_display_nav; |
|
514 | + |
|
515 | + $options['ee_map_nav_display'] = |
|
516 | + isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) |
|
517 | + ? 'true' |
|
518 | + : $options['ee_map_nav_display']; |
|
519 | + |
|
520 | + $options['ee_map_nav_size'] = $details_page |
|
521 | + ? $map_cfg->event_details_nav_size |
|
522 | + : $map_cfg->event_list_nav_size; |
|
523 | + |
|
524 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) |
|
525 | + ? $gmap['ee_map_nav_size'] |
|
526 | + : $options['ee_map_nav_size']; |
|
527 | + |
|
528 | + $options['ee_map_type_control'] = $details_page |
|
529 | + ? $map_cfg->event_details_control_type |
|
530 | + : $map_cfg->event_list_control_type; |
|
531 | + |
|
532 | + $options['ee_map_type_control'] = |
|
533 | + isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) |
|
534 | + ? $gmap['ee_map_type_control'] |
|
535 | + : $options['ee_map_type_control']; |
|
536 | + |
|
537 | + $options['ee_map_align'] = $details_page |
|
538 | + ? $map_cfg->event_details_map_align |
|
539 | + : $map_cfg->event_list_map_align; |
|
540 | + |
|
541 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) |
|
542 | + ? $gmap['ee_map_align'] |
|
543 | + : $options['ee_map_align']; |
|
544 | + |
|
545 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) |
|
546 | + ? (bool) absint($gmap['ee_static_url']) |
|
547 | + : $venue->google_map_link(); |
|
548 | + |
|
549 | + return EEH_Maps::google_map($options); |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + return ''; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Gets the HTML to display a static map of the venue |
|
559 | + * |
|
560 | + * @param EE_Venue $venue |
|
561 | + * @param array $attributes like EEH_Maps::google_map_link |
|
562 | + * @return string |
|
563 | + * @throws EE_Error |
|
564 | + * @throws ReflectionException |
|
565 | + */ |
|
566 | + public static function espresso_google_static_map(EE_Venue $venue, $attributes = []) |
|
567 | + { |
|
568 | + $state = $venue->state_obj(); |
|
569 | + $country = $venue->country_obj(); |
|
570 | + $attributes = shortcode_atts( |
|
571 | + [ |
|
572 | + 'id' => $venue->ID(), |
|
573 | + 'address' => $venue->get('VNU_address'), |
|
574 | + 'city' => $venue->get('VNU_city'), |
|
575 | + 'state' => $state instanceof EE_State ? $state->name() : '', |
|
576 | + 'zip' => $venue->get('VNU_zip'), |
|
577 | + 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
578 | + 'type' => 'map', |
|
579 | + 'map_w' => 200, |
|
580 | + 'map_h' => 200, |
|
581 | + ], |
|
582 | + $attributes |
|
583 | + ); |
|
584 | + return EEH_Maps::google_map_link($attributes); |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * edit_venue_link |
|
590 | + * |
|
591 | + * @access public |
|
592 | + * @param int $VNU_ID |
|
593 | + * @param string $link |
|
594 | + * @param string $before |
|
595 | + * @param string $after |
|
596 | + * @return string |
|
597 | + * @throws EE_Error |
|
598 | + * @throws ReflectionException |
|
599 | + */ |
|
600 | + public static function edit_venue_link( |
|
601 | + $VNU_ID = 0, |
|
602 | + $link = '', |
|
603 | + $before = '<p class="edit-venue-lnk small-txt">', |
|
604 | + $after = '</p>' |
|
605 | + ) { |
|
606 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
607 | + if ($venue instanceof EE_Venue) { |
|
608 | + // can the user edit this post ? |
|
609 | + if (current_user_can('edit_post', $venue->ID())) { |
|
610 | + // set link text |
|
611 | + $link = ! empty($link) ? $link : esc_html__('edit this venue', 'event_espresso'); |
|
612 | + // generate nonce |
|
613 | + $nonce = wp_create_nonce('edit_nonce'); |
|
614 | + // generate url to venue editor for this venue |
|
615 | + $url = |
|
616 | + add_query_arg( |
|
617 | + [ |
|
618 | + 'page' => 'espresso_venues', |
|
619 | + 'action' => 'edit', |
|
620 | + 'post' => $venue->ID(), |
|
621 | + 'edit_nonce' => $nonce, |
|
622 | + ], |
|
623 | + admin_url('admin.php') |
|
624 | + ); |
|
625 | + // get edit CPT text |
|
626 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
627 | + // build final link html |
|
628 | + $link = |
|
629 | + '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( |
|
630 | + $post_type_obj->labels->edit_item |
|
631 | + ) . '">' . $link . '</a>'; |
|
632 | + // put it all together |
|
633 | + return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
634 | + } |
|
635 | + } |
|
636 | + return ''; |
|
637 | + } |
|
638 | 638 | } |