@@ -32,211 +32,211 @@ |
||
32 | 32 | class ShortcodesManager |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
37 | - */ |
|
38 | - private $legacy_shortcodes_manager; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var ShortcodeInterface[] $shortcodes |
|
42 | - */ |
|
43 | - private $shortcodes; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * ShortcodesManager constructor |
|
49 | - * |
|
50 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
51 | - */ |
|
52 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
53 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
54 | - // assemble a list of installed and active shortcodes |
|
55 | - add_action( |
|
56 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
57 | - array($this, 'registerShortcodes'), |
|
58 | - 999 |
|
59 | - ); |
|
60 | - // call add_shortcode() for all installed shortcodes |
|
61 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
62 | - // check content for shortcodes the old way |
|
63 | - add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
64 | - // check content for shortcodes the NEW more efficient way |
|
65 | - add_action('wp_head', array($this, 'wpHead'), 0); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return CollectionInterface|ShortcodeInterface[] |
|
72 | - * @throws InvalidIdentifierException |
|
73 | - * @throws InvalidInterfaceException |
|
74 | - * @throws InvalidFilePathException |
|
75 | - * @throws InvalidEntityException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidClassException |
|
78 | - */ |
|
79 | - public function getShortcodes() |
|
80 | - { |
|
81 | - if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
82 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
83 | - } |
|
84 | - return $this->shortcodes; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return CollectionInterface|ShortcodeInterface[] |
|
91 | - * @throws InvalidIdentifierException |
|
92 | - * @throws InvalidInterfaceException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - * @throws InvalidEntityException |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws InvalidClassException |
|
97 | - */ |
|
98 | - protected function loadShortcodesCollection() |
|
99 | - { |
|
100 | - $loader = new CollectionLoader( |
|
101 | - new CollectionDetails( |
|
102 | - // collection name |
|
103 | - 'shortcodes', |
|
104 | - // collection interface |
|
105 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
106 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
107 | - array('EventEspresso\core\domain\entities\shortcodes'), |
|
108 | - // filepaths to classes to add |
|
109 | - array(), |
|
110 | - // file mask to use if parsing folder for files to add |
|
111 | - '', |
|
112 | - // what to use as identifier for collection entities |
|
113 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
114 | - CollectionDetails::ID_CLASS_NAME |
|
115 | - ) |
|
116 | - ); |
|
117 | - return $loader->getCollection(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - * @throws DomainException |
|
125 | - * @throws InvalidInterfaceException |
|
126 | - * @throws InvalidIdentifierException |
|
127 | - * @throws InvalidFilePathException |
|
128 | - * @throws InvalidEntityException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws InvalidClassException |
|
131 | - */ |
|
132 | - public function registerShortcodes() |
|
133 | - { |
|
134 | - try { |
|
135 | - $this->shortcodes = apply_filters( |
|
136 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
137 | - $this->getShortcodes() |
|
138 | - ); |
|
139 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
140 | - throw new InvalidEntityException( |
|
141 | - $this->shortcodes, |
|
142 | - 'CollectionInterface', |
|
143 | - sprintf( |
|
144 | - esc_html__( |
|
145 | - 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
149 | - ) |
|
150 | - ); |
|
151 | - } |
|
152 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
153 | - } catch (Exception $exception) { |
|
154 | - new ExceptionStackTraceDisplay($exception); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return void |
|
162 | - */ |
|
163 | - public function addShortcodes() |
|
164 | - { |
|
165 | - try { |
|
166 | - // cycle thru shortcode folders |
|
167 | - foreach ($this->shortcodes as $shortcode) { |
|
168 | - /** @var ShortcodeInterface $shortcode */ |
|
169 | - if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
170 | - add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
171 | - add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
172 | - } |
|
173 | - // add_shortcode() if it has not already been added |
|
174 | - if ( ! shortcode_exists($shortcode->getTag())) { |
|
175 | - add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
176 | - } |
|
177 | - } |
|
178 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
179 | - } catch (Exception $exception) { |
|
180 | - new ExceptionStackTraceDisplay($exception); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * callback for the "wp_head" hook point |
|
188 | - * checks posts for EE shortcodes, and initializes them, |
|
189 | - * then toggles filter switch that loads core default assets |
|
190 | - * |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function wpHead() |
|
194 | - { |
|
195 | - global $wp_query; |
|
196 | - if (empty($wp_query->posts)) { |
|
197 | - return; |
|
198 | - } |
|
199 | - $load_assets = false; |
|
200 | - // array of posts displayed in current request |
|
201 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
202 | - foreach ($posts as $post) { |
|
203 | - // now check post content and excerpt for EE shortcodes |
|
204 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | - ? true |
|
206 | - : $load_assets; |
|
207 | - } |
|
208 | - if ($load_assets) { |
|
209 | - $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
210 | - add_filter('FHEE_load_css', '__return_true'); |
|
211 | - add_filter('FHEE_load_js', '__return_true'); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * checks supplied content against list of shortcodes, |
|
219 | - * then initializes any found shortcodes, and returns true. |
|
220 | - * returns false if no shortcodes found. |
|
221 | - * |
|
222 | - * @param string $content |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function parseContentForShortcodes($content) |
|
226 | - { |
|
227 | - $has_shortcode = false; |
|
228 | - if(empty($this->shortcodes)){ |
|
229 | - return $has_shortcode; |
|
230 | - } |
|
231 | - foreach ($this->shortcodes as $shortcode) { |
|
232 | - /** @var ShortcodeInterface $shortcode */ |
|
233 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
234 | - $shortcode->initializeShortcode(); |
|
235 | - $has_shortcode = true; |
|
236 | - } |
|
237 | - } |
|
238 | - return $has_shortcode; |
|
239 | - } |
|
35 | + /** |
|
36 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
37 | + */ |
|
38 | + private $legacy_shortcodes_manager; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var ShortcodeInterface[] $shortcodes |
|
42 | + */ |
|
43 | + private $shortcodes; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * ShortcodesManager constructor |
|
49 | + * |
|
50 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
51 | + */ |
|
52 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
53 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
54 | + // assemble a list of installed and active shortcodes |
|
55 | + add_action( |
|
56 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
57 | + array($this, 'registerShortcodes'), |
|
58 | + 999 |
|
59 | + ); |
|
60 | + // call add_shortcode() for all installed shortcodes |
|
61 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
62 | + // check content for shortcodes the old way |
|
63 | + add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
64 | + // check content for shortcodes the NEW more efficient way |
|
65 | + add_action('wp_head', array($this, 'wpHead'), 0); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return CollectionInterface|ShortcodeInterface[] |
|
72 | + * @throws InvalidIdentifierException |
|
73 | + * @throws InvalidInterfaceException |
|
74 | + * @throws InvalidFilePathException |
|
75 | + * @throws InvalidEntityException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidClassException |
|
78 | + */ |
|
79 | + public function getShortcodes() |
|
80 | + { |
|
81 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
82 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
83 | + } |
|
84 | + return $this->shortcodes; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return CollectionInterface|ShortcodeInterface[] |
|
91 | + * @throws InvalidIdentifierException |
|
92 | + * @throws InvalidInterfaceException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + * @throws InvalidEntityException |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws InvalidClassException |
|
97 | + */ |
|
98 | + protected function loadShortcodesCollection() |
|
99 | + { |
|
100 | + $loader = new CollectionLoader( |
|
101 | + new CollectionDetails( |
|
102 | + // collection name |
|
103 | + 'shortcodes', |
|
104 | + // collection interface |
|
105 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
106 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
107 | + array('EventEspresso\core\domain\entities\shortcodes'), |
|
108 | + // filepaths to classes to add |
|
109 | + array(), |
|
110 | + // file mask to use if parsing folder for files to add |
|
111 | + '', |
|
112 | + // what to use as identifier for collection entities |
|
113 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
114 | + CollectionDetails::ID_CLASS_NAME |
|
115 | + ) |
|
116 | + ); |
|
117 | + return $loader->getCollection(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + * @throws DomainException |
|
125 | + * @throws InvalidInterfaceException |
|
126 | + * @throws InvalidIdentifierException |
|
127 | + * @throws InvalidFilePathException |
|
128 | + * @throws InvalidEntityException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws InvalidClassException |
|
131 | + */ |
|
132 | + public function registerShortcodes() |
|
133 | + { |
|
134 | + try { |
|
135 | + $this->shortcodes = apply_filters( |
|
136 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
137 | + $this->getShortcodes() |
|
138 | + ); |
|
139 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
140 | + throw new InvalidEntityException( |
|
141 | + $this->shortcodes, |
|
142 | + 'CollectionInterface', |
|
143 | + sprintf( |
|
144 | + esc_html__( |
|
145 | + 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
149 | + ) |
|
150 | + ); |
|
151 | + } |
|
152 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
153 | + } catch (Exception $exception) { |
|
154 | + new ExceptionStackTraceDisplay($exception); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return void |
|
162 | + */ |
|
163 | + public function addShortcodes() |
|
164 | + { |
|
165 | + try { |
|
166 | + // cycle thru shortcode folders |
|
167 | + foreach ($this->shortcodes as $shortcode) { |
|
168 | + /** @var ShortcodeInterface $shortcode */ |
|
169 | + if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
170 | + add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
171 | + add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
172 | + } |
|
173 | + // add_shortcode() if it has not already been added |
|
174 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
175 | + add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
176 | + } |
|
177 | + } |
|
178 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
179 | + } catch (Exception $exception) { |
|
180 | + new ExceptionStackTraceDisplay($exception); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * callback for the "wp_head" hook point |
|
188 | + * checks posts for EE shortcodes, and initializes them, |
|
189 | + * then toggles filter switch that loads core default assets |
|
190 | + * |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function wpHead() |
|
194 | + { |
|
195 | + global $wp_query; |
|
196 | + if (empty($wp_query->posts)) { |
|
197 | + return; |
|
198 | + } |
|
199 | + $load_assets = false; |
|
200 | + // array of posts displayed in current request |
|
201 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
202 | + foreach ($posts as $post) { |
|
203 | + // now check post content and excerpt for EE shortcodes |
|
204 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | + ? true |
|
206 | + : $load_assets; |
|
207 | + } |
|
208 | + if ($load_assets) { |
|
209 | + $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
210 | + add_filter('FHEE_load_css', '__return_true'); |
|
211 | + add_filter('FHEE_load_js', '__return_true'); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * checks supplied content against list of shortcodes, |
|
219 | + * then initializes any found shortcodes, and returns true. |
|
220 | + * returns false if no shortcodes found. |
|
221 | + * |
|
222 | + * @param string $content |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function parseContentForShortcodes($content) |
|
226 | + { |
|
227 | + $has_shortcode = false; |
|
228 | + if(empty($this->shortcodes)){ |
|
229 | + return $has_shortcode; |
|
230 | + } |
|
231 | + foreach ($this->shortcodes as $shortcode) { |
|
232 | + /** @var ShortcodeInterface $shortcode */ |
|
233 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
234 | + $shortcode->initializeShortcode(); |
|
235 | + $has_shortcode = true; |
|
236 | + } |
|
237 | + } |
|
238 | + return $has_shortcode; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | // End of file ShortcodesManager.php |
@@ -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 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.40.rc.017'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.40.rc.017'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |