@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | } |
83 | 83 | return $this->shortcodeContent( |
84 | - $this->sanitizeAttributes((array)$attributes) |
|
84 | + $this->sanitizeAttributes((array) $attributes) |
|
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | // serialized attributes |
110 | 110 | wp_json_encode($attributes), |
111 | 111 | // Closure for generating content if cache is expired |
112 | - function () use ($shortcode, $attributes) { |
|
113 | - if($shortcode->initialized === false){ |
|
112 | + function() use ($shortcode, $attributes) { |
|
113 | + if ($shortcode->initialized === false) { |
|
114 | 114 | $shortcode->initializeShortcode(); |
115 | 115 | } |
116 | 116 | return $shortcode->processShortcode($attributes); |
@@ -21,219 +21,219 @@ |
||
21 | 21 | abstract class EspressoShortcode implements ShortcodeInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * transient prefix |
|
26 | - * |
|
27 | - * @type string |
|
28 | - */ |
|
29 | - const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var PostRelatedCacheManager $cache_manager |
|
33 | - */ |
|
34 | - private $cache_manager; |
|
35 | - |
|
36 | - /** |
|
37 | - * true if ShortcodeInterface::initializeShortcode() has been called |
|
38 | - * if false, then that will get called before processing |
|
39 | - * |
|
40 | - * @var boolean $initialized |
|
41 | - */ |
|
42 | - private $initialized = false; |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * EspressoShortcode constructor |
|
48 | - * |
|
49 | - * @param PostRelatedCacheManager $cache_manager |
|
50 | - */ |
|
51 | - public function __construct(PostRelatedCacheManager $cache_manager) |
|
52 | - { |
|
53 | - $this->cache_manager = $cache_manager; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - public function shortcodeHasBeenInitialized() |
|
62 | - { |
|
63 | - $this->initialized = true; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * enqueues scripts then processes the shortcode |
|
70 | - * |
|
71 | - * @param array $attributes |
|
72 | - * @return string |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - final public function processShortcodeCallback($attributes = array()) |
|
76 | - { |
|
77 | - if ($this instanceof EnqueueAssetsInterface) { |
|
78 | - if (is_admin()) { |
|
79 | - $this->enqueueAdminScripts(); |
|
80 | - } else { |
|
81 | - $this->enqueueScripts(); |
|
82 | - } |
|
83 | - } |
|
84 | - return $this->shortcodeContent( |
|
85 | - $this->sanitizeAttributes((array)$attributes) |
|
86 | - ); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * If shortcode caching is enabled for the shortcode, |
|
93 | - * and cached results exist, then that will be returned |
|
94 | - * else new content will be generated. |
|
95 | - * If caching is enabled, then the new content will be cached for later. |
|
96 | - * |
|
97 | - * @param array $attributes |
|
98 | - * @return mixed|string |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - private function shortcodeContent(array $attributes) |
|
102 | - { |
|
103 | - $shortcode = $this; |
|
104 | - $post_ID = $this->currentPostID(); |
|
105 | - // something like "SC_EVENTS-123" |
|
106 | - $cache_ID = $this->shortcodeCacheID($post_ID); |
|
107 | - $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
108 | - return $this->cache_manager->get( |
|
109 | - $cache_ID, |
|
110 | - // serialized attributes |
|
111 | - wp_json_encode($attributes), |
|
112 | - // Closure for generating content if cache is expired |
|
113 | - function () use ($shortcode, $attributes) { |
|
114 | - if($shortcode->initialized === false){ |
|
115 | - $shortcode->initializeShortcode(); |
|
116 | - } |
|
117 | - return $shortcode->processShortcode($attributes); |
|
118 | - }, |
|
119 | - // filterable cache expiration set by each shortcode |
|
120 | - apply_filters( |
|
121 | - 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
122 | - $this->cacheExpiration(), |
|
123 | - $this->getTag(), |
|
124 | - $this |
|
125 | - ) |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return int |
|
133 | - * @throws EE_Error |
|
134 | - */ |
|
135 | - private function currentPostID() |
|
136 | - { |
|
137 | - // try to get EE_Event any way we can |
|
138 | - $event = EEH_Event_View::get_event(); |
|
139 | - // then get some kind of ID |
|
140 | - if ($event instanceof \EE_Event) { |
|
141 | - $post_ID = $event->ID(); |
|
142 | - } else { |
|
143 | - global $post; |
|
144 | - $post_ID = $post->ID; |
|
145 | - } |
|
146 | - return $post_ID; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param int $post_ID |
|
153 | - * @return string |
|
154 | - * @throws EE_Error |
|
155 | - */ |
|
156 | - private function shortcodeCacheID($post_ID) |
|
157 | - { |
|
158 | - $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
159 | - return "SC_{$tag}-{$post_ID}"; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * array for defining custom attribute sanitization callbacks, |
|
166 | - * where keys match keys in your attributes array, |
|
167 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
168 | - * So for example, if you had an integer attribute named "event_id" |
|
169 | - * that you wanted to be sanitized using absint(), |
|
170 | - * then you would return the following: |
|
171 | - * array('event_id' => 'absint') |
|
172 | - * Entering 'skip_sanitization' for the callback value |
|
173 | - * means that no sanitization will be applied |
|
174 | - * on the assumption that the attribute |
|
175 | - * will be sanitized at some point... right? |
|
176 | - * You wouldn't pass around unsanitized attributes would you? |
|
177 | - * That would be very Tom Foolery of you!!! |
|
178 | - * |
|
179 | - * @return array |
|
180 | - */ |
|
181 | - protected function customAttributeSanitizationMap() |
|
182 | - { |
|
183 | - return array(); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Performs basic sanitization on shortcode attributes |
|
190 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
191 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
192 | - * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
193 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
194 | - * |
|
195 | - * @param array $attributes |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - private function sanitizeAttributes(array $attributes) |
|
199 | - { |
|
200 | - $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
201 | - foreach ($attributes as $key => $value) { |
|
202 | - // is a custom sanitization callback specified ? |
|
203 | - if (isset($custom_sanitization[$key])) { |
|
204 | - $callback = $custom_sanitization[$key]; |
|
205 | - if ($callback === 'skip_sanitization') { |
|
206 | - $attributes[$key] = $value; |
|
207 | - continue; |
|
208 | - } |
|
209 | - if (function_exists($callback)) { |
|
210 | - $attributes[$key] = $callback($value); |
|
211 | - continue; |
|
212 | - } |
|
213 | - } |
|
214 | - switch (true) { |
|
215 | - case $value === null : |
|
216 | - case is_int($value) : |
|
217 | - case is_float($value) : |
|
218 | - // typical booleans |
|
219 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
220 | - $attributes[$key] = $value; |
|
221 | - break; |
|
222 | - case is_string($value) : |
|
223 | - $attributes[$key] = sanitize_text_field($value); |
|
224 | - break; |
|
225 | - case is_array($value) : |
|
226 | - $attributes[$key] = $this->sanitizeAttributes($value); |
|
227 | - break; |
|
228 | - default : |
|
229 | - // only remaining data types are Object and Resource |
|
230 | - // which are not allowed as shortcode attributes |
|
231 | - $attributes[$key] = null; |
|
232 | - break; |
|
233 | - } |
|
234 | - } |
|
235 | - return $attributes; |
|
236 | - } |
|
24 | + /** |
|
25 | + * transient prefix |
|
26 | + * |
|
27 | + * @type string |
|
28 | + */ |
|
29 | + const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var PostRelatedCacheManager $cache_manager |
|
33 | + */ |
|
34 | + private $cache_manager; |
|
35 | + |
|
36 | + /** |
|
37 | + * true if ShortcodeInterface::initializeShortcode() has been called |
|
38 | + * if false, then that will get called before processing |
|
39 | + * |
|
40 | + * @var boolean $initialized |
|
41 | + */ |
|
42 | + private $initialized = false; |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * EspressoShortcode constructor |
|
48 | + * |
|
49 | + * @param PostRelatedCacheManager $cache_manager |
|
50 | + */ |
|
51 | + public function __construct(PostRelatedCacheManager $cache_manager) |
|
52 | + { |
|
53 | + $this->cache_manager = $cache_manager; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + public function shortcodeHasBeenInitialized() |
|
62 | + { |
|
63 | + $this->initialized = true; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * enqueues scripts then processes the shortcode |
|
70 | + * |
|
71 | + * @param array $attributes |
|
72 | + * @return string |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + final public function processShortcodeCallback($attributes = array()) |
|
76 | + { |
|
77 | + if ($this instanceof EnqueueAssetsInterface) { |
|
78 | + if (is_admin()) { |
|
79 | + $this->enqueueAdminScripts(); |
|
80 | + } else { |
|
81 | + $this->enqueueScripts(); |
|
82 | + } |
|
83 | + } |
|
84 | + return $this->shortcodeContent( |
|
85 | + $this->sanitizeAttributes((array)$attributes) |
|
86 | + ); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * If shortcode caching is enabled for the shortcode, |
|
93 | + * and cached results exist, then that will be returned |
|
94 | + * else new content will be generated. |
|
95 | + * If caching is enabled, then the new content will be cached for later. |
|
96 | + * |
|
97 | + * @param array $attributes |
|
98 | + * @return mixed|string |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + private function shortcodeContent(array $attributes) |
|
102 | + { |
|
103 | + $shortcode = $this; |
|
104 | + $post_ID = $this->currentPostID(); |
|
105 | + // something like "SC_EVENTS-123" |
|
106 | + $cache_ID = $this->shortcodeCacheID($post_ID); |
|
107 | + $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
108 | + return $this->cache_manager->get( |
|
109 | + $cache_ID, |
|
110 | + // serialized attributes |
|
111 | + wp_json_encode($attributes), |
|
112 | + // Closure for generating content if cache is expired |
|
113 | + function () use ($shortcode, $attributes) { |
|
114 | + if($shortcode->initialized === false){ |
|
115 | + $shortcode->initializeShortcode(); |
|
116 | + } |
|
117 | + return $shortcode->processShortcode($attributes); |
|
118 | + }, |
|
119 | + // filterable cache expiration set by each shortcode |
|
120 | + apply_filters( |
|
121 | + 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
122 | + $this->cacheExpiration(), |
|
123 | + $this->getTag(), |
|
124 | + $this |
|
125 | + ) |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return int |
|
133 | + * @throws EE_Error |
|
134 | + */ |
|
135 | + private function currentPostID() |
|
136 | + { |
|
137 | + // try to get EE_Event any way we can |
|
138 | + $event = EEH_Event_View::get_event(); |
|
139 | + // then get some kind of ID |
|
140 | + if ($event instanceof \EE_Event) { |
|
141 | + $post_ID = $event->ID(); |
|
142 | + } else { |
|
143 | + global $post; |
|
144 | + $post_ID = $post->ID; |
|
145 | + } |
|
146 | + return $post_ID; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param int $post_ID |
|
153 | + * @return string |
|
154 | + * @throws EE_Error |
|
155 | + */ |
|
156 | + private function shortcodeCacheID($post_ID) |
|
157 | + { |
|
158 | + $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
159 | + return "SC_{$tag}-{$post_ID}"; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * array for defining custom attribute sanitization callbacks, |
|
166 | + * where keys match keys in your attributes array, |
|
167 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
168 | + * So for example, if you had an integer attribute named "event_id" |
|
169 | + * that you wanted to be sanitized using absint(), |
|
170 | + * then you would return the following: |
|
171 | + * array('event_id' => 'absint') |
|
172 | + * Entering 'skip_sanitization' for the callback value |
|
173 | + * means that no sanitization will be applied |
|
174 | + * on the assumption that the attribute |
|
175 | + * will be sanitized at some point... right? |
|
176 | + * You wouldn't pass around unsanitized attributes would you? |
|
177 | + * That would be very Tom Foolery of you!!! |
|
178 | + * |
|
179 | + * @return array |
|
180 | + */ |
|
181 | + protected function customAttributeSanitizationMap() |
|
182 | + { |
|
183 | + return array(); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Performs basic sanitization on shortcode attributes |
|
190 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
191 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
192 | + * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
193 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
194 | + * |
|
195 | + * @param array $attributes |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + private function sanitizeAttributes(array $attributes) |
|
199 | + { |
|
200 | + $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
201 | + foreach ($attributes as $key => $value) { |
|
202 | + // is a custom sanitization callback specified ? |
|
203 | + if (isset($custom_sanitization[$key])) { |
|
204 | + $callback = $custom_sanitization[$key]; |
|
205 | + if ($callback === 'skip_sanitization') { |
|
206 | + $attributes[$key] = $value; |
|
207 | + continue; |
|
208 | + } |
|
209 | + if (function_exists($callback)) { |
|
210 | + $attributes[$key] = $callback($value); |
|
211 | + continue; |
|
212 | + } |
|
213 | + } |
|
214 | + switch (true) { |
|
215 | + case $value === null : |
|
216 | + case is_int($value) : |
|
217 | + case is_float($value) : |
|
218 | + // typical booleans |
|
219 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
220 | + $attributes[$key] = $value; |
|
221 | + break; |
|
222 | + case is_string($value) : |
|
223 | + $attributes[$key] = sanitize_text_field($value); |
|
224 | + break; |
|
225 | + case is_array($value) : |
|
226 | + $attributes[$key] = $this->sanitizeAttributes($value); |
|
227 | + break; |
|
228 | + default : |
|
229 | + // only remaining data types are Object and Resource |
|
230 | + // which are not allowed as shortcode attributes |
|
231 | + $attributes[$key] = null; |
|
232 | + break; |
|
233 | + } |
|
234 | + } |
|
235 | + return $attributes; |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | 239 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace EventEspresso\core\exceptions; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -18,32 +18,32 @@ discard block |
||
18 | 18 | class InvalidEntityException extends \InvalidArgumentException |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * InvalidInterfaceException constructor. |
|
23 | - * |
|
24 | - * @param string $actual classname of what we got |
|
25 | - * @param string $expected classname of the entity we wanted |
|
26 | - * @param string $message |
|
27 | - * @param int $code |
|
28 | - * @param \Exception $previous |
|
29 | - */ |
|
30 | - public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
31 | - { |
|
32 | - if (empty($message)) { |
|
33 | - $message = sprintf( |
|
34 | - __( |
|
35 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - is_object($actual) |
|
39 | - ? get_class($actual) |
|
40 | - : gettype($actual), |
|
41 | - $expected, |
|
42 | - var_export($actual, true) |
|
43 | - ); |
|
44 | - } |
|
45 | - parent::__construct($message, $code, $previous); |
|
46 | - } |
|
21 | + /** |
|
22 | + * InvalidInterfaceException constructor. |
|
23 | + * |
|
24 | + * @param string $actual classname of what we got |
|
25 | + * @param string $expected classname of the entity we wanted |
|
26 | + * @param string $message |
|
27 | + * @param int $code |
|
28 | + * @param \Exception $previous |
|
29 | + */ |
|
30 | + public function __construct($actual, $expected, $message = '', $code = 0, \Exception $previous = null) |
|
31 | + { |
|
32 | + if (empty($message)) { |
|
33 | + $message = sprintf( |
|
34 | + __( |
|
35 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + is_object($actual) |
|
39 | + ? get_class($actual) |
|
40 | + : gettype($actual), |
|
41 | + $expected, |
|
42 | + var_export($actual, true) |
|
43 | + ); |
|
44 | + } |
|
45 | + parent::__construct($message, $code, $previous); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | // End of file InvalidEntityException.php |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace EventEspresso\core\exceptions; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('No direct script access allowed'); |
7 | 7 | } |
8 | 8 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,117 +15,117 @@ discard block |
||
15 | 15 | class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param null $validation_error_message |
|
20 | - */ |
|
21 | - public function __construct($validation_error_message = null) |
|
22 | - { |
|
23 | - if (! $validation_error_message) { |
|
24 | - $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
|
25 | - } |
|
26 | - parent::__construct($validation_error_message); |
|
27 | - } |
|
18 | + /** |
|
19 | + * @param null $validation_error_message |
|
20 | + */ |
|
21 | + public function __construct($validation_error_message = null) |
|
22 | + { |
|
23 | + if (! $validation_error_message) { |
|
24 | + $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
|
25 | + } |
|
26 | + parent::__construct($validation_error_message); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * just checks the field isn't blank |
|
33 | - * |
|
34 | - * @param $normalized_value |
|
35 | - * @return bool |
|
36 | - * @throws \EE_Validation_Error |
|
37 | - */ |
|
38 | - public function validate($normalized_value) |
|
39 | - { |
|
40 | - if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
41 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
42 | - } |
|
43 | - } |
|
31 | + /** |
|
32 | + * just checks the field isn't blank |
|
33 | + * |
|
34 | + * @param $normalized_value |
|
35 | + * @return bool |
|
36 | + * @throws \EE_Validation_Error |
|
37 | + */ |
|
38 | + public function validate($normalized_value) |
|
39 | + { |
|
40 | + if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
41 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function get_jquery_validation_rule_array() |
|
51 | - { |
|
52 | - return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
53 | - } |
|
47 | + /** |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function get_jquery_validation_rule_array() |
|
51 | + { |
|
52 | + return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Validate an email address. |
|
59 | - * Provide email address (raw input) |
|
60 | - * |
|
61 | - * @param $email |
|
62 | - * @return bool of whether the email is valid or not |
|
63 | - * @throws \EE_Validation_Error |
|
64 | - */ |
|
65 | - private function _validate_email($email) |
|
66 | - { |
|
67 | - $validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
68 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
69 | - : 'wp_default'; |
|
70 | - if (! preg_match('/^.+\@\S+$/', $email)) { // \.\S+ |
|
71 | - // email not in correct {string}@{string} format |
|
72 | - return false; |
|
73 | - } else { |
|
74 | - $atIndex = strrpos($email, "@"); |
|
75 | - $domain = substr($email, $atIndex + 1); |
|
76 | - $local = substr($email, 0, $atIndex); |
|
77 | - $localLen = strlen($local); |
|
78 | - $domainLen = strlen($domain); |
|
79 | - if ($localLen < 1 || $localLen > 64) { |
|
80 | - // local part length exceeded |
|
81 | - return false; |
|
82 | - } else if ($domainLen < 1 || $domainLen > 255) { |
|
83 | - // domain part length exceeded |
|
84 | - return false; |
|
85 | - } else if ($local[0] === '.' || $local[$localLen - 1] === '.') { |
|
86 | - // local part starts or ends with '.' |
|
87 | - return false; |
|
88 | - } else if (preg_match('/\\.\\./', $local)) { |
|
89 | - // local part has two consecutive dots |
|
90 | - return false; |
|
91 | - } else if (preg_match('/\\.\\./', $domain)) { |
|
92 | - // domain part has two consecutive dots |
|
93 | - return false; |
|
94 | - } else if ($validation_level === 'wp_default') { |
|
95 | - return is_email($email); |
|
96 | - } else if ( |
|
97 | - ($validation_level === 'i18n' || $validation_level === 'i18n_dns') |
|
98 | - // plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
99 | - && ! preg_match( |
|
100 | - '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
101 | ||
102 | - ) |
|
103 | - ) { |
|
104 | - return false; |
|
105 | - } |
|
106 | - if ($validation_level === 'i18n_dns') { |
|
107 | - if (! checkdnsrr($domain, "MX")) { |
|
108 | - // domain not found in MX records |
|
109 | - throw new EE_Validation_Error( |
|
110 | - __( |
|
111 | - 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
112 | - 'event_espresso' |
|
113 | - ) |
|
114 | - ); |
|
115 | - } else if (! checkdnsrr($domain, "A")) { |
|
116 | - // domain not found in A records |
|
117 | - throw new EE_Validation_Error( |
|
118 | - __( |
|
119 | - 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
120 | - 'event_espresso' |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - // you have successfully run the gauntlet young Padawan |
|
127 | - return true; |
|
128 | - } |
|
57 | + /** |
|
58 | + * Validate an email address. |
|
59 | + * Provide email address (raw input) |
|
60 | + * |
|
61 | + * @param $email |
|
62 | + * @return bool of whether the email is valid or not |
|
63 | + * @throws \EE_Validation_Error |
|
64 | + */ |
|
65 | + private function _validate_email($email) |
|
66 | + { |
|
67 | + $validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
68 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
69 | + : 'wp_default'; |
|
70 | + if (! preg_match('/^.+\@\S+$/', $email)) { // \.\S+ |
|
71 | + // email not in correct {string}@{string} format |
|
72 | + return false; |
|
73 | + } else { |
|
74 | + $atIndex = strrpos($email, "@"); |
|
75 | + $domain = substr($email, $atIndex + 1); |
|
76 | + $local = substr($email, 0, $atIndex); |
|
77 | + $localLen = strlen($local); |
|
78 | + $domainLen = strlen($domain); |
|
79 | + if ($localLen < 1 || $localLen > 64) { |
|
80 | + // local part length exceeded |
|
81 | + return false; |
|
82 | + } else if ($domainLen < 1 || $domainLen > 255) { |
|
83 | + // domain part length exceeded |
|
84 | + return false; |
|
85 | + } else if ($local[0] === '.' || $local[$localLen - 1] === '.') { |
|
86 | + // local part starts or ends with '.' |
|
87 | + return false; |
|
88 | + } else if (preg_match('/\\.\\./', $local)) { |
|
89 | + // local part has two consecutive dots |
|
90 | + return false; |
|
91 | + } else if (preg_match('/\\.\\./', $domain)) { |
|
92 | + // domain part has two consecutive dots |
|
93 | + return false; |
|
94 | + } else if ($validation_level === 'wp_default') { |
|
95 | + return is_email($email); |
|
96 | + } else if ( |
|
97 | + ($validation_level === 'i18n' || $validation_level === 'i18n_dns') |
|
98 | + // plz see http://stackoverflow.com/a/24817336 re: the following regex |
|
99 | + && ! preg_match( |
|
100 | + '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u', |
|
101 | ||
102 | + ) |
|
103 | + ) { |
|
104 | + return false; |
|
105 | + } |
|
106 | + if ($validation_level === 'i18n_dns') { |
|
107 | + if (! checkdnsrr($domain, "MX")) { |
|
108 | + // domain not found in MX records |
|
109 | + throw new EE_Validation_Error( |
|
110 | + __( |
|
111 | + 'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.', |
|
112 | + 'event_espresso' |
|
113 | + ) |
|
114 | + ); |
|
115 | + } else if (! checkdnsrr($domain, "A")) { |
|
116 | + // domain not found in A records |
|
117 | + throw new EE_Validation_Error( |
|
118 | + __( |
|
119 | + 'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.', |
|
120 | + 'event_espresso' |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + // you have successfully run the gauntlet young Padawan |
|
127 | + return true; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | 131 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function __construct($validation_error_message = null) |
22 | 22 | { |
23 | - if (! $validation_error_message) { |
|
23 | + if ( ! $validation_error_message) { |
|
24 | 24 | $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
25 | 25 | } |
26 | 26 | parent::__construct($validation_error_message); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
68 | 68 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
69 | 69 | : 'wp_default'; |
70 | - if (! preg_match('/^.+\@\S+$/', $email)) { // \.\S+ |
|
70 | + if ( ! preg_match('/^.+\@\S+$/', $email)) { // \.\S+ |
|
71 | 71 | // email not in correct {string}@{string} format |
72 | 72 | return false; |
73 | 73 | } else { |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | if ($validation_level === 'i18n_dns') { |
107 | - if (! checkdnsrr($domain, "MX")) { |
|
107 | + if ( ! checkdnsrr($domain, "MX")) { |
|
108 | 108 | // domain not found in MX records |
109 | 109 | throw new EE_Validation_Error( |
110 | 110 | __( |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | 'event_espresso' |
113 | 113 | ) |
114 | 114 | ); |
115 | - } else if (! checkdnsrr($domain, "A")) { |
|
115 | + } else if ( ! checkdnsrr($domain, "A")) { |
|
116 | 116 | // domain not found in A records |
117 | 117 | throw new EE_Validation_Error( |
118 | 118 | __( |
@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * This retrieves any EE_Message_Template_Group in the repo by its ID. |
49 | 49 | * |
50 | - * @param $GRP_ID |
|
50 | + * @param integer $GRP_ID |
|
51 | 51 | * @return EE_Message_Template_Group | null |
52 | 52 | */ |
53 | 53 | public function get_by_ID($GRP_ID) |
@@ -14,115 +14,115 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * EE_Message_Template_Group_Collection constructor. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - $this->interface = 'EE_Message_Template_Group'; |
|
23 | - } |
|
17 | + /** |
|
18 | + * EE_Message_Template_Group_Collection constructor. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + $this->interface = 'EE_Message_Template_Group'; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Adds the Message Template Group object to the repository. |
|
28 | - * |
|
29 | - * @param $message_template_group |
|
30 | - * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
31 | - * indexing the template by key. If this template is shared among multiple events then |
|
32 | - * include the events as an array. |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function add($message_template_group, $EVT_ID = array()) |
|
36 | - { |
|
37 | - $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
38 | - if ($message_template_group instanceof $this->interface) { |
|
39 | - $data['key'] = $this->getKey( |
|
40 | - $message_template_group->messenger(), |
|
41 | - $message_template_group->message_type(), |
|
42 | - $EVT_ID |
|
43 | - ); |
|
44 | - return parent::add($message_template_group, $data); |
|
45 | - } |
|
46 | - return false; |
|
47 | - } |
|
26 | + /** |
|
27 | + * Adds the Message Template Group object to the repository. |
|
28 | + * |
|
29 | + * @param $message_template_group |
|
30 | + * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
31 | + * indexing the template by key. If this template is shared among multiple events then |
|
32 | + * include the events as an array. |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function add($message_template_group, $EVT_ID = array()) |
|
36 | + { |
|
37 | + $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
38 | + if ($message_template_group instanceof $this->interface) { |
|
39 | + $data['key'] = $this->getKey( |
|
40 | + $message_template_group->messenger(), |
|
41 | + $message_template_group->message_type(), |
|
42 | + $EVT_ID |
|
43 | + ); |
|
44 | + return parent::add($message_template_group, $data); |
|
45 | + } |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
52 | - * |
|
53 | - * @param $GRP_ID |
|
54 | - * @return EE_Message_Template_Group | null |
|
55 | - */ |
|
56 | - public function get_by_ID($GRP_ID) |
|
57 | - { |
|
58 | - $this->rewind(); |
|
59 | - while ($this->valid()) { |
|
60 | - if ($this->current()->ID() === $GRP_ID) { |
|
61 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
62 | - $message_template_group = $this->current(); |
|
63 | - $this->rewind(); |
|
64 | - return $message_template_group; |
|
65 | - } |
|
66 | - $this->next(); |
|
67 | - } |
|
68 | - return null; |
|
69 | - } |
|
50 | + /** |
|
51 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
52 | + * |
|
53 | + * @param $GRP_ID |
|
54 | + * @return EE_Message_Template_Group | null |
|
55 | + */ |
|
56 | + public function get_by_ID($GRP_ID) |
|
57 | + { |
|
58 | + $this->rewind(); |
|
59 | + while ($this->valid()) { |
|
60 | + if ($this->current()->ID() === $GRP_ID) { |
|
61 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
62 | + $message_template_group = $this->current(); |
|
63 | + $this->rewind(); |
|
64 | + return $message_template_group; |
|
65 | + } |
|
66 | + $this->next(); |
|
67 | + } |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Generates a hash used to identify a given Message Template Group. |
|
74 | - * |
|
75 | - * @param string $messenger The EE_messenger->name |
|
76 | - * @param string $message_type The EE_message_type->name |
|
77 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
78 | - * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
82 | - { |
|
83 | - $EVT_ID = (array) $EVT_ID; |
|
84 | - return $this->getKey($messenger, $message_type, $EVT_ID); |
|
85 | - } |
|
72 | + /** |
|
73 | + * Generates a hash used to identify a given Message Template Group. |
|
74 | + * |
|
75 | + * @param string $messenger The EE_messenger->name |
|
76 | + * @param string $message_type The EE_message_type->name |
|
77 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
78 | + * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
82 | + { |
|
83 | + $EVT_ID = (array) $EVT_ID; |
|
84 | + return $this->getKey($messenger, $message_type, $EVT_ID); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * Generates a hash used to identify a given Message Template Group |
|
90 | - * @param string $messenger The EE_messenger->name |
|
91 | - * @param string $message_type The EE_message_type->name |
|
92 | - * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
93 | - * be included. |
|
94 | - * @since 4.9.40.rc.017 |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
98 | - { |
|
99 | - sort($EVT_ID); |
|
100 | - $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
101 | - return md5($messenger . $message_type . $EVT_ID); |
|
102 | - } |
|
88 | + /** |
|
89 | + * Generates a hash used to identify a given Message Template Group |
|
90 | + * @param string $messenger The EE_messenger->name |
|
91 | + * @param string $message_type The EE_message_type->name |
|
92 | + * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
93 | + * be included. |
|
94 | + * @since 4.9.40.rc.017 |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
98 | + { |
|
99 | + sort($EVT_ID); |
|
100 | + $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
101 | + return md5($messenger . $message_type . $EVT_ID); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
107 | - * the given string. |
|
108 | - * |
|
109 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
110 | - * @return null|EE_Message_Template_Group |
|
111 | - */ |
|
112 | - public function get_by_key($key) |
|
113 | - { |
|
114 | - $this->rewind(); |
|
115 | - while ($this->valid()) { |
|
116 | - $data = $this->getInfo(); |
|
117 | - if (isset($data['key']) && $data['key'] === $key) { |
|
118 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
119 | - $message_template_group = $this->current(); |
|
120 | - $this->rewind(); |
|
121 | - return $message_template_group; |
|
122 | - } |
|
123 | - $this->next(); |
|
124 | - } |
|
125 | - return null; |
|
126 | - } |
|
105 | + /** |
|
106 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
107 | + * the given string. |
|
108 | + * |
|
109 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
110 | + * @return null|EE_Message_Template_Group |
|
111 | + */ |
|
112 | + public function get_by_key($key) |
|
113 | + { |
|
114 | + $this->rewind(); |
|
115 | + while ($this->valid()) { |
|
116 | + $data = $this->getInfo(); |
|
117 | + if (isset($data['key']) && $data['key'] === $key) { |
|
118 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
119 | + $message_template_group = $this->current(); |
|
120 | + $this->rewind(); |
|
121 | + return $message_template_group; |
|
122 | + } |
|
123 | + $this->next(); |
|
124 | + } |
|
125 | + return null; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | } |
@@ -98,7 +98,7 @@ |
||
98 | 98 | { |
99 | 99 | sort($EVT_ID); |
100 | 100 | $EVT_ID = implode(',', array_unique($EVT_ID)); |
101 | - return md5($messenger . $message_type . $EVT_ID); |
|
101 | + return md5($messenger.$message_type.$EVT_ID); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidSessionDataException; |
3 | 3 | use EventEspresso\core\services\cache\CacheStorageInterface; |
4 | 4 | |
5 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
6 | 6 | /** |
7 | 7 | * |
8 | 8 | * EE_Session class |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * array for defining default session vars |
109 | 109 | * @var array |
110 | 110 | */ |
111 | - private $_default_session_vars = array ( |
|
111 | + private $_default_session_vars = array( |
|
112 | 112 | 'id' => null, |
113 | 113 | 'user_id' => null, |
114 | 114 | 'ip_address' => null, |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | // check if class object is instantiated |
137 | 137 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
138 | 138 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
139 | - if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) { |
|
140 | - self::$_instance = new self($cache_storage, $encryption ); |
|
139 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
140 | + self::$_instance = new self($cache_storage, $encryption); |
|
141 | 141 | } |
142 | 142 | return self::$_instance; |
143 | 143 | } |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | * @throws \EE_Error |
153 | 153 | * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
154 | 154 | */ |
155 | - protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null ) { |
|
155 | + protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null) { |
|
156 | 156 | |
157 | 157 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
158 | - if ( ! apply_filters( 'FHEE_load_EE_Session', true ) ) { |
|
158 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
162 | - if ( ! defined( 'ESPRESSO_SESSION' ) ) { |
|
163 | - define( 'ESPRESSO_SESSION', true ); |
|
161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
162 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
163 | + define('ESPRESSO_SESSION', true); |
|
164 | 164 | } |
165 | 165 | // default session lifespan in seconds |
166 | 166 | $this->_lifespan = apply_filters( |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * } |
175 | 175 | */ |
176 | 176 | // retrieve session options from db |
177 | - $session_settings = (array) get_option( 'ee_session_settings', array() ); |
|
178 | - if ( ! empty( $session_settings )) { |
|
177 | + $session_settings = (array) get_option('ee_session_settings', array()); |
|
178 | + if ( ! empty($session_settings)) { |
|
179 | 179 | // cycle though existing session options |
180 | - foreach ( $session_settings as $var_name => $session_setting ) { |
|
180 | + foreach ($session_settings as $var_name => $session_setting) { |
|
181 | 181 | // set values for class properties |
182 | - $var_name = '_' . $var_name; |
|
182 | + $var_name = '_'.$var_name; |
|
183 | 183 | $this->{$var_name} = $session_setting; |
184 | 184 | } |
185 | 185 | } |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | // encrypt data via: $this->encryption->encrypt(); |
191 | 191 | $this->encryption = $encryption; |
192 | 192 | // filter hook allows outside functions/classes/plugins to change default empty cart |
193 | - $extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() ); |
|
194 | - array_merge( $this->_default_session_vars, $extra_default_session_vars ); |
|
193 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
194 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
195 | 195 | // apply default session vars |
196 | 196 | $this->_set_defaults(); |
197 | 197 | add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
198 | 198 | // check request for 'clear_session' param |
199 | - add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' )); |
|
199 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
200 | 200 | // once everything is all said and done, |
201 | - add_action( 'shutdown', array( $this, 'update' ), 100 ); |
|
201 | + add_action('shutdown', array($this, 'update'), 100); |
|
202 | 202 | $this->configure_garbage_collection_filters(); |
203 | 203 | } |
204 | 204 | |
@@ -286,11 +286,11 @@ discard block |
||
286 | 286 | */ |
287 | 287 | private function _set_defaults() { |
288 | 288 | // set some defaults |
289 | - foreach ( $this->_default_session_vars as $key => $default_var ) { |
|
290 | - if ( is_array( $default_var )) { |
|
291 | - $this->_session_data[ $key ] = array(); |
|
289 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
290 | + if (is_array($default_var)) { |
|
291 | + $this->_session_data[$key] = array(); |
|
292 | 292 | } else { |
293 | - $this->_session_data[ $key ] = ''; |
|
293 | + $this->_session_data[$key] = ''; |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param \EE_Checkout $checkout |
346 | 346 | * @return bool |
347 | 347 | */ |
348 | - public function set_checkout( EE_Checkout $checkout ) { |
|
348 | + public function set_checkout(EE_Checkout $checkout) { |
|
349 | 349 | $this->_session_data['checkout'] = $checkout; |
350 | 350 | return TRUE; |
351 | 351 | } |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | * @return bool |
379 | 379 | * @throws \EE_Error |
380 | 380 | */ |
381 | - public function set_transaction( EE_Transaction $transaction ) { |
|
381 | + public function set_transaction(EE_Transaction $transaction) { |
|
382 | 382 | // first remove the session from the transaction before we save the transaction in the session |
383 | - $transaction->set_txn_session_data( NULL ); |
|
383 | + $transaction->set_txn_session_data(NULL); |
|
384 | 384 | $this->_session_data['transaction'] = $transaction; |
385 | 385 | return TRUE; |
386 | 386 | } |
@@ -416,15 +416,15 @@ discard block |
||
416 | 416 | * @param bool $reset_cache |
417 | 417 | * @return array |
418 | 418 | */ |
419 | - public function get_session_data( $key = NULL, $reset_cache = FALSE ) { |
|
420 | - if ( $reset_cache ) { |
|
419 | + public function get_session_data($key = NULL, $reset_cache = FALSE) { |
|
420 | + if ($reset_cache) { |
|
421 | 421 | $this->reset_cart(); |
422 | 422 | $this->reset_checkout(); |
423 | 423 | $this->reset_transaction(); |
424 | 424 | } |
425 | - if ( ! empty( $key )) { |
|
426 | - return isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL; |
|
427 | - } else { |
|
425 | + if ( ! empty($key)) { |
|
426 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL; |
|
427 | + } else { |
|
428 | 428 | return $this->_session_data; |
429 | 429 | } |
430 | 430 | } |
@@ -437,20 +437,20 @@ discard block |
||
437 | 437 | * @param array $data |
438 | 438 | * @return TRUE on success, FALSE on fail |
439 | 439 | */ |
440 | - public function set_session_data( $data ) { |
|
440 | + public function set_session_data($data) { |
|
441 | 441 | |
442 | 442 | // nothing ??? bad data ??? go home! |
443 | - if ( empty( $data ) || ! is_array( $data )) { |
|
444 | - EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
443 | + if (empty($data) || ! is_array($data)) { |
|
444 | + EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
445 | 445 | return FALSE; |
446 | 446 | } |
447 | 447 | |
448 | - foreach ( $data as $key =>$value ) { |
|
449 | - if ( isset( $this->_default_session_vars[ $key ] )) { |
|
450 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ ); |
|
448 | + foreach ($data as $key =>$value) { |
|
449 | + if (isset($this->_default_session_vars[$key])) { |
|
450 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__); |
|
451 | 451 | return FALSE; |
452 | 452 | } else { |
453 | - $this->_session_data[ $key ] = $value; |
|
453 | + $this->_session_data[$key] = $value; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
@@ -468,9 +468,9 @@ discard block |
||
468 | 468 | * @throws \EE_Error |
469 | 469 | */ |
470 | 470 | private function _espresso_session() { |
471 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
471 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
472 | 472 | // check that session has started |
473 | - if ( session_id() === '' ) { |
|
473 | + if (session_id() === '') { |
|
474 | 474 | //starts a new session if one doesn't already exist, or re-initiates an existing one |
475 | 475 | session_start(); |
476 | 476 | } |
@@ -479,39 +479,39 @@ discard block |
||
479 | 479 | // and the visitors IP |
480 | 480 | $this->_ip_address = $this->_visitor_ip(); |
481 | 481 | // set the "user agent" |
482 | - $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE; |
|
482 | + $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE; |
|
483 | 483 | // now let's retrieve what's in the db |
484 | 484 | $session_data = $this->_retrieve_session_data(); |
485 | - if (! empty($session_data)) { |
|
485 | + if ( ! empty($session_data)) { |
|
486 | 486 | // get the current time in UTC |
487 | - $this->_time = isset( $this->_time ) ? $this->_time : time(); |
|
487 | + $this->_time = isset($this->_time) ? $this->_time : time(); |
|
488 | 488 | // and reset the session expiration |
489 | - $this->_expiration = isset( $session_data['expiration'] ) |
|
489 | + $this->_expiration = isset($session_data['expiration']) |
|
490 | 490 | ? $session_data['expiration'] |
491 | 491 | : $this->_time + $this->_lifespan; |
492 | 492 | } else { |
493 | 493 | // set initial site access time and the session expiration |
494 | 494 | $this->_set_init_access_and_expiration(); |
495 | 495 | // set referer |
496 | - $this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] ) |
|
497 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
496 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
497 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
498 | 498 | : ''; |
499 | 499 | // no previous session = go back and create one (on top of the data above) |
500 | 500 | return FALSE; |
501 | 501 | } |
502 | 502 | // now the user agent |
503 | - if ( $session_data['user_agent'] !== $this->_user_agent ) { |
|
503 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
504 | 504 | return FALSE; |
505 | 505 | } |
506 | 506 | // wait a minute... how old are you? |
507 | - if ( $this->_time > $this->_expiration ) { |
|
507 | + if ($this->_time > $this->_expiration) { |
|
508 | 508 | // yer too old fer me! |
509 | 509 | $this->_expired = true; |
510 | 510 | // wipe out everything that isn't a default session datum |
511 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
511 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
512 | 512 | } |
513 | 513 | // make event espresso session data available to plugin |
514 | - $this->_session_data = array_merge( $this->_session_data, $session_data ); |
|
514 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
515 | 515 | return TRUE; |
516 | 516 | |
517 | 517 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | */ |
528 | 528 | protected function _retrieve_session_data() |
529 | 529 | { |
530 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
530 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
531 | 531 | try { |
532 | 532 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
533 | 533 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | } |
537 | 537 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
538 | 538 | $hash_check = $this->cache_storage->get( |
539 | - EE_Session::hash_check_prefix . $this->_sid, |
|
539 | + EE_Session::hash_check_prefix.$this->_sid, |
|
540 | 540 | false |
541 | 541 | ); |
542 | 542 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
547 | 547 | 'event_espresso' |
548 | 548 | ), |
549 | - EE_Session::session_id_prefix . $this->_sid |
|
549 | + EE_Session::session_id_prefix.$this->_sid |
|
550 | 550 | ), |
551 | 551 | __FILE__, __FUNCTION__, __LINE__ |
552 | 552 | ); |
@@ -558,17 +558,17 @@ discard block |
||
558 | 558 | $row = $wpdb->get_row( |
559 | 559 | $wpdb->prepare( |
560 | 560 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
561 | - '_transient_' . $ssn_key |
|
561 | + '_transient_'.$ssn_key |
|
562 | 562 | ) |
563 | 563 | ); |
564 | 564 | $session_data = is_object($row) ? $row->option_value : null; |
565 | 565 | if ($session_data) { |
566 | 566 | $session_data = preg_replace_callback( |
567 | 567 | '!s:(d+):"(.*?)";!', |
568 | - function ($match) { |
|
568 | + function($match) { |
|
569 | 569 | return $match[1] === strlen($match[2]) |
570 | 570 | ? $match[0] |
571 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
571 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
572 | 572 | }, |
573 | 573 | $session_data |
574 | 574 | ); |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | 'event_espresso' |
590 | 590 | ); |
591 | 591 | $msg .= WP_DEBUG |
592 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
592 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
593 | 593 | : ''; |
594 | 594 | throw new InvalidSessionDataException($msg, 0, $e); |
595 | 595 | } |
@@ -602,11 +602,11 @@ discard block |
||
602 | 602 | 'event_espresso' |
603 | 603 | ); |
604 | 604 | $msg .= WP_DEBUG |
605 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
605 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
606 | 606 | : ''; |
607 | 607 | throw new InvalidSessionDataException($msg); |
608 | 608 | } |
609 | - if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) { |
|
609 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
610 | 610 | $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
611 | 611 | $session_data['transaction'] |
612 | 612 | ); |
@@ -627,12 +627,12 @@ discard block |
||
627 | 627 | */ |
628 | 628 | protected function _generate_session_id() { |
629 | 629 | // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
630 | - if ( isset( $_REQUEST[ 'EESID' ] ) ) { |
|
631 | - $session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] ); |
|
630 | + if (isset($_REQUEST['EESID'])) { |
|
631 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
632 | 632 | } else { |
633 | - $session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() ); |
|
633 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
634 | 634 | } |
635 | - return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id ); |
|
635 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
@@ -644,20 +644,20 @@ discard block |
||
644 | 644 | */ |
645 | 645 | protected function _get_sid_salt() { |
646 | 646 | // was session id salt already saved to db ? |
647 | - if ( empty( $this->_sid_salt ) ) { |
|
647 | + if (empty($this->_sid_salt)) { |
|
648 | 648 | // no? then maybe use WP defined constant |
649 | - if ( defined( 'AUTH_SALT' ) ) { |
|
649 | + if (defined('AUTH_SALT')) { |
|
650 | 650 | $this->_sid_salt = AUTH_SALT; |
651 | 651 | } |
652 | 652 | // if salt doesn't exist or is too short |
653 | - if ( strlen( $this->_sid_salt ) < 32 ) { |
|
653 | + if (strlen($this->_sid_salt) < 32) { |
|
654 | 654 | // create a new one |
655 | - $this->_sid_salt = wp_generate_password( 64 ); |
|
655 | + $this->_sid_salt = wp_generate_password(64); |
|
656 | 656 | } |
657 | 657 | // and save it as a permanent session setting |
658 | - $session_settings = get_option( 'ee_session_settings' ); |
|
659 | - $session_settings[ 'sid_salt' ] = $this->_sid_salt; |
|
660 | - update_option( 'ee_session_settings', $session_settings ); |
|
658 | + $session_settings = get_option('ee_session_settings'); |
|
659 | + $session_settings['sid_salt'] = $this->_sid_salt; |
|
660 | + update_option('ee_session_settings', $session_settings); |
|
661 | 661 | } |
662 | 662 | return $this->_sid_salt; |
663 | 663 | } |
@@ -686,19 +686,19 @@ discard block |
||
686 | 686 | * @return TRUE on success, FALSE on fail |
687 | 687 | * @throws \EE_Error |
688 | 688 | */ |
689 | - public function update( $new_session = FALSE ) { |
|
690 | - $this->_session_data = isset( $this->_session_data ) |
|
691 | - && is_array( $this->_session_data ) |
|
692 | - && isset( $this->_session_data['id']) |
|
689 | + public function update($new_session = FALSE) { |
|
690 | + $this->_session_data = isset($this->_session_data) |
|
691 | + && is_array($this->_session_data) |
|
692 | + && isset($this->_session_data['id']) |
|
693 | 693 | ? $this->_session_data |
694 | 694 | : array(); |
695 | - if ( empty( $this->_session_data )) { |
|
695 | + if (empty($this->_session_data)) { |
|
696 | 696 | $this->_set_defaults(); |
697 | 697 | } |
698 | 698 | $session_data = array(); |
699 | - foreach ( $this->_session_data as $key => $value ) { |
|
699 | + foreach ($this->_session_data as $key => $value) { |
|
700 | 700 | |
701 | - switch( $key ) { |
|
701 | + switch ($key) { |
|
702 | 702 | |
703 | 703 | case 'id' : |
704 | 704 | // session ID |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | break; |
717 | 717 | |
718 | 718 | case 'init_access' : |
719 | - $session_data['init_access'] = absint( $value ); |
|
719 | + $session_data['init_access'] = absint($value); |
|
720 | 720 | break; |
721 | 721 | |
722 | 722 | case 'last_access' : |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | |
727 | 727 | case 'expiration' : |
728 | 728 | // when the session expires |
729 | - $session_data['expiration'] = ! empty( $this->_expiration ) |
|
729 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
730 | 730 | ? $this->_expiration |
731 | 731 | : $session_data['init_access'] + $this->_lifespan; |
732 | 732 | break; |
@@ -738,11 +738,11 @@ discard block |
||
738 | 738 | |
739 | 739 | case 'pages_visited' : |
740 | 740 | $page_visit = $this->_get_page_visit(); |
741 | - if ( $page_visit ) { |
|
741 | + if ($page_visit) { |
|
742 | 742 | // set pages visited where the first will be the http referrer |
743 | - $this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit; |
|
743 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
744 | 744 | // we'll only save the last 10 page visits. |
745 | - $session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 ); |
|
745 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
746 | 746 | } |
747 | 747 | break; |
748 | 748 | |
@@ -756,9 +756,9 @@ discard block |
||
756 | 756 | |
757 | 757 | $this->_session_data = $session_data; |
758 | 758 | // creating a new session does not require saving to the db just yet |
759 | - if ( ! $new_session ) { |
|
759 | + if ( ! $new_session) { |
|
760 | 760 | // ready? let's save |
761 | - if ( $this->_save_session_to_db() ) { |
|
761 | + if ($this->_save_session_to_db()) { |
|
762 | 762 | return TRUE; |
763 | 763 | } else { |
764 | 764 | return FALSE; |
@@ -778,9 +778,9 @@ discard block |
||
778 | 778 | * @throws \EE_Error |
779 | 779 | */ |
780 | 780 | private function _create_espresso_session( ) { |
781 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' ); |
|
781 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
782 | 782 | // use the update function for now with $new_session arg set to TRUE |
783 | - return $this->update( TRUE ) ? TRUE : FALSE; |
|
783 | + return $this->update(TRUE) ? TRUE : FALSE; |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | EE_Registry::instance()->REQ->front_ajax |
801 | 801 | || ( |
802 | 802 | // OR an admin request that is NOT AJAX |
803 | - ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
803 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
804 | 804 | && is_admin() |
805 | 805 | ) |
806 | 806 | || ( |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | return false; |
814 | 814 | } |
815 | 815 | $transaction = $this->transaction(); |
816 | - if ( $transaction instanceof EE_Transaction ) { |
|
817 | - if ( ! $transaction->ID() ) { |
|
816 | + if ($transaction instanceof EE_Transaction) { |
|
817 | + if ( ! $transaction->ID()) { |
|
818 | 818 | $transaction->save(); |
819 | 819 | } |
820 | 820 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -823,19 +823,19 @@ discard block |
||
823 | 823 | $session_data = serialize($this->_session_data); |
824 | 824 | // do we need to also encode it to avoid corrupted data when saved to the db? |
825 | 825 | $session_data = $this->_use_encryption |
826 | - ? $this->encryption->base64_string_encode( $session_data ) |
|
826 | + ? $this->encryption->base64_string_encode($session_data) |
|
827 | 827 | : $session_data; |
828 | 828 | // maybe save hash check |
829 | - if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) { |
|
829 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
830 | 830 | $this->cache_storage->add( |
831 | - EE_Session::hash_check_prefix . $this->_sid, |
|
831 | + EE_Session::hash_check_prefix.$this->_sid, |
|
832 | 832 | md5($session_data), |
833 | 833 | $this->_lifespan |
834 | 834 | ); |
835 | 835 | } |
836 | 836 | // we're using the Transient API for storing session data, |
837 | 837 | return $this->cache_storage->add( |
838 | - EE_Session::session_id_prefix . $this->_sid, |
|
838 | + EE_Session::session_id_prefix.$this->_sid, |
|
839 | 839 | $session_data, |
840 | 840 | $this->_lifespan |
841 | 841 | ); |
@@ -864,10 +864,10 @@ discard block |
||
864 | 864 | 'HTTP_FORWARDED', |
865 | 865 | 'REMOTE_ADDR' |
866 | 866 | ); |
867 | - foreach ( $server_keys as $key ){ |
|
868 | - if ( isset( $_SERVER[ $key ] )) { |
|
869 | - foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) { |
|
870 | - if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) { |
|
867 | + foreach ($server_keys as $key) { |
|
868 | + if (isset($_SERVER[$key])) { |
|
869 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
870 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) { |
|
871 | 871 | $visitor_ip = $ip; |
872 | 872 | } |
873 | 873 | } |
@@ -886,32 +886,32 @@ discard block |
||
886 | 886 | * @return string |
887 | 887 | */ |
888 | 888 | public function _get_page_visit() { |
889 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
889 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
890 | 890 | // check for request url |
891 | - if ( isset( $_SERVER['REQUEST_URI'] )) { |
|
891 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
892 | 892 | $http_host = ''; |
893 | 893 | $page_id = '?'; |
894 | 894 | $e_reg = ''; |
895 | - $request_uri = esc_url( $_SERVER['REQUEST_URI'] ); |
|
896 | - $ru_bits = explode( '?', $request_uri ); |
|
895 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
896 | + $ru_bits = explode('?', $request_uri); |
|
897 | 897 | $request_uri = $ru_bits[0]; |
898 | 898 | // check for and grab host as well |
899 | - if ( isset( $_SERVER['HTTP_HOST'] )) { |
|
900 | - $http_host = esc_url( $_SERVER['HTTP_HOST'] ); |
|
899 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
900 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
901 | 901 | } |
902 | 902 | // check for page_id in SERVER REQUEST |
903 | - if ( isset( $_REQUEST['page_id'] )) { |
|
903 | + if (isset($_REQUEST['page_id'])) { |
|
904 | 904 | // rebuild $e_reg without any of the extra parameters |
905 | - $page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&'; |
|
905 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
906 | 906 | } |
907 | 907 | // check for $e_reg in SERVER REQUEST |
908 | - if ( isset( $_REQUEST['ee'] )) { |
|
908 | + if (isset($_REQUEST['ee'])) { |
|
909 | 909 | // rebuild $e_reg without any of the extra parameters |
910 | - $e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] ); |
|
910 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
911 | 911 | } |
912 | - $page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' ); |
|
912 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
913 | 913 | } |
914 | - return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : ''; |
|
914 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
915 | 915 | |
916 | 916 | } |
917 | 917 | |
@@ -941,14 +941,14 @@ discard block |
||
941 | 941 | * @return void |
942 | 942 | * @throws \EE_Error |
943 | 943 | */ |
944 | - public function clear_session( $class = '', $function = '' ) { |
|
944 | + public function clear_session($class = '', $function = '') { |
|
945 | 945 | //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b></h3>'; |
946 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()' ); |
|
946 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
947 | 947 | $this->reset_cart(); |
948 | 948 | $this->reset_checkout(); |
949 | 949 | $this->reset_transaction(); |
950 | 950 | // wipe out everything that isn't a default session datum |
951 | - $this->reset_data( array_keys( $this->_session_data )); |
|
951 | + $this->reset_data(array_keys($this->_session_data)); |
|
952 | 952 | // reset initial site access time and the session expiration |
953 | 953 | $this->_set_init_access_and_expiration(); |
954 | 954 | $this->_save_session_to_db(); |
@@ -963,42 +963,42 @@ discard block |
||
963 | 963 | * @param bool $show_all_notices |
964 | 964 | * @return TRUE on success, FALSE on fail |
965 | 965 | */ |
966 | - public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) { |
|
966 | + public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) { |
|
967 | 967 | // if $data_to_reset is not in an array, then put it in one |
968 | - if ( ! is_array( $data_to_reset ) ) { |
|
969 | - $data_to_reset = array ( $data_to_reset ); |
|
968 | + if ( ! is_array($data_to_reset)) { |
|
969 | + $data_to_reset = array($data_to_reset); |
|
970 | 970 | } |
971 | 971 | // nothing ??? go home! |
972 | - if ( empty( $data_to_reset )) { |
|
973 | - EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
972 | + if (empty($data_to_reset)) { |
|
973 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
974 | 974 | return FALSE; |
975 | 975 | } |
976 | 976 | $return_value = TRUE; |
977 | 977 | // since $data_to_reset is an array, cycle through the values |
978 | - foreach ( $data_to_reset as $reset ) { |
|
978 | + foreach ($data_to_reset as $reset) { |
|
979 | 979 | |
980 | 980 | // first check to make sure it is a valid session var |
981 | - if ( isset( $this->_session_data[ $reset ] )) { |
|
981 | + if (isset($this->_session_data[$reset])) { |
|
982 | 982 | // then check to make sure it is not a default var |
983 | - if ( ! array_key_exists( $reset, $this->_default_session_vars )) { |
|
983 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
984 | 984 | // remove session var |
985 | - unset( $this->_session_data[ $reset ] ); |
|
986 | - if ( $show_all_notices ) { |
|
987 | - EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
985 | + unset($this->_session_data[$reset]); |
|
986 | + if ($show_all_notices) { |
|
987 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
988 | 988 | } |
989 | - $return_value = !isset($return_value) ? TRUE : $return_value; |
|
989 | + $return_value = ! isset($return_value) ? TRUE : $return_value; |
|
990 | 990 | |
991 | 991 | } else { |
992 | 992 | // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
993 | - if ( $show_all_notices ) { |
|
994 | - EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
993 | + if ($show_all_notices) { |
|
994 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
995 | 995 | } |
996 | 996 | $return_value = FALSE; |
997 | 997 | } |
998 | 998 | |
999 | - } else if ( $show_all_notices ) { |
|
999 | + } else if ($show_all_notices) { |
|
1000 | 1000 | // oops! that session var does not exist! |
1001 | - EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1001 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1002 | 1002 | $return_value = FALSE; |
1003 | 1003 | } |
1004 | 1004 | |
@@ -1017,8 +1017,8 @@ discard block |
||
1017 | 1017 | * @throws \EE_Error |
1018 | 1018 | */ |
1019 | 1019 | public function wp_loaded() { |
1020 | - if ( isset( EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) { |
|
1021 | - $this->clear_session( __CLASS__, __FUNCTION__ ); |
|
1020 | + if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) { |
|
1021 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
1022 | 1022 | } |
1023 | 1023 | } |
1024 | 1024 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | // or use that for the new transient cleanup query limit |
1055 | 1055 | add_filter( |
1056 | 1056 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
1057 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1057 | + function() use ($expired_session_transient_delete_query_limit) { |
|
1058 | 1058 | return $expired_session_transient_delete_query_limit; |
1059 | 1059 | } |
1060 | 1060 | ); |
@@ -1068,34 +1068,34 @@ discard block |
||
1068 | 1068 | * @param $data1 |
1069 | 1069 | * @return string |
1070 | 1070 | */ |
1071 | - private function find_serialize_error( $data1 ) { |
|
1071 | + private function find_serialize_error($data1) { |
|
1072 | 1072 | $error = '<pre>'; |
1073 | 1073 | $data2 = preg_replace_callback( |
1074 | 1074 | '!s:(\d+):"(.*?)";!', |
1075 | - function ( $match ) { |
|
1076 | - return ( $match[1] === strlen( $match[2] ) ) |
|
1075 | + function($match) { |
|
1076 | + return ($match[1] === strlen($match[2])) |
|
1077 | 1077 | ? $match[0] |
1078 | 1078 | : 's:' |
1079 | - . strlen( $match[2] ) |
|
1079 | + . strlen($match[2]) |
|
1080 | 1080 | . ':"' |
1081 | 1081 | . $match[2] |
1082 | 1082 | . '";'; |
1083 | 1083 | }, |
1084 | 1084 | $data1 |
1085 | 1085 | ); |
1086 | - $max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 ); |
|
1087 | - $error .= $data1 . PHP_EOL; |
|
1088 | - $error .= $data2 . PHP_EOL; |
|
1089 | - for ( $i = 0; $i < $max; $i++ ) { |
|
1090 | - if ( @$data1[ $i ] !== @$data2[ $i ] ) { |
|
1091 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1092 | - $error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . ' != ' . ord( @$data2[ $i ] ) . PHP_EOL; |
|
1093 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1094 | - $start = ( $i - 20 ); |
|
1095 | - $start = ( $start < 0 ) ? 0 : $start; |
|
1086 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1087 | + $error .= $data1.PHP_EOL; |
|
1088 | + $error .= $data2.PHP_EOL; |
|
1089 | + for ($i = 0; $i < $max; $i++) { |
|
1090 | + if (@$data1[$i] !== @$data2[$i]) { |
|
1091 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
1092 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
1093 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
1094 | + $start = ($i - 20); |
|
1095 | + $start = ($start < 0) ? 0 : $start; |
|
1096 | 1096 | $length = 40; |
1097 | 1097 | $point = $max - $i; |
1098 | - if ( $point < 20 ) { |
|
1098 | + if ($point < 20) { |
|
1099 | 1099 | $rlength = 1; |
1100 | 1100 | $rpoint = -$point; |
1101 | 1101 | } else { |
@@ -1104,16 +1104,16 @@ discard block |
||
1104 | 1104 | } |
1105 | 1105 | $error .= "\t-> Section Data1 = "; |
1106 | 1106 | $error .= substr_replace( |
1107 | - substr( $data1, $start, $length ), |
|
1108 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1107 | + substr($data1, $start, $length), |
|
1108 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
1109 | 1109 | $rpoint, |
1110 | 1110 | $rlength |
1111 | 1111 | ); |
1112 | 1112 | $error .= PHP_EOL; |
1113 | 1113 | $error .= "\t-> Section Data2 = "; |
1114 | 1114 | $error .= substr_replace( |
1115 | - substr( $data2, $start, $length ), |
|
1116 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1115 | + substr($data2, $start, $length), |
|
1116 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
1117 | 1117 | $rpoint, |
1118 | 1118 | $rlength |
1119 | 1119 | ); |
@@ -24,82 +24,82 @@ |
||
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * the actual shortcode tag that gets registered with WordPress |
|
29 | - * |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function getTag() |
|
33 | - { |
|
34 | - return 'ESPRESSO_TICKET_SELECTOR'; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * the time in seconds to cache the results of the processShortcode() method |
|
41 | - * 0 means the processShortcode() results will NOT be cached at all |
|
42 | - * |
|
43 | - * @return int |
|
44 | - */ |
|
45 | - public function cacheExpiration() |
|
46 | - { |
|
47 | - return MINUTE_IN_SECONDS; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
53 | - * this may be required for shortcodes that utilize a corresponding module, |
|
54 | - * and need to enqueue assets for that module |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function initializeShortcode() |
|
59 | - { |
|
60 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
61 | - $this->shortcodeHasBeenInitialized(); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * callback that runs when the shortcode is encountered in post content. |
|
68 | - * IMPORTANT !!! |
|
69 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
70 | - * |
|
71 | - * @param array $attributes |
|
72 | - * @return string |
|
73 | - * @throws InvalidArgumentException |
|
74 | - */ |
|
75 | - public function processShortcode($attributes = array()) |
|
76 | - { |
|
77 | - extract($attributes, EXTR_OVERWRITE); |
|
78 | - $event_id = isset($event_id) ? $event_id : 0; |
|
79 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
80 | - if (! $event instanceof EE_Event) { |
|
81 | - new ExceptionStackTraceDisplay( |
|
82 | - new InvalidArgumentException( |
|
83 | - sprintf( |
|
84 | - esc_html__( |
|
85 | - 'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - $this->getTag(), |
|
89 | - $event_id, |
|
90 | - 'event_id', |
|
91 | - '<br />' |
|
92 | - ) |
|
93 | - ) |
|
94 | - ); |
|
95 | - return ''; |
|
96 | - } |
|
97 | - ob_start(); |
|
98 | - do_action('AHEE_event_details_before_post', $event_id); |
|
99 | - espresso_ticket_selector($event); |
|
100 | - do_action('AHEE_event_details_after_post'); |
|
101 | - return ob_get_clean(); |
|
102 | - } |
|
27 | + /** |
|
28 | + * the actual shortcode tag that gets registered with WordPress |
|
29 | + * |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function getTag() |
|
33 | + { |
|
34 | + return 'ESPRESSO_TICKET_SELECTOR'; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * the time in seconds to cache the results of the processShortcode() method |
|
41 | + * 0 means the processShortcode() results will NOT be cached at all |
|
42 | + * |
|
43 | + * @return int |
|
44 | + */ |
|
45 | + public function cacheExpiration() |
|
46 | + { |
|
47 | + return MINUTE_IN_SECONDS; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
53 | + * this may be required for shortcodes that utilize a corresponding module, |
|
54 | + * and need to enqueue assets for that module |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function initializeShortcode() |
|
59 | + { |
|
60 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
61 | + $this->shortcodeHasBeenInitialized(); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * callback that runs when the shortcode is encountered in post content. |
|
68 | + * IMPORTANT !!! |
|
69 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
70 | + * |
|
71 | + * @param array $attributes |
|
72 | + * @return string |
|
73 | + * @throws InvalidArgumentException |
|
74 | + */ |
|
75 | + public function processShortcode($attributes = array()) |
|
76 | + { |
|
77 | + extract($attributes, EXTR_OVERWRITE); |
|
78 | + $event_id = isset($event_id) ? $event_id : 0; |
|
79 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
80 | + if (! $event instanceof EE_Event) { |
|
81 | + new ExceptionStackTraceDisplay( |
|
82 | + new InvalidArgumentException( |
|
83 | + sprintf( |
|
84 | + esc_html__( |
|
85 | + 'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + $this->getTag(), |
|
89 | + $event_id, |
|
90 | + 'event_id', |
|
91 | + '<br />' |
|
92 | + ) |
|
93 | + ) |
|
94 | + ); |
|
95 | + return ''; |
|
96 | + } |
|
97 | + ob_start(); |
|
98 | + do_action('AHEE_event_details_before_post', $event_id); |
|
99 | + espresso_ticket_selector($event); |
|
100 | + do_action('AHEE_event_details_after_post'); |
|
101 | + return ob_get_clean(); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | extract($attributes, EXTR_OVERWRITE); |
78 | 78 | $event_id = isset($event_id) ? $event_id : 0; |
79 | 79 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
80 | - if (! $event instanceof EE_Event) { |
|
80 | + if ( ! $event instanceof EE_Event) { |
|
81 | 81 | new ExceptionStackTraceDisplay( |
82 | 82 | new InvalidArgumentException( |
83 | 83 | sprintf( |
@@ -5,9 +5,9 @@ |
||
5 | 5 | interface SessionIdentifierInterface |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @return string |
|
10 | - */ |
|
11 | - public function id(); |
|
8 | + /** |
|
9 | + * @return string |
|
10 | + */ |
|
11 | + public function id(); |
|
12 | 12 | |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | ); |
200 | 200 | return CollectionLoader::ENTITY_ADDED; |
201 | 201 | } |
202 | - do_action( |
|
203 | - 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
204 | - $this, |
|
205 | - $this->collection_details->collectionName(), |
|
206 | - $this->collection_details |
|
207 | - ); |
|
208 | - return CollectionLoader::ENTITY_NOT_ADDED; |
|
202 | + do_action( |
|
203 | + 'FHEE__CollectionLoader__addEntityToCollection__entity_not_added', |
|
204 | + $this, |
|
205 | + $this->collection_details->collectionName(), |
|
206 | + $this->collection_details |
|
207 | + ); |
|
208 | + return CollectionLoader::ENTITY_NOT_ADDED; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -220,37 +220,37 @@ discard block |
||
220 | 220 | * @throws \EventEspresso\core\exceptions\InvalidEntityException |
221 | 221 | */ |
222 | 222 | protected function setIdentifier( $entity, $identifier ) { |
223 | - switch($this->collection_details->identifierType()) { |
|
224 | - // every unique object gets added to the collection, but not duplicates of the exact same object |
|
225 | - case CollectionDetails::ID_OBJECT_HASH : |
|
226 | - $identifier = spl_object_hash($entity); |
|
227 | - break; |
|
228 | - // only one entity per class can be added to collection, like a singleton |
|
229 | - case CollectionDetails::ID_CLASS_NAME : |
|
230 | - $identifier = get_class($entity); |
|
231 | - break; |
|
232 | - // objects added to the collection based on entity callback, so the entity itself decides |
|
233 | - case CollectionDetails::ID_CALLBACK_METHOD : |
|
234 | - $identifier_callback = $this->collection_details->identifierCallback(); |
|
235 | - if ( ! method_exists($entity, $identifier_callback)) { |
|
236 | - throw new InvalidEntityException( |
|
237 | - $entity, |
|
238 | - $this->collection_details->getCollectionInterface(), |
|
239 | - sprintf( |
|
240 | - __( |
|
241 | - 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
223 | + switch($this->collection_details->identifierType()) { |
|
224 | + // every unique object gets added to the collection, but not duplicates of the exact same object |
|
225 | + case CollectionDetails::ID_OBJECT_HASH : |
|
226 | + $identifier = spl_object_hash($entity); |
|
227 | + break; |
|
228 | + // only one entity per class can be added to collection, like a singleton |
|
229 | + case CollectionDetails::ID_CLASS_NAME : |
|
230 | + $identifier = get_class($entity); |
|
231 | + break; |
|
232 | + // objects added to the collection based on entity callback, so the entity itself decides |
|
233 | + case CollectionDetails::ID_CALLBACK_METHOD : |
|
234 | + $identifier_callback = $this->collection_details->identifierCallback(); |
|
235 | + if ( ! method_exists($entity, $identifier_callback)) { |
|
236 | + throw new InvalidEntityException( |
|
237 | + $entity, |
|
238 | + $this->collection_details->getCollectionInterface(), |
|
239 | + sprintf( |
|
240 | + __( |
|
241 | + 'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance |
|
242 | 242 | of "%2$s", but does not contain this method.', |
243 | - 'event_espresso' |
|
244 | - ), |
|
245 | - $identifier_callback, |
|
246 | - get_class($entity) |
|
247 | - ) |
|
248 | - ); |
|
249 | - } |
|
250 | - $identifier = $entity->{$identifier_callback}(); |
|
251 | - break; |
|
252 | - |
|
253 | - } |
|
243 | + 'event_espresso' |
|
244 | + ), |
|
245 | + $identifier_callback, |
|
246 | + get_class($entity) |
|
247 | + ) |
|
248 | + ); |
|
249 | + } |
|
250 | + $identifier = $entity->{$identifier_callback}(); |
|
251 | + break; |
|
252 | + |
|
253 | + } |
|
254 | 254 | return apply_filters( |
255 | 255 | 'FHEE__CollectionLoader__addEntityToCollection__identifier', |
256 | 256 | $identifier, |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | // with these parameters |
141 | 141 | $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
142 | 142 | // then md5 the above to control it's length, add all of our prefixes, and truncate |
143 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
143 | + return substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | return ' |
171 | 171 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
172 | 172 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
173 | - <b>' . $type . '</b><span style="color:#999"> : </span> |
|
174 | - <span>' . $cache_id . '</span> |
|
175 | - <span style="margin-left:2em;">' . __FILE__ . '</span> |
|
173 | + <b>' . $type.'</b><span style="color:#999"> : </span> |
|
174 | + <span>' . $cache_id.'</span> |
|
175 | + <span style="margin-left:2em;">' . __FILE__.'</span> |
|
176 | 176 | </p> |
177 | 177 | </div>'; |
178 | 178 | } |
@@ -19,140 +19,140 @@ discard block |
||
19 | 19 | class BasicCacheManager implements CacheManagerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @type string |
|
24 | - */ |
|
25 | - const CACHE_PREFIX = 'ee_cache_'; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @var CacheStorageInterface $cache_storage |
|
30 | - */ |
|
31 | - private $cache_storage; |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * BasicCacheManager constructor. |
|
37 | - * |
|
38 | - * @param CacheStorageInterface $cache_storage [required] |
|
39 | - */ |
|
40 | - public function __construct(CacheStorageInterface $cache_storage) |
|
41 | - { |
|
42 | - $this->cache_storage = $cache_storage; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * returns a string that will be prepended to all cache identifiers |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function cachePrefix() |
|
53 | - { |
|
54 | - return BasicCacheManager::CACHE_PREFIX; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
61 | - * May also be helpful to include an additional specific identifier, |
|
62 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
63 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
64 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
65 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
66 | - * It is advisable to use some of the actual data |
|
67 | - * that is used to generate the content being cached, |
|
68 | - * in order to guarantee that the cache id is unique for that content. |
|
69 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
70 | - * and the entire cache id string will be truncated to 190 characters. |
|
71 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
72 | - * necessary, |
|
73 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
74 | - * @param int $expiration |
|
75 | - * @return Closure|mixed |
|
76 | - */ |
|
77 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
78 | - { |
|
79 | - $content = ''; |
|
80 | - $expiration = absint( |
|
81 | - apply_filters( |
|
82 | - 'FHEE__CacheManager__get__cache_expiration', |
|
83 | - $expiration, |
|
84 | - $id_prefix, |
|
85 | - $cache_id |
|
86 | - ) |
|
87 | - ); |
|
88 | - $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
89 | - // is caching enabled for this content ? |
|
90 | - if ($expiration) { |
|
91 | - $content = $this->cache_storage->get($cache_id); |
|
92 | - } |
|
93 | - // any existing content ? |
|
94 | - if (empty($content)) { |
|
95 | - // nope! let's generate some new stuff |
|
96 | - $content = $callback(); |
|
97 | - // save the new content if caching is enabled |
|
98 | - if ($expiration) { |
|
99 | - $this->cache_storage->add($cache_id, $content, $expiration); |
|
100 | - if (EE_DEBUG) { |
|
101 | - $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
102 | - } |
|
103 | - } |
|
104 | - } else { |
|
105 | - if (EE_DEBUG) { |
|
106 | - $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
107 | - } |
|
108 | - } |
|
109 | - return $content; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Generates a unique identifier string for the cache |
|
116 | - * |
|
117 | - * @param string $id_prefix [required] see BasicCacheManager::get() |
|
118 | - * @param string $cache_id [required] see BasicCacheManager::get() |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - private function generateCacheIdentifier($id_prefix, $cache_id) |
|
122 | - { |
|
123 | - // let's make the cached content unique for this "page" |
|
124 | - $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
125 | - // with these parameters |
|
126 | - $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
127 | - // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
128 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
135 | - * or a specific ID targeting a single cache item |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - public function clear($cache_id) |
|
139 | - { |
|
140 | - // ensure incoming arg is in an array |
|
141 | - $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
142 | - // delete corresponding transients for the supplied id prefix |
|
143 | - $this->cache_storage->deleteMany($cache_id); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | - * or a specific ID targeting a single cache item |
|
151 | - * @param string $type |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - private function displayCacheNotice($cache_id, $type) { |
|
155 | - return ' |
|
22 | + /** |
|
23 | + * @type string |
|
24 | + */ |
|
25 | + const CACHE_PREFIX = 'ee_cache_'; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @var CacheStorageInterface $cache_storage |
|
30 | + */ |
|
31 | + private $cache_storage; |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * BasicCacheManager constructor. |
|
37 | + * |
|
38 | + * @param CacheStorageInterface $cache_storage [required] |
|
39 | + */ |
|
40 | + public function __construct(CacheStorageInterface $cache_storage) |
|
41 | + { |
|
42 | + $this->cache_storage = $cache_storage; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * returns a string that will be prepended to all cache identifiers |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function cachePrefix() |
|
53 | + { |
|
54 | + return BasicCacheManager::CACHE_PREFIX; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
61 | + * May also be helpful to include an additional specific identifier, |
|
62 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
63 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
64 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
65 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
66 | + * It is advisable to use some of the actual data |
|
67 | + * that is used to generate the content being cached, |
|
68 | + * in order to guarantee that the cache id is unique for that content. |
|
69 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
70 | + * and the entire cache id string will be truncated to 190 characters. |
|
71 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
72 | + * necessary, |
|
73 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
74 | + * @param int $expiration |
|
75 | + * @return Closure|mixed |
|
76 | + */ |
|
77 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
78 | + { |
|
79 | + $content = ''; |
|
80 | + $expiration = absint( |
|
81 | + apply_filters( |
|
82 | + 'FHEE__CacheManager__get__cache_expiration', |
|
83 | + $expiration, |
|
84 | + $id_prefix, |
|
85 | + $cache_id |
|
86 | + ) |
|
87 | + ); |
|
88 | + $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
89 | + // is caching enabled for this content ? |
|
90 | + if ($expiration) { |
|
91 | + $content = $this->cache_storage->get($cache_id); |
|
92 | + } |
|
93 | + // any existing content ? |
|
94 | + if (empty($content)) { |
|
95 | + // nope! let's generate some new stuff |
|
96 | + $content = $callback(); |
|
97 | + // save the new content if caching is enabled |
|
98 | + if ($expiration) { |
|
99 | + $this->cache_storage->add($cache_id, $content, $expiration); |
|
100 | + if (EE_DEBUG) { |
|
101 | + $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
102 | + } |
|
103 | + } |
|
104 | + } else { |
|
105 | + if (EE_DEBUG) { |
|
106 | + $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
107 | + } |
|
108 | + } |
|
109 | + return $content; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Generates a unique identifier string for the cache |
|
116 | + * |
|
117 | + * @param string $id_prefix [required] see BasicCacheManager::get() |
|
118 | + * @param string $cache_id [required] see BasicCacheManager::get() |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + private function generateCacheIdentifier($id_prefix, $cache_id) |
|
122 | + { |
|
123 | + // let's make the cached content unique for this "page" |
|
124 | + $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
125 | + // with these parameters |
|
126 | + $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
127 | + // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
128 | + return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
135 | + * or a specific ID targeting a single cache item |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + public function clear($cache_id) |
|
139 | + { |
|
140 | + // ensure incoming arg is in an array |
|
141 | + $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
142 | + // delete corresponding transients for the supplied id prefix |
|
143 | + $this->cache_storage->deleteMany($cache_id); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
150 | + * or a specific ID targeting a single cache item |
|
151 | + * @param string $type |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + private function displayCacheNotice($cache_id, $type) { |
|
155 | + return ' |
|
156 | 156 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
157 | 157 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
158 | 158 | <b>' . $type . '</b><span style="color:#999"> : </span> |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | <span style="margin-left:2em;">' . __FILE__ . '</span> |
161 | 161 | </p> |
162 | 162 | </div>'; |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | // End of file BasicCacheManager.php |