@@ -15,94 +15,94 @@ |
||
15 | 15 | */ |
16 | 16 | class LicenseService |
17 | 17 | { |
18 | - /** |
|
19 | - * @var Config |
|
20 | - */ |
|
21 | - private $config; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Stats |
|
26 | - */ |
|
27 | - private $stats_collection; |
|
28 | - |
|
29 | - public function __construct(Stats $stats_collection, Config $config) |
|
30 | - { |
|
31 | - $this->config = $config; |
|
32 | - $this->stats_collection = $stats_collection; |
|
33 | - $this->loadPueClient(); |
|
34 | - } |
|
35 | - |
|
36 | - private function loadPueClient() |
|
37 | - { |
|
38 | - // PUE Auto Upgrades stuff |
|
39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
41 | - |
|
42 | - // $options needs to be an array with the included keys as listed. |
|
43 | - $options = array( |
|
44 | - // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
45 | - // clients options table. Will be automatically set if left blank. |
|
46 | - 'apikey' => $this->config->siteLicenseKey(), |
|
47 | - // (required), you will need to obtain the apikey that the client gets from your site and |
|
48 | - // then saves in their sites options table (see 'getting an api-key' below) |
|
49 | - 'lang_domain' => $this->config->i18nDomain(), |
|
50 | - // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
51 | - // localized). That way strings in this file will be included in the translation for your plugin. |
|
52 | - 'checkPeriod' => $this->config->checkPeriod(), |
|
53 | - // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
54 | - // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
55 | - // default to 12 hours. |
|
56 | - 'option_key' => $this->config->optionKey(), |
|
57 | - // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
58 | - // updating your information message whenever this option_key is modified. |
|
59 | - 'options_page_slug' => $this->config->optionsPageSlug(), |
|
60 | - 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
61 | - 'use_wp_update' => true, |
|
62 | - // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
63 | - 'extra_stats' => $this->stats_collection->statsCallback(), |
|
64 | - 'turn_on_notices_saved' => true, |
|
65 | - ); |
|
66 | - // initiate the class and start the plugin update engine! |
|
67 | - new PluginUpdateEngineChecker( |
|
68 | - $this->config->hostServerUrl(), |
|
69 | - $this->config->pluginSlug(), |
|
70 | - $options |
|
71 | - ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
78 | - * |
|
79 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
80 | - * identify plugins. Defaults to core update |
|
81 | - * @return boolean True if update available, false if not. |
|
82 | - */ |
|
83 | - public static function isUpdateAvailable($basename = '') |
|
84 | - { |
|
85 | - $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
86 | - |
|
87 | - $update = false; |
|
88 | - |
|
89 | - // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
90 | - $folder = '/' . dirname($basename); |
|
91 | - |
|
92 | - $plugins = get_plugins($folder); |
|
93 | - $current = get_site_transient('update_plugins'); |
|
94 | - |
|
95 | - foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
96 | - if (isset($current->response['plugin_file'])) { |
|
97 | - $update = true; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - // it's possible that there is an update but an invalid site-license-key is in use |
|
102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
103 | - $update = true; |
|
104 | - } |
|
105 | - |
|
106 | - return $update; |
|
107 | - } |
|
18 | + /** |
|
19 | + * @var Config |
|
20 | + */ |
|
21 | + private $config; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Stats |
|
26 | + */ |
|
27 | + private $stats_collection; |
|
28 | + |
|
29 | + public function __construct(Stats $stats_collection, Config $config) |
|
30 | + { |
|
31 | + $this->config = $config; |
|
32 | + $this->stats_collection = $stats_collection; |
|
33 | + $this->loadPueClient(); |
|
34 | + } |
|
35 | + |
|
36 | + private function loadPueClient() |
|
37 | + { |
|
38 | + // PUE Auto Upgrades stuff |
|
39 | + if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | + require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
41 | + |
|
42 | + // $options needs to be an array with the included keys as listed. |
|
43 | + $options = array( |
|
44 | + // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
45 | + // clients options table. Will be automatically set if left blank. |
|
46 | + 'apikey' => $this->config->siteLicenseKey(), |
|
47 | + // (required), you will need to obtain the apikey that the client gets from your site and |
|
48 | + // then saves in their sites options table (see 'getting an api-key' below) |
|
49 | + 'lang_domain' => $this->config->i18nDomain(), |
|
50 | + // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
51 | + // localized). That way strings in this file will be included in the translation for your plugin. |
|
52 | + 'checkPeriod' => $this->config->checkPeriod(), |
|
53 | + // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
54 | + // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
55 | + // default to 12 hours. |
|
56 | + 'option_key' => $this->config->optionKey(), |
|
57 | + // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
58 | + // updating your information message whenever this option_key is modified. |
|
59 | + 'options_page_slug' => $this->config->optionsPageSlug(), |
|
60 | + 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
61 | + 'use_wp_update' => true, |
|
62 | + // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
63 | + 'extra_stats' => $this->stats_collection->statsCallback(), |
|
64 | + 'turn_on_notices_saved' => true, |
|
65 | + ); |
|
66 | + // initiate the class and start the plugin update engine! |
|
67 | + new PluginUpdateEngineChecker( |
|
68 | + $this->config->hostServerUrl(), |
|
69 | + $this->config->pluginSlug(), |
|
70 | + $options |
|
71 | + ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
78 | + * |
|
79 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
80 | + * identify plugins. Defaults to core update |
|
81 | + * @return boolean True if update available, false if not. |
|
82 | + */ |
|
83 | + public static function isUpdateAvailable($basename = '') |
|
84 | + { |
|
85 | + $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
86 | + |
|
87 | + $update = false; |
|
88 | + |
|
89 | + // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
90 | + $folder = '/' . dirname($basename); |
|
91 | + |
|
92 | + $plugins = get_plugins($folder); |
|
93 | + $current = get_site_transient('update_plugins'); |
|
94 | + |
|
95 | + foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
96 | + if (isset($current->response['plugin_file'])) { |
|
97 | + $update = true; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + // it's possible that there is an update but an invalid site-license-key is in use |
|
102 | + if (get_site_option('pue_json_error_' . $basename)) { |
|
103 | + $update = true; |
|
104 | + } |
|
105 | + |
|
106 | + return $update; |
|
107 | + } |
|
108 | 108 | } |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | private function loadPueClient() |
37 | 37 | { |
38 | 38 | // PUE Auto Upgrades stuff |
39 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { // include the file |
|
40 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php'); |
|
39 | + if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { // include the file |
|
40 | + require_once(EE_THIRD_PARTY.'pue/pue-client.php'); |
|
41 | 41 | |
42 | 42 | // $options needs to be an array with the included keys as listed. |
43 | 43 | $options = array( |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $update = false; |
88 | 88 | |
89 | 89 | // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
90 | - $folder = '/' . dirname($basename); |
|
90 | + $folder = '/'.dirname($basename); |
|
91 | 91 | |
92 | 92 | $plugins = get_plugins($folder); |
93 | 93 | $current = get_site_transient('update_plugins'); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | // it's possible that there is an update but an invalid site-license-key is in use |
102 | - if (get_site_option('pue_json_error_' . $basename)) { |
|
102 | + if (get_site_option('pue_json_error_'.$basename)) { |
|
103 | 103 | $update = true; |
104 | 104 | } |
105 | 105 |
@@ -31,385 +31,385 @@ |
||
31 | 31 | class PersistentAdminNoticeManager |
32 | 32 | { |
33 | 33 | |
34 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | - */ |
|
39 | - private $notice_collection; |
|
40 | - |
|
41 | - /** |
|
42 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | - * |
|
45 | - * @var string $return_url |
|
46 | - */ |
|
47 | - private $return_url; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var CapabilitiesChecker $capabilities_checker |
|
51 | - */ |
|
52 | - private $capabilities_checker; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var RequestInterface $request |
|
56 | - */ |
|
57 | - private $request; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * PersistentAdminNoticeManager constructor |
|
62 | - * |
|
63 | - * @param string $return_url where to redirect to after dismissing notices |
|
64 | - * @param CapabilitiesChecker $capabilities_checker |
|
65 | - * @param RequestInterface $request |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - */ |
|
68 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->setReturnUrl($return_url); |
|
71 | - $this->capabilities_checker = $capabilities_checker; |
|
72 | - $this->request = $request; |
|
73 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | - add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $return_url |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - public function setReturnUrl($return_url) |
|
87 | - { |
|
88 | - if (! is_string($return_url)) { |
|
89 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | - } |
|
91 | - $this->return_url = $return_url; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return Collection |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws DomainException |
|
101 | - * @throws DuplicateCollectionIdentifierException |
|
102 | - */ |
|
103 | - protected function getPersistentAdminNoticeCollection() |
|
104 | - { |
|
105 | - if (! $this->notice_collection instanceof Collection) { |
|
106 | - $this->notice_collection = new Collection( |
|
107 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | - ); |
|
109 | - $this->retrieveStoredNotices(); |
|
110 | - $this->registerNotices(); |
|
111 | - } |
|
112 | - return $this->notice_collection; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | - * |
|
119 | - * @return void |
|
120 | - * @throws InvalidEntityException |
|
121 | - * @throws DomainException |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws DuplicateCollectionIdentifierException |
|
124 | - */ |
|
125 | - protected function retrieveStoredNotices() |
|
126 | - { |
|
127 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | - if (! empty($persistent_admin_notices)) { |
|
129 | - foreach ($persistent_admin_notices as $name => $details) { |
|
130 | - if (is_array($details)) { |
|
131 | - if (! isset( |
|
132 | - $details['message'], |
|
133 | - $details['capability'], |
|
134 | - $details['cap_context'], |
|
135 | - $details['dismissed'] |
|
136 | - )) { |
|
137 | - throw new DomainException( |
|
138 | - sprintf( |
|
139 | - esc_html__( |
|
140 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | - 'event_espresso' |
|
142 | - ), |
|
143 | - $name |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - // new format for nag notices |
|
148 | - $this->notice_collection->add( |
|
149 | - new PersistentAdminNotice( |
|
150 | - $name, |
|
151 | - $details['message'], |
|
152 | - false, |
|
153 | - $details['capability'], |
|
154 | - $details['cap_context'], |
|
155 | - $details['dismissed'] |
|
156 | - ), |
|
157 | - sanitize_key($name) |
|
158 | - ); |
|
159 | - } else { |
|
160 | - try { |
|
161 | - // old nag notices, that we want to convert to the new format |
|
162 | - $this->notice_collection->add( |
|
163 | - new PersistentAdminNotice( |
|
164 | - $name, |
|
165 | - (string) $details, |
|
166 | - false, |
|
167 | - '', |
|
168 | - '', |
|
169 | - empty($details) |
|
170 | - ), |
|
171 | - sanitize_key($name) |
|
172 | - ); |
|
173 | - } catch (Exception $e) { |
|
174 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | - } |
|
176 | - } |
|
177 | - // each notice will self register when the action hook in registerNotices is triggered |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * exposes the Persistent Admin Notice Collection via an action |
|
185 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | - * without compromising the actual collection like a filter would |
|
187 | - */ |
|
188 | - protected function registerNotices() |
|
189 | - { |
|
190 | - do_action( |
|
191 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | - $this->notice_collection |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @throws DomainException |
|
199 | - * @throws InvalidClassException |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DuplicateCollectionIdentifierException |
|
204 | - */ |
|
205 | - public function displayNotices() |
|
206 | - { |
|
207 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | - if ($this->notice_collection->hasObjects()) { |
|
209 | - $enqueue_assets = false; |
|
210 | - // and display notices |
|
211 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | - // don't display notices that have already been dismissed |
|
214 | - if ($persistent_admin_notice->getDismissed()) { |
|
215 | - continue; |
|
216 | - } |
|
217 | - try { |
|
218 | - $this->capabilities_checker->processCapCheck( |
|
219 | - $persistent_admin_notice->getCapCheck() |
|
220 | - ); |
|
221 | - } catch (InsufficientPermissionsException $e) { |
|
222 | - // user does not have required cap, so skip to next notice |
|
223 | - // and just eat the exception - nom nom nom nom |
|
224 | - continue; |
|
225 | - } |
|
226 | - if ($persistent_admin_notice->getMessage() === '') { |
|
227 | - continue; |
|
228 | - } |
|
229 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | - $enqueue_assets = true; |
|
231 | - } |
|
232 | - if ($enqueue_assets) { |
|
233 | - $this->enqueueAssets(); |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * does what it's named |
|
241 | - * |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - public function enqueueAssets() |
|
245 | - { |
|
246 | - wp_register_script( |
|
247 | - 'espresso_core', |
|
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | - array('jquery'), |
|
250 | - EVENT_ESPRESSO_VERSION, |
|
251 | - true |
|
252 | - ); |
|
253 | - wp_register_script( |
|
254 | - 'ee_error_js', |
|
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | - array('espresso_core'), |
|
257 | - EVENT_ESPRESSO_VERSION, |
|
258 | - true |
|
259 | - ); |
|
260 | - wp_localize_script( |
|
261 | - 'ee_error_js', |
|
262 | - 'ee_dismiss', |
|
263 | - array( |
|
264 | - 'return_url' => urlencode($this->return_url), |
|
265 | - 'ajax_url' => WP_AJAX_URL, |
|
266 | - 'unknown_error' => esc_html__( |
|
267 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - ) |
|
271 | - ); |
|
272 | - wp_enqueue_script('ee_error_js'); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * displayPersistentAdminNoticeHtml |
|
278 | - * |
|
279 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | - */ |
|
281 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | - { |
|
283 | - // used in template |
|
284 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | - require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * dismissNotice |
|
292 | - * |
|
293 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
294 | - * @param bool $purge if true, then delete it from the db |
|
295 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
296 | - * @return void |
|
297 | - * @throws InvalidEntityException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws DomainException |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws DuplicateCollectionIdentifierException |
|
306 | - */ |
|
307 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
308 | - { |
|
309 | - $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
310 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
311 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
313 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
314 | - $persistent_admin_notice->setDismissed(true); |
|
315 | - $persistent_admin_notice->setPurge($purge); |
|
316 | - $this->saveNotices(); |
|
317 | - } |
|
318 | - if ($return) { |
|
319 | - return; |
|
320 | - } |
|
321 | - if ($this->request->isAjax()) { |
|
322 | - // grab any notices and concatenate into string |
|
323 | - echo wp_json_encode( |
|
324 | - array( |
|
325 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
326 | - ) |
|
327 | - ); |
|
328 | - exit(); |
|
329 | - } |
|
330 | - // save errors to a transient to be displayed on next request (after redirect) |
|
331 | - EE_Error::get_notices(false, true); |
|
332 | - wp_safe_redirect( |
|
333 | - urldecode( |
|
334 | - $this->request->getRequestParam('return_url', '') |
|
335 | - ) |
|
336 | - ); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * saveNotices |
|
342 | - * |
|
343 | - * @throws DomainException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - * @throws InvalidEntityException |
|
347 | - * @throws DuplicateCollectionIdentifierException |
|
348 | - */ |
|
349 | - public function saveNotices() |
|
350 | - { |
|
351 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
352 | - if ($this->notice_collection->hasObjects()) { |
|
353 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
354 | - // maybe initialize persistent_admin_notices |
|
355 | - if (empty($persistent_admin_notices)) { |
|
356 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
357 | - } |
|
358 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
359 | - // are we deleting this notice ? |
|
360 | - if ($persistent_admin_notice->getPurge()) { |
|
361 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
362 | - } else { |
|
363 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
364 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
365 | - 'message' => $persistent_admin_notice->getMessage(), |
|
366 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
367 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
368 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
369 | - ); |
|
370 | - } |
|
371 | - } |
|
372 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @throws DomainException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - * @throws InvalidEntityException |
|
381 | - * @throws InvalidInterfaceException |
|
382 | - * @throws DuplicateCollectionIdentifierException |
|
383 | - */ |
|
384 | - public function registerAndSaveNotices() |
|
385 | - { |
|
386 | - $this->getPersistentAdminNoticeCollection(); |
|
387 | - $this->registerNotices(); |
|
388 | - $this->saveNotices(); |
|
389 | - add_filter( |
|
390 | - 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
391 | - '__return_true' |
|
392 | - ); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @throws DomainException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws InvalidEntityException |
|
400 | - * @throws InvalidInterfaceException |
|
401 | - * @throws InvalidArgumentException |
|
402 | - * @throws DuplicateCollectionIdentifierException |
|
403 | - */ |
|
404 | - public static function loadRegisterAndSaveNotices() |
|
405 | - { |
|
406 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
407 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
408 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
409 | - ); |
|
410 | - // if shutdown has already run, then call registerAndSaveNotices() manually |
|
411 | - if (did_action('shutdown')) { |
|
412 | - $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
413 | - } |
|
414 | - } |
|
34 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | + */ |
|
39 | + private $notice_collection; |
|
40 | + |
|
41 | + /** |
|
42 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | + * |
|
45 | + * @var string $return_url |
|
46 | + */ |
|
47 | + private $return_url; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var CapabilitiesChecker $capabilities_checker |
|
51 | + */ |
|
52 | + private $capabilities_checker; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var RequestInterface $request |
|
56 | + */ |
|
57 | + private $request; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * PersistentAdminNoticeManager constructor |
|
62 | + * |
|
63 | + * @param string $return_url where to redirect to after dismissing notices |
|
64 | + * @param CapabilitiesChecker $capabilities_checker |
|
65 | + * @param RequestInterface $request |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + */ |
|
68 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->setReturnUrl($return_url); |
|
71 | + $this->capabilities_checker = $capabilities_checker; |
|
72 | + $this->request = $request; |
|
73 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | + add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $return_url |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + public function setReturnUrl($return_url) |
|
87 | + { |
|
88 | + if (! is_string($return_url)) { |
|
89 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | + } |
|
91 | + $this->return_url = $return_url; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return Collection |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws DomainException |
|
101 | + * @throws DuplicateCollectionIdentifierException |
|
102 | + */ |
|
103 | + protected function getPersistentAdminNoticeCollection() |
|
104 | + { |
|
105 | + if (! $this->notice_collection instanceof Collection) { |
|
106 | + $this->notice_collection = new Collection( |
|
107 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | + ); |
|
109 | + $this->retrieveStoredNotices(); |
|
110 | + $this->registerNotices(); |
|
111 | + } |
|
112 | + return $this->notice_collection; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | + * |
|
119 | + * @return void |
|
120 | + * @throws InvalidEntityException |
|
121 | + * @throws DomainException |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws DuplicateCollectionIdentifierException |
|
124 | + */ |
|
125 | + protected function retrieveStoredNotices() |
|
126 | + { |
|
127 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | + if (! empty($persistent_admin_notices)) { |
|
129 | + foreach ($persistent_admin_notices as $name => $details) { |
|
130 | + if (is_array($details)) { |
|
131 | + if (! isset( |
|
132 | + $details['message'], |
|
133 | + $details['capability'], |
|
134 | + $details['cap_context'], |
|
135 | + $details['dismissed'] |
|
136 | + )) { |
|
137 | + throw new DomainException( |
|
138 | + sprintf( |
|
139 | + esc_html__( |
|
140 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | + 'event_espresso' |
|
142 | + ), |
|
143 | + $name |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + // new format for nag notices |
|
148 | + $this->notice_collection->add( |
|
149 | + new PersistentAdminNotice( |
|
150 | + $name, |
|
151 | + $details['message'], |
|
152 | + false, |
|
153 | + $details['capability'], |
|
154 | + $details['cap_context'], |
|
155 | + $details['dismissed'] |
|
156 | + ), |
|
157 | + sanitize_key($name) |
|
158 | + ); |
|
159 | + } else { |
|
160 | + try { |
|
161 | + // old nag notices, that we want to convert to the new format |
|
162 | + $this->notice_collection->add( |
|
163 | + new PersistentAdminNotice( |
|
164 | + $name, |
|
165 | + (string) $details, |
|
166 | + false, |
|
167 | + '', |
|
168 | + '', |
|
169 | + empty($details) |
|
170 | + ), |
|
171 | + sanitize_key($name) |
|
172 | + ); |
|
173 | + } catch (Exception $e) { |
|
174 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | + } |
|
176 | + } |
|
177 | + // each notice will self register when the action hook in registerNotices is triggered |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * exposes the Persistent Admin Notice Collection via an action |
|
185 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | + * without compromising the actual collection like a filter would |
|
187 | + */ |
|
188 | + protected function registerNotices() |
|
189 | + { |
|
190 | + do_action( |
|
191 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | + $this->notice_collection |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @throws DomainException |
|
199 | + * @throws InvalidClassException |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DuplicateCollectionIdentifierException |
|
204 | + */ |
|
205 | + public function displayNotices() |
|
206 | + { |
|
207 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | + if ($this->notice_collection->hasObjects()) { |
|
209 | + $enqueue_assets = false; |
|
210 | + // and display notices |
|
211 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | + // don't display notices that have already been dismissed |
|
214 | + if ($persistent_admin_notice->getDismissed()) { |
|
215 | + continue; |
|
216 | + } |
|
217 | + try { |
|
218 | + $this->capabilities_checker->processCapCheck( |
|
219 | + $persistent_admin_notice->getCapCheck() |
|
220 | + ); |
|
221 | + } catch (InsufficientPermissionsException $e) { |
|
222 | + // user does not have required cap, so skip to next notice |
|
223 | + // and just eat the exception - nom nom nom nom |
|
224 | + continue; |
|
225 | + } |
|
226 | + if ($persistent_admin_notice->getMessage() === '') { |
|
227 | + continue; |
|
228 | + } |
|
229 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | + $enqueue_assets = true; |
|
231 | + } |
|
232 | + if ($enqueue_assets) { |
|
233 | + $this->enqueueAssets(); |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * does what it's named |
|
241 | + * |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + public function enqueueAssets() |
|
245 | + { |
|
246 | + wp_register_script( |
|
247 | + 'espresso_core', |
|
248 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | + array('jquery'), |
|
250 | + EVENT_ESPRESSO_VERSION, |
|
251 | + true |
|
252 | + ); |
|
253 | + wp_register_script( |
|
254 | + 'ee_error_js', |
|
255 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | + array('espresso_core'), |
|
257 | + EVENT_ESPRESSO_VERSION, |
|
258 | + true |
|
259 | + ); |
|
260 | + wp_localize_script( |
|
261 | + 'ee_error_js', |
|
262 | + 'ee_dismiss', |
|
263 | + array( |
|
264 | + 'return_url' => urlencode($this->return_url), |
|
265 | + 'ajax_url' => WP_AJAX_URL, |
|
266 | + 'unknown_error' => esc_html__( |
|
267 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + ) |
|
271 | + ); |
|
272 | + wp_enqueue_script('ee_error_js'); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * displayPersistentAdminNoticeHtml |
|
278 | + * |
|
279 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | + */ |
|
281 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | + { |
|
283 | + // used in template |
|
284 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | + require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * dismissNotice |
|
292 | + * |
|
293 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
294 | + * @param bool $purge if true, then delete it from the db |
|
295 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
296 | + * @return void |
|
297 | + * @throws InvalidEntityException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws DomainException |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws DuplicateCollectionIdentifierException |
|
306 | + */ |
|
307 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
308 | + { |
|
309 | + $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
310 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
311 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
313 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
314 | + $persistent_admin_notice->setDismissed(true); |
|
315 | + $persistent_admin_notice->setPurge($purge); |
|
316 | + $this->saveNotices(); |
|
317 | + } |
|
318 | + if ($return) { |
|
319 | + return; |
|
320 | + } |
|
321 | + if ($this->request->isAjax()) { |
|
322 | + // grab any notices and concatenate into string |
|
323 | + echo wp_json_encode( |
|
324 | + array( |
|
325 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
326 | + ) |
|
327 | + ); |
|
328 | + exit(); |
|
329 | + } |
|
330 | + // save errors to a transient to be displayed on next request (after redirect) |
|
331 | + EE_Error::get_notices(false, true); |
|
332 | + wp_safe_redirect( |
|
333 | + urldecode( |
|
334 | + $this->request->getRequestParam('return_url', '') |
|
335 | + ) |
|
336 | + ); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * saveNotices |
|
342 | + * |
|
343 | + * @throws DomainException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + * @throws InvalidEntityException |
|
347 | + * @throws DuplicateCollectionIdentifierException |
|
348 | + */ |
|
349 | + public function saveNotices() |
|
350 | + { |
|
351 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
352 | + if ($this->notice_collection->hasObjects()) { |
|
353 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
354 | + // maybe initialize persistent_admin_notices |
|
355 | + if (empty($persistent_admin_notices)) { |
|
356 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
357 | + } |
|
358 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
359 | + // are we deleting this notice ? |
|
360 | + if ($persistent_admin_notice->getPurge()) { |
|
361 | + unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
362 | + } else { |
|
363 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
364 | + $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
365 | + 'message' => $persistent_admin_notice->getMessage(), |
|
366 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
367 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
368 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
369 | + ); |
|
370 | + } |
|
371 | + } |
|
372 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @throws DomainException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + * @throws InvalidEntityException |
|
381 | + * @throws InvalidInterfaceException |
|
382 | + * @throws DuplicateCollectionIdentifierException |
|
383 | + */ |
|
384 | + public function registerAndSaveNotices() |
|
385 | + { |
|
386 | + $this->getPersistentAdminNoticeCollection(); |
|
387 | + $this->registerNotices(); |
|
388 | + $this->saveNotices(); |
|
389 | + add_filter( |
|
390 | + 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
391 | + '__return_true' |
|
392 | + ); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @throws DomainException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws InvalidEntityException |
|
400 | + * @throws InvalidInterfaceException |
|
401 | + * @throws InvalidArgumentException |
|
402 | + * @throws DuplicateCollectionIdentifierException |
|
403 | + */ |
|
404 | + public static function loadRegisterAndSaveNotices() |
|
405 | + { |
|
406 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
407 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
408 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
409 | + ); |
|
410 | + // if shutdown has already run, then call registerAndSaveNotices() manually |
|
411 | + if (did_action('shutdown')) { |
|
412 | + $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
413 | + } |
|
414 | + } |
|
415 | 415 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function setReturnUrl($return_url) |
87 | 87 | { |
88 | - if (! is_string($return_url)) { |
|
88 | + if ( ! is_string($return_url)) { |
|
89 | 89 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
90 | 90 | } |
91 | 91 | $this->return_url = $return_url; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function getPersistentAdminNoticeCollection() |
104 | 104 | { |
105 | - if (! $this->notice_collection instanceof Collection) { |
|
105 | + if ( ! $this->notice_collection instanceof Collection) { |
|
106 | 106 | $this->notice_collection = new Collection( |
107 | 107 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
108 | 108 | ); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | protected function retrieveStoredNotices() |
126 | 126 | { |
127 | 127 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
128 | - if (! empty($persistent_admin_notices)) { |
|
128 | + if ( ! empty($persistent_admin_notices)) { |
|
129 | 129 | foreach ($persistent_admin_notices as $name => $details) { |
130 | 130 | if (is_array($details)) { |
131 | - if (! isset( |
|
131 | + if ( ! isset( |
|
132 | 132 | $details['message'], |
133 | 133 | $details['capability'], |
134 | 134 | $details['cap_context'], |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | { |
246 | 246 | wp_register_script( |
247 | 247 | 'espresso_core', |
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
248 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
249 | 249 | array('jquery'), |
250 | 250 | EVENT_ESPRESSO_VERSION, |
251 | 251 | true |
252 | 252 | ); |
253 | 253 | wp_register_script( |
254 | 254 | 'ee_error_js', |
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
255 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
256 | 256 | array('espresso_core'), |
257 | 257 | EVENT_ESPRESSO_VERSION, |
258 | 258 | true |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // used in template |
284 | 284 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
285 | 285 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
286 | - require EE_TEMPLATES . '/notifications/persistent_admin_notice.template.php'; |
|
286 | + require EE_TEMPLATES.'/notifications/persistent_admin_notice.template.php'; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | { |
309 | 309 | $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
310 | 310 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
311 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
311 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | 312 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
313 | 313 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
314 | 314 | $persistent_admin_notice->setDismissed(true); |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | foreach ($this->notice_collection as $persistent_admin_notice) { |
359 | 359 | // are we deleting this notice ? |
360 | 360 | if ($persistent_admin_notice->getPurge()) { |
361 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
361 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
362 | 362 | } else { |
363 | 363 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
364 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
364 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
365 | 365 | 'message' => $persistent_admin_notice->getMessage(), |
366 | 366 | 'capability' => $persistent_admin_notice->getCapability(), |
367 | 367 | 'cap_context' => $persistent_admin_notice->getCapContext(), |
@@ -16,29 +16,29 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * used for setting up css and js required for the display strategy |
|
21 | - * |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function enqueueStylesAndScripts() |
|
25 | - { |
|
26 | - // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
27 | - wp_enqueue_style( |
|
28 | - 'ee_progress_steps_display_number_bubbles', |
|
29 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
30 | - ); |
|
31 | - } |
|
19 | + /** |
|
20 | + * used for setting up css and js required for the display strategy |
|
21 | + * |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function enqueueStylesAndScripts() |
|
25 | + { |
|
26 | + // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
|
27 | + wp_enqueue_style( |
|
28 | + 'ee_progress_steps_display_number_bubbles', |
|
29 | + plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * loads and returns a full server path to the template used for the display strategy |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function getTemplate() |
|
40 | - { |
|
41 | - // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
42 | - return __DIR__ . '/number_bubbles.template.php'; |
|
43 | - } |
|
34 | + /** |
|
35 | + * loads and returns a full server path to the template used for the display strategy |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function getTemplate() |
|
40 | + { |
|
41 | + // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
|
42 | + return __DIR__ . '/number_bubbles.template.php'; |
|
43 | + } |
|
44 | 44 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css |
27 | 27 | wp_enqueue_style( |
28 | 28 | 'ee_progress_steps_display_number_bubbles', |
29 | - plugin_dir_url(__FILE__) . 'number_bubbles.css' |
|
29 | + plugin_dir_url(__FILE__).'number_bubbles.css' |
|
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
@@ -39,6 +39,6 @@ discard block |
||
39 | 39 | public function getTemplate() |
40 | 40 | { |
41 | 41 | // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php'; |
42 | - return __DIR__ . '/number_bubbles.template.php'; |
|
42 | + return __DIR__.'/number_bubbles.template.php'; |
|
43 | 43 | } |
44 | 44 | } |
@@ -21,409 +21,409 @@ |
||
21 | 21 | class LegacyShortcodesManager |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var EE_Registry $registry |
|
26 | - */ |
|
27 | - private $registry; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * LegacyShortcodesManager constructor. |
|
32 | - * |
|
33 | - * @param \EE_Registry $registry |
|
34 | - */ |
|
35 | - public function __construct(EE_Registry $registry) |
|
36 | - { |
|
37 | - $this->registry = $registry; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @return EE_Registry |
|
43 | - */ |
|
44 | - public function registry() |
|
45 | - { |
|
46 | - return $this->registry; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * registerShortcodes |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function registerShortcodes() |
|
56 | - { |
|
57 | - $this->registry->shortcodes = $this->getShortcodes(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * getShortcodes |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getShortcodes() |
|
67 | - { |
|
68 | - // previously this method would glob the shortcodes directory |
|
69 | - // then filter that list of shortcodes to register, |
|
70 | - // but now we are going to just supply an empty array. |
|
71 | - // this allows any shortcodes that have not yet been converted to the new system |
|
72 | - // to still get loaded and processed, albeit using the same legacy logic as before |
|
73 | - $shortcodes_to_register = apply_filters( |
|
74 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
75 | - array() |
|
76 | - ); |
|
77 | - if (! empty($shortcodes_to_register)) { |
|
78 | - // cycle thru shortcode folders |
|
79 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
80 | - // add to list of installed shortcode modules |
|
81 | - $this->registerShortcode($shortcode_path); |
|
82 | - } |
|
83 | - } |
|
84 | - // filter list of installed modules |
|
85 | - return apply_filters( |
|
86 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
87 | - ! empty($this->registry->shortcodes) |
|
88 | - ? $this->registry->shortcodes |
|
89 | - : array() |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * register_shortcode - makes core aware of this shortcode |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function registerShortcode($shortcode_path = null) |
|
102 | - { |
|
103 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
104 | - $shortcode_ext = '.shortcode.php'; |
|
105 | - // make all separators match |
|
106 | - $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
107 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
108 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
109 | - // grab shortcode file name from directory name and break apart at dots |
|
110 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
111 | - // take first segment from file name pieces and remove class prefix if it exists |
|
112 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
113 | - ? substr($shortcode_file[0], 4) |
|
114 | - : $shortcode_file[0]; |
|
115 | - // sanitize shortcode directory name |
|
116 | - $shortcode = sanitize_key($shortcode); |
|
117 | - // now we need to rebuild the shortcode path |
|
118 | - $shortcode_path = explode('/', $shortcode_path); |
|
119 | - // remove last segment |
|
120 | - array_pop($shortcode_path); |
|
121 | - // glue it back together |
|
122 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
123 | - } else { |
|
124 | - // we need to generate the filename based off of the folder name |
|
125 | - // grab and sanitize shortcode directory name |
|
126 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
127 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
128 | - } |
|
129 | - // create classname from shortcode directory or file name |
|
130 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
131 | - // add class prefix |
|
132 | - $shortcode_class = 'EES_' . $shortcode; |
|
133 | - // does the shortcode exist ? |
|
134 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
135 | - $msg = sprintf( |
|
136 | - esc_html__( |
|
137 | - 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
138 | - 'event_espresso' |
|
139 | - ), |
|
140 | - $shortcode_class, |
|
141 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
142 | - ); |
|
143 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | - return false; |
|
145 | - } |
|
146 | - // load the shortcode class file |
|
147 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
148 | - // verify that class exists |
|
149 | - if (! class_exists($shortcode_class)) { |
|
150 | - $msg = sprintf( |
|
151 | - esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
152 | - $shortcode_class |
|
153 | - ); |
|
154 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | - return false; |
|
156 | - } |
|
157 | - $shortcode = strtoupper($shortcode); |
|
158 | - // add to array of registered shortcodes |
|
159 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
160 | - return true; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * _initialize_shortcodes |
|
166 | - * allow shortcodes to set hooks for the rest of the system |
|
167 | - * |
|
168 | - * @access private |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public function addShortcodes() |
|
172 | - { |
|
173 | - // cycle thru shortcode folders |
|
174 | - foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
175 | - // add class prefix |
|
176 | - $shortcode_class = 'EES_' . $shortcode; |
|
177 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
178 | - // which set hooks ? |
|
179 | - if (is_admin()) { |
|
180 | - // fire immediately |
|
181 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
182 | - } else { |
|
183 | - // delay until other systems are online |
|
184 | - add_action( |
|
185 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
186 | - array($shortcode_class, 'set_hooks') |
|
187 | - ); |
|
188 | - // convert classname to UPPERCASE and create WP shortcode. |
|
189 | - $shortcode_tag = strtoupper($shortcode); |
|
190 | - // but first check if the shortcode has already |
|
191 | - // been added before assigning 'fallback_shortcode_processor' |
|
192 | - if (! shortcode_exists($shortcode_tag)) { |
|
193 | - // NOTE: this shortcode declaration will get overridden if the shortcode |
|
194 | - // is successfully detected in the post content in initializeShortcode() |
|
195 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * callback for the WP "get_header" hook point |
|
204 | - * checks posts for EE shortcodes, and initializes them, |
|
205 | - * then toggles filter switch that loads core default assets |
|
206 | - * |
|
207 | - * @param \WP_Query $wp_query |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - public function initializeShortcodes(WP_Query $wp_query) |
|
211 | - { |
|
212 | - if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
213 | - return; |
|
214 | - } |
|
215 | - global $wp; |
|
216 | - /** @var EE_Front_controller $Front_Controller */ |
|
217 | - $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
218 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
219 | - $Front_Controller->Request_Handler()->set_request_vars(); |
|
220 | - // grab post_name from request |
|
221 | - $current_post = apply_filters( |
|
222 | - 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
223 | - $Front_Controller->Request_Handler()->get('post_name') |
|
224 | - ); |
|
225 | - $show_on_front = get_option('show_on_front'); |
|
226 | - // if it's not set, then check if frontpage is blog |
|
227 | - if (empty($current_post)) { |
|
228 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
229 | - $current_post = 'posts'; |
|
230 | - // unless.. |
|
231 | - if ($show_on_front === 'page') { |
|
232 | - // some other page is set as the homepage |
|
233 | - $page_on_front = get_option('page_on_front'); |
|
234 | - if ($page_on_front) { |
|
235 | - // k now we need to find the post_name for this page |
|
236 | - global $wpdb; |
|
237 | - $page_on_front = $wpdb->get_var( |
|
238 | - $wpdb->prepare( |
|
239 | - "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
240 | - $page_on_front |
|
241 | - ) |
|
242 | - ); |
|
243 | - // set the current post slug to what it actually is |
|
244 | - $current_post = $page_on_front ? $page_on_front : $current_post; |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
249 | - $current_post = basename($current_post); |
|
250 | - if (// is current page/post the "blog" page ? |
|
251 | - $current_post === EE_Config::get_page_for_posts() |
|
252 | - // or are we on a category page? |
|
253 | - || ( |
|
254 | - is_array(term_exists($current_post, 'category')) |
|
255 | - || array_key_exists('category_name', $wp->query_vars) |
|
256 | - ) |
|
257 | - ) { |
|
258 | - // initialize all legacy shortcodes |
|
259 | - $load_assets = $this->parseContentForShortcodes('', true); |
|
260 | - } else { |
|
261 | - global $wpdb; |
|
262 | - $post_content = $wpdb->get_var( |
|
263 | - $wpdb->prepare( |
|
264 | - "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
265 | - $current_post |
|
266 | - ) |
|
267 | - ); |
|
268 | - $load_assets = $this->parseContentForShortcodes($post_content); |
|
269 | - } |
|
270 | - if ($load_assets) { |
|
271 | - $this->registry->REQ->set_espresso_page(true); |
|
272 | - add_filter('FHEE_load_css', '__return_true'); |
|
273 | - add_filter('FHEE_load_js', '__return_true'); |
|
274 | - } |
|
275 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * checks supplied content against list of legacy shortcodes, |
|
281 | - * then initializes any found shortcodes, and returns true. |
|
282 | - * returns false if no shortcodes found. |
|
283 | - * |
|
284 | - * @param string $content |
|
285 | - * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public function parseContentForShortcodes($content = '', $load_all = false) |
|
289 | - { |
|
290 | - $has_shortcode = false; |
|
291 | - foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
292 | - if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
293 | - // load up the shortcode |
|
294 | - $this->initializeShortcode($shortcode_class); |
|
295 | - $has_shortcode = true; |
|
296 | - } |
|
297 | - } |
|
298 | - return $has_shortcode; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
304 | - * |
|
305 | - * @param string $shortcode_class |
|
306 | - * @param WP $wp |
|
307 | - */ |
|
308 | - public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
309 | - { |
|
310 | - // don't do anything if shortcode is already initialized |
|
311 | - if (empty($this->registry->shortcodes->{$shortcode_class}) |
|
312 | - || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
313 | - ) { |
|
314 | - return; |
|
315 | - } |
|
316 | - // let's pause to reflect on this... |
|
317 | - $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
318 | - // ensure that class is actually a shortcode |
|
319 | - if (defined('WP_DEBUG') |
|
320 | - && WP_DEBUG === true |
|
321 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
322 | - ) { |
|
323 | - EE_Error::add_error( |
|
324 | - sprintf( |
|
325 | - esc_html__( |
|
326 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
327 | - 'event_espresso' |
|
328 | - ), |
|
329 | - $shortcode_class |
|
330 | - ), |
|
331 | - __FILE__, |
|
332 | - __FUNCTION__, |
|
333 | - __LINE__ |
|
334 | - ); |
|
335 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
336 | - return; |
|
337 | - } |
|
338 | - global $wp; |
|
339 | - // and pass the request object to the run method |
|
340 | - $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
341 | - // fire the shortcode class's run method, so that it can activate resources |
|
342 | - $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * get classname, remove EES_prefix, and convert to UPPERCASE |
|
348 | - * |
|
349 | - * @param string $class_name |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public static function generateShortcodeTagFromClassName($class_name) |
|
353 | - { |
|
354 | - return strtoupper(str_replace('EES_', '', $class_name)); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * add EES_prefix and Capitalize words |
|
360 | - * |
|
361 | - * @param string $tag |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public static function generateShortcodeClassNameFromTag($tag) |
|
365 | - { |
|
366 | - // order of operation runs from inside to out |
|
367 | - // 5) maybe add prefix |
|
368 | - return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
369 | - // 4) find spaces, replace with underscores |
|
370 | - str_replace( |
|
371 | - ' ', |
|
372 | - '_', |
|
373 | - // 3) capitalize first letter of each word |
|
374 | - ucwords( |
|
375 | - // 2) also change to lowercase so ucwords() will work |
|
376 | - strtolower( |
|
377 | - // 1) find underscores, replace with spaces so ucwords() will work |
|
378 | - str_replace( |
|
379 | - '_', |
|
380 | - ' ', |
|
381 | - $tag |
|
382 | - ) |
|
383 | - ) |
|
384 | - ) |
|
385 | - ) |
|
386 | - ); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * maybe add EES_prefix |
|
392 | - * |
|
393 | - * @param string $class_name |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public static function addShortcodeClassPrefix($class_name) |
|
397 | - { |
|
398 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @return array |
|
404 | - */ |
|
405 | - public function getEspressoShortcodeTags() |
|
406 | - { |
|
407 | - static $shortcode_tags = array(); |
|
408 | - if (empty($shortcode_tags)) { |
|
409 | - $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
410 | - } |
|
411 | - return $shortcode_tags; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @param string $content |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function doShortcode($content) |
|
420 | - { |
|
421 | - foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
422 | - if (strpos($content, $shortcode_tag) !== false) { |
|
423 | - $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
424 | - $this->initializeShortcode($shortcode_class); |
|
425 | - } |
|
426 | - } |
|
427 | - return do_shortcode($content); |
|
428 | - } |
|
24 | + /** |
|
25 | + * @var EE_Registry $registry |
|
26 | + */ |
|
27 | + private $registry; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * LegacyShortcodesManager constructor. |
|
32 | + * |
|
33 | + * @param \EE_Registry $registry |
|
34 | + */ |
|
35 | + public function __construct(EE_Registry $registry) |
|
36 | + { |
|
37 | + $this->registry = $registry; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @return EE_Registry |
|
43 | + */ |
|
44 | + public function registry() |
|
45 | + { |
|
46 | + return $this->registry; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * registerShortcodes |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function registerShortcodes() |
|
56 | + { |
|
57 | + $this->registry->shortcodes = $this->getShortcodes(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * getShortcodes |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getShortcodes() |
|
67 | + { |
|
68 | + // previously this method would glob the shortcodes directory |
|
69 | + // then filter that list of shortcodes to register, |
|
70 | + // but now we are going to just supply an empty array. |
|
71 | + // this allows any shortcodes that have not yet been converted to the new system |
|
72 | + // to still get loaded and processed, albeit using the same legacy logic as before |
|
73 | + $shortcodes_to_register = apply_filters( |
|
74 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
75 | + array() |
|
76 | + ); |
|
77 | + if (! empty($shortcodes_to_register)) { |
|
78 | + // cycle thru shortcode folders |
|
79 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
80 | + // add to list of installed shortcode modules |
|
81 | + $this->registerShortcode($shortcode_path); |
|
82 | + } |
|
83 | + } |
|
84 | + // filter list of installed modules |
|
85 | + return apply_filters( |
|
86 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
87 | + ! empty($this->registry->shortcodes) |
|
88 | + ? $this->registry->shortcodes |
|
89 | + : array() |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * register_shortcode - makes core aware of this shortcode |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function registerShortcode($shortcode_path = null) |
|
102 | + { |
|
103 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
104 | + $shortcode_ext = '.shortcode.php'; |
|
105 | + // make all separators match |
|
106 | + $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
107 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
108 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
109 | + // grab shortcode file name from directory name and break apart at dots |
|
110 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
111 | + // take first segment from file name pieces and remove class prefix if it exists |
|
112 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
113 | + ? substr($shortcode_file[0], 4) |
|
114 | + : $shortcode_file[0]; |
|
115 | + // sanitize shortcode directory name |
|
116 | + $shortcode = sanitize_key($shortcode); |
|
117 | + // now we need to rebuild the shortcode path |
|
118 | + $shortcode_path = explode('/', $shortcode_path); |
|
119 | + // remove last segment |
|
120 | + array_pop($shortcode_path); |
|
121 | + // glue it back together |
|
122 | + $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
123 | + } else { |
|
124 | + // we need to generate the filename based off of the folder name |
|
125 | + // grab and sanitize shortcode directory name |
|
126 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
127 | + $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
128 | + } |
|
129 | + // create classname from shortcode directory or file name |
|
130 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
131 | + // add class prefix |
|
132 | + $shortcode_class = 'EES_' . $shortcode; |
|
133 | + // does the shortcode exist ? |
|
134 | + if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
135 | + $msg = sprintf( |
|
136 | + esc_html__( |
|
137 | + 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
138 | + 'event_espresso' |
|
139 | + ), |
|
140 | + $shortcode_class, |
|
141 | + $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
142 | + ); |
|
143 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | + return false; |
|
145 | + } |
|
146 | + // load the shortcode class file |
|
147 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
148 | + // verify that class exists |
|
149 | + if (! class_exists($shortcode_class)) { |
|
150 | + $msg = sprintf( |
|
151 | + esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
152 | + $shortcode_class |
|
153 | + ); |
|
154 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | + return false; |
|
156 | + } |
|
157 | + $shortcode = strtoupper($shortcode); |
|
158 | + // add to array of registered shortcodes |
|
159 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
160 | + return true; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * _initialize_shortcodes |
|
166 | + * allow shortcodes to set hooks for the rest of the system |
|
167 | + * |
|
168 | + * @access private |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public function addShortcodes() |
|
172 | + { |
|
173 | + // cycle thru shortcode folders |
|
174 | + foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
175 | + // add class prefix |
|
176 | + $shortcode_class = 'EES_' . $shortcode; |
|
177 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
178 | + // which set hooks ? |
|
179 | + if (is_admin()) { |
|
180 | + // fire immediately |
|
181 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
182 | + } else { |
|
183 | + // delay until other systems are online |
|
184 | + add_action( |
|
185 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
186 | + array($shortcode_class, 'set_hooks') |
|
187 | + ); |
|
188 | + // convert classname to UPPERCASE and create WP shortcode. |
|
189 | + $shortcode_tag = strtoupper($shortcode); |
|
190 | + // but first check if the shortcode has already |
|
191 | + // been added before assigning 'fallback_shortcode_processor' |
|
192 | + if (! shortcode_exists($shortcode_tag)) { |
|
193 | + // NOTE: this shortcode declaration will get overridden if the shortcode |
|
194 | + // is successfully detected in the post content in initializeShortcode() |
|
195 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * callback for the WP "get_header" hook point |
|
204 | + * checks posts for EE shortcodes, and initializes them, |
|
205 | + * then toggles filter switch that loads core default assets |
|
206 | + * |
|
207 | + * @param \WP_Query $wp_query |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + public function initializeShortcodes(WP_Query $wp_query) |
|
211 | + { |
|
212 | + if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) { |
|
213 | + return; |
|
214 | + } |
|
215 | + global $wp; |
|
216 | + /** @var EE_Front_controller $Front_Controller */ |
|
217 | + $Front_Controller = $this->registry->load_core('Front_Controller', array(), false); |
|
218 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
219 | + $Front_Controller->Request_Handler()->set_request_vars(); |
|
220 | + // grab post_name from request |
|
221 | + $current_post = apply_filters( |
|
222 | + 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
223 | + $Front_Controller->Request_Handler()->get('post_name') |
|
224 | + ); |
|
225 | + $show_on_front = get_option('show_on_front'); |
|
226 | + // if it's not set, then check if frontpage is blog |
|
227 | + if (empty($current_post)) { |
|
228 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
229 | + $current_post = 'posts'; |
|
230 | + // unless.. |
|
231 | + if ($show_on_front === 'page') { |
|
232 | + // some other page is set as the homepage |
|
233 | + $page_on_front = get_option('page_on_front'); |
|
234 | + if ($page_on_front) { |
|
235 | + // k now we need to find the post_name for this page |
|
236 | + global $wpdb; |
|
237 | + $page_on_front = $wpdb->get_var( |
|
238 | + $wpdb->prepare( |
|
239 | + "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
240 | + $page_on_front |
|
241 | + ) |
|
242 | + ); |
|
243 | + // set the current post slug to what it actually is |
|
244 | + $current_post = $page_on_front ? $page_on_front : $current_post; |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
249 | + $current_post = basename($current_post); |
|
250 | + if (// is current page/post the "blog" page ? |
|
251 | + $current_post === EE_Config::get_page_for_posts() |
|
252 | + // or are we on a category page? |
|
253 | + || ( |
|
254 | + is_array(term_exists($current_post, 'category')) |
|
255 | + || array_key_exists('category_name', $wp->query_vars) |
|
256 | + ) |
|
257 | + ) { |
|
258 | + // initialize all legacy shortcodes |
|
259 | + $load_assets = $this->parseContentForShortcodes('', true); |
|
260 | + } else { |
|
261 | + global $wpdb; |
|
262 | + $post_content = $wpdb->get_var( |
|
263 | + $wpdb->prepare( |
|
264 | + "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
265 | + $current_post |
|
266 | + ) |
|
267 | + ); |
|
268 | + $load_assets = $this->parseContentForShortcodes($post_content); |
|
269 | + } |
|
270 | + if ($load_assets) { |
|
271 | + $this->registry->REQ->set_espresso_page(true); |
|
272 | + add_filter('FHEE_load_css', '__return_true'); |
|
273 | + add_filter('FHEE_load_js', '__return_true'); |
|
274 | + } |
|
275 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * checks supplied content against list of legacy shortcodes, |
|
281 | + * then initializes any found shortcodes, and returns true. |
|
282 | + * returns false if no shortcodes found. |
|
283 | + * |
|
284 | + * @param string $content |
|
285 | + * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public function parseContentForShortcodes($content = '', $load_all = false) |
|
289 | + { |
|
290 | + $has_shortcode = false; |
|
291 | + foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
292 | + if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
293 | + // load up the shortcode |
|
294 | + $this->initializeShortcode($shortcode_class); |
|
295 | + $has_shortcode = true; |
|
296 | + } |
|
297 | + } |
|
298 | + return $has_shortcode; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
304 | + * |
|
305 | + * @param string $shortcode_class |
|
306 | + * @param WP $wp |
|
307 | + */ |
|
308 | + public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
309 | + { |
|
310 | + // don't do anything if shortcode is already initialized |
|
311 | + if (empty($this->registry->shortcodes->{$shortcode_class}) |
|
312 | + || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
313 | + ) { |
|
314 | + return; |
|
315 | + } |
|
316 | + // let's pause to reflect on this... |
|
317 | + $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
318 | + // ensure that class is actually a shortcode |
|
319 | + if (defined('WP_DEBUG') |
|
320 | + && WP_DEBUG === true |
|
321 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
322 | + ) { |
|
323 | + EE_Error::add_error( |
|
324 | + sprintf( |
|
325 | + esc_html__( |
|
326 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
327 | + 'event_espresso' |
|
328 | + ), |
|
329 | + $shortcode_class |
|
330 | + ), |
|
331 | + __FILE__, |
|
332 | + __FUNCTION__, |
|
333 | + __LINE__ |
|
334 | + ); |
|
335 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
336 | + return; |
|
337 | + } |
|
338 | + global $wp; |
|
339 | + // and pass the request object to the run method |
|
340 | + $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
341 | + // fire the shortcode class's run method, so that it can activate resources |
|
342 | + $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * get classname, remove EES_prefix, and convert to UPPERCASE |
|
348 | + * |
|
349 | + * @param string $class_name |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public static function generateShortcodeTagFromClassName($class_name) |
|
353 | + { |
|
354 | + return strtoupper(str_replace('EES_', '', $class_name)); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * add EES_prefix and Capitalize words |
|
360 | + * |
|
361 | + * @param string $tag |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public static function generateShortcodeClassNameFromTag($tag) |
|
365 | + { |
|
366 | + // order of operation runs from inside to out |
|
367 | + // 5) maybe add prefix |
|
368 | + return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
369 | + // 4) find spaces, replace with underscores |
|
370 | + str_replace( |
|
371 | + ' ', |
|
372 | + '_', |
|
373 | + // 3) capitalize first letter of each word |
|
374 | + ucwords( |
|
375 | + // 2) also change to lowercase so ucwords() will work |
|
376 | + strtolower( |
|
377 | + // 1) find underscores, replace with spaces so ucwords() will work |
|
378 | + str_replace( |
|
379 | + '_', |
|
380 | + ' ', |
|
381 | + $tag |
|
382 | + ) |
|
383 | + ) |
|
384 | + ) |
|
385 | + ) |
|
386 | + ); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * maybe add EES_prefix |
|
392 | + * |
|
393 | + * @param string $class_name |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public static function addShortcodeClassPrefix($class_name) |
|
397 | + { |
|
398 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @return array |
|
404 | + */ |
|
405 | + public function getEspressoShortcodeTags() |
|
406 | + { |
|
407 | + static $shortcode_tags = array(); |
|
408 | + if (empty($shortcode_tags)) { |
|
409 | + $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
410 | + } |
|
411 | + return $shortcode_tags; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @param string $content |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function doShortcode($content) |
|
420 | + { |
|
421 | + foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
422 | + if (strpos($content, $shortcode_tag) !== false) { |
|
423 | + $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
424 | + $this->initializeShortcode($shortcode_class); |
|
425 | + } |
|
426 | + } |
|
427 | + return do_shortcode($content); |
|
428 | + } |
|
429 | 429 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
75 | 75 | array() |
76 | 76 | ); |
77 | - if (! empty($shortcodes_to_register)) { |
|
77 | + if ( ! empty($shortcodes_to_register)) { |
|
78 | 78 | // cycle thru shortcode folders |
79 | 79 | foreach ($shortcodes_to_register as $shortcode_path) { |
80 | 80 | // add to list of installed shortcode modules |
@@ -119,44 +119,44 @@ discard block |
||
119 | 119 | // remove last segment |
120 | 120 | array_pop($shortcode_path); |
121 | 121 | // glue it back together |
122 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
122 | + $shortcode_path = implode('/', $shortcode_path).'/'; |
|
123 | 123 | } else { |
124 | 124 | // we need to generate the filename based off of the folder name |
125 | 125 | // grab and sanitize shortcode directory name |
126 | 126 | $shortcode = sanitize_key(basename($shortcode_path)); |
127 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
127 | + $shortcode_path = rtrim($shortcode_path, '/').'/'; |
|
128 | 128 | } |
129 | 129 | // create classname from shortcode directory or file name |
130 | 130 | $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
131 | 131 | // add class prefix |
132 | - $shortcode_class = 'EES_' . $shortcode; |
|
132 | + $shortcode_class = 'EES_'.$shortcode; |
|
133 | 133 | // does the shortcode exist ? |
134 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
134 | + if ( ! is_readable($shortcode_path.'/'.$shortcode_class.$shortcode_ext)) { |
|
135 | 135 | $msg = sprintf( |
136 | 136 | esc_html__( |
137 | 137 | 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
138 | 138 | 'event_espresso' |
139 | 139 | ), |
140 | 140 | $shortcode_class, |
141 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
141 | + $shortcode_path.'/'.$shortcode_class.$shortcode_ext |
|
142 | 142 | ); |
143 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | // load the shortcode class file |
147 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
147 | + require_once($shortcode_path.$shortcode_class.$shortcode_ext); |
|
148 | 148 | // verify that class exists |
149 | - if (! class_exists($shortcode_class)) { |
|
149 | + if ( ! class_exists($shortcode_class)) { |
|
150 | 150 | $msg = sprintf( |
151 | 151 | esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
152 | 152 | $shortcode_class |
153 | 153 | ); |
154 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | $shortcode = strtoupper($shortcode); |
158 | 158 | // add to array of registered shortcodes |
159 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
159 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext; |
|
160 | 160 | return true; |
161 | 161 | } |
162 | 162 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | // cycle thru shortcode folders |
174 | 174 | foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
175 | 175 | // add class prefix |
176 | - $shortcode_class = 'EES_' . $shortcode; |
|
176 | + $shortcode_class = 'EES_'.$shortcode; |
|
177 | 177 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
178 | 178 | // which set hooks ? |
179 | 179 | if (is_admin()) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $shortcode_tag = strtoupper($shortcode); |
190 | 190 | // but first check if the shortcode has already |
191 | 191 | // been added before assigning 'fallback_shortcode_processor' |
192 | - if (! shortcode_exists($shortcode_tag)) { |
|
192 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
193 | 193 | // NOTE: this shortcode declaration will get overridden if the shortcode |
194 | 194 | // is successfully detected in the post content in initializeShortcode() |
195 | 195 | add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public static function addShortcodeClassPrefix($class_name) |
397 | 397 | { |
398 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
398 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 |
@@ -17,261 +17,261 @@ |
||
17 | 17 | class EE_Log |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $_logs_folder = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $_log_file = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private $_log = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $_debug_file = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - private $_debug_log = ''; |
|
44 | - |
|
45 | - /** |
|
46 | - * Used for remote logging |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $_remote_logging_url = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $_remote_log = ''; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EE_Log |
|
59 | - */ |
|
60 | - private static $_instance; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return EE_Log |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - if (! self::$_instance instanceof EE_Log) { |
|
69 | - self::$_instance = new self(); |
|
70 | - } |
|
71 | - return self::$_instance; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @access private |
|
76 | - * @return EE_Log |
|
77 | - */ |
|
78 | - private function __construct() |
|
79 | - { |
|
80 | - |
|
81 | - if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
82 | - && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
87 | - $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
|
88 | - $this->_log = ''; |
|
89 | - $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
|
90 | - $this->_debug_log = ''; |
|
91 | - $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
92 | - $this->_remote_log = ''; |
|
93 | - |
|
94 | - add_action('admin_init', array($this, 'verify_filesystem'), -10); |
|
95 | - add_action('AHEE_log', array($this, 'log'), 10, 4); |
|
96 | - if (EE_Registry::instance()->CFG->admin->use_full_logging) { |
|
97 | - add_action('shutdown', array($this, 'write_log'), 9999); |
|
98 | - // if WP_DEBUG |
|
99 | - add_action('shutdown', array($this, 'write_debug'), 9999); |
|
100 | - } |
|
101 | - if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
102 | - add_action('shutdown', array($this, 'send_log'), 9999); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * verify_filesystem |
|
109 | - * tests that the required files and folders exist and are writable |
|
110 | - * |
|
111 | - */ |
|
112 | - public function verify_filesystem() |
|
113 | - { |
|
114 | - try { |
|
115 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
116 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
117 | - EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
|
118 | - } catch (EE_Error $e) { |
|
119 | - EE_Error::add_error( |
|
120 | - sprintf( |
|
121 | - __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
|
122 | - ' ' . $e->getMessage() |
|
123 | - ), |
|
124 | - __FILE__, |
|
125 | - __FUNCTION__, |
|
126 | - __LINE__ |
|
127 | - ); |
|
128 | - return; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * _format_message |
|
135 | - * makes yer log entries look all purdy |
|
136 | - * |
|
137 | - * @param string $file |
|
138 | - * @param string $function |
|
139 | - * @param string $message |
|
140 | - * @param string $type |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
144 | - { |
|
145 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
146 | - $msg .= '[' . current_time('mysql') . '] '; |
|
147 | - $msg .= ! empty($file) ? basename($file) : ''; |
|
148 | - $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
149 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
150 | - $msg .= PHP_EOL; |
|
151 | - $type = ! empty($type) ? $type : 'log message'; |
|
152 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
153 | - return $msg; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * log |
|
159 | - * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
160 | - * EE_Log::write_log() callback |
|
161 | - * |
|
162 | - * @param string $file |
|
163 | - * @param string $function |
|
164 | - * @param string $message |
|
165 | - * @param string $type |
|
166 | - */ |
|
167 | - public function log($file = '', $function = '', $message = '', $type = '') |
|
168 | - { |
|
169 | - $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * write_log |
|
175 | - * appends the results of the 'AHEE_log' filter to the espresso log file |
|
176 | - */ |
|
177 | - public function write_log() |
|
178 | - { |
|
179 | - try { |
|
180 | - // get existing log file and append new log info |
|
181 | - $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
182 | - EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
183 | - } catch (EE_Error $e) { |
|
184 | - EE_Error::add_error( |
|
185 | - sprintf( |
|
186 | - __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
|
187 | - ' ' . $e->getMessage() |
|
188 | - ), |
|
189 | - __FILE__, |
|
190 | - __FUNCTION__, |
|
191 | - __LINE__ |
|
192 | - ); |
|
193 | - return; |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * send_log |
|
200 | - * sends the espresso log to a remote URL via a PHP cURL request |
|
201 | - */ |
|
202 | - public function send_log() |
|
203 | - { |
|
204 | - |
|
205 | - if (empty($this->_remote_logging_url)) { |
|
206 | - return; |
|
207 | - } |
|
208 | - |
|
209 | - $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
210 | - $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
211 | - $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
212 | - $data .= '&time=' . time(); |
|
213 | - $data .= '&remote_log=' . $this->_log; |
|
214 | - $data .= '&request_array=' . json_encode($_REQUEST); |
|
215 | - $data .= '&action=save'; |
|
216 | - |
|
217 | - if (defined('EELOGGING_PASS')) { |
|
218 | - $data .= '&pass=' . EELOGGING_PASS; |
|
219 | - } |
|
220 | - if (defined('EELOGGING_KEY')) { |
|
221 | - $data .= '&key=' . EELOGGING_KEY; |
|
222 | - } |
|
223 | - |
|
224 | - $c = curl_init($this->_remote_logging_url); |
|
225 | - curl_setopt($c, CURLOPT_POST, true); |
|
226 | - curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
227 | - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
228 | - curl_exec($c); |
|
229 | - curl_close($c); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * write_debug |
|
235 | - * writes the contents of the current request's $_GET and $_POST arrays to a log file. |
|
236 | - * previous entries are overwritten |
|
237 | - */ |
|
238 | - public function write_debug() |
|
239 | - { |
|
240 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
241 | - $this->_debug_log = ''; |
|
242 | - foreach ($_GET as $key => $value) { |
|
243 | - $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
244 | - } |
|
245 | - foreach ($_POST as $key => $value) { |
|
246 | - $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
247 | - } |
|
248 | - try { |
|
249 | - EEH_File::write_to_file( |
|
250 | - $this->_logs_folder . $this->_debug_file, |
|
251 | - $this->_debug_log, |
|
252 | - 'Event Espresso Debug Log' |
|
253 | - ); |
|
254 | - } catch (EE_Error $e) { |
|
255 | - EE_Error::add_error( |
|
256 | - sprintf( |
|
257 | - __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
|
258 | - ' ' . $e->getMessage() |
|
259 | - ), |
|
260 | - __FILE__, |
|
261 | - __FUNCTION__, |
|
262 | - __LINE__ |
|
263 | - ); |
|
264 | - return; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * __clone |
|
272 | - */ |
|
273 | - public function __clone() |
|
274 | - { |
|
275 | - trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
276 | - } |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $_logs_folder = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $_log_file = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private $_log = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $_debug_file = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + private $_debug_log = ''; |
|
44 | + |
|
45 | + /** |
|
46 | + * Used for remote logging |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $_remote_logging_url = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $_remote_log = ''; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EE_Log |
|
59 | + */ |
|
60 | + private static $_instance; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return EE_Log |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + if (! self::$_instance instanceof EE_Log) { |
|
69 | + self::$_instance = new self(); |
|
70 | + } |
|
71 | + return self::$_instance; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @access private |
|
76 | + * @return EE_Log |
|
77 | + */ |
|
78 | + private function __construct() |
|
79 | + { |
|
80 | + |
|
81 | + if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
82 | + && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
87 | + $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
|
88 | + $this->_log = ''; |
|
89 | + $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
|
90 | + $this->_debug_log = ''; |
|
91 | + $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
92 | + $this->_remote_log = ''; |
|
93 | + |
|
94 | + add_action('admin_init', array($this, 'verify_filesystem'), -10); |
|
95 | + add_action('AHEE_log', array($this, 'log'), 10, 4); |
|
96 | + if (EE_Registry::instance()->CFG->admin->use_full_logging) { |
|
97 | + add_action('shutdown', array($this, 'write_log'), 9999); |
|
98 | + // if WP_DEBUG |
|
99 | + add_action('shutdown', array($this, 'write_debug'), 9999); |
|
100 | + } |
|
101 | + if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
102 | + add_action('shutdown', array($this, 'send_log'), 9999); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * verify_filesystem |
|
109 | + * tests that the required files and folders exist and are writable |
|
110 | + * |
|
111 | + */ |
|
112 | + public function verify_filesystem() |
|
113 | + { |
|
114 | + try { |
|
115 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
116 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
117 | + EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
|
118 | + } catch (EE_Error $e) { |
|
119 | + EE_Error::add_error( |
|
120 | + sprintf( |
|
121 | + __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
|
122 | + ' ' . $e->getMessage() |
|
123 | + ), |
|
124 | + __FILE__, |
|
125 | + __FUNCTION__, |
|
126 | + __LINE__ |
|
127 | + ); |
|
128 | + return; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * _format_message |
|
135 | + * makes yer log entries look all purdy |
|
136 | + * |
|
137 | + * @param string $file |
|
138 | + * @param string $function |
|
139 | + * @param string $message |
|
140 | + * @param string $type |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
144 | + { |
|
145 | + $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
146 | + $msg .= '[' . current_time('mysql') . '] '; |
|
147 | + $msg .= ! empty($file) ? basename($file) : ''; |
|
148 | + $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
149 | + $msg .= ! empty($function) ? $function . '()' : ''; |
|
150 | + $msg .= PHP_EOL; |
|
151 | + $type = ! empty($type) ? $type : 'log message'; |
|
152 | + $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
153 | + return $msg; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * log |
|
159 | + * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
160 | + * EE_Log::write_log() callback |
|
161 | + * |
|
162 | + * @param string $file |
|
163 | + * @param string $function |
|
164 | + * @param string $message |
|
165 | + * @param string $type |
|
166 | + */ |
|
167 | + public function log($file = '', $function = '', $message = '', $type = '') |
|
168 | + { |
|
169 | + $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * write_log |
|
175 | + * appends the results of the 'AHEE_log' filter to the espresso log file |
|
176 | + */ |
|
177 | + public function write_log() |
|
178 | + { |
|
179 | + try { |
|
180 | + // get existing log file and append new log info |
|
181 | + $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
182 | + EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
183 | + } catch (EE_Error $e) { |
|
184 | + EE_Error::add_error( |
|
185 | + sprintf( |
|
186 | + __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
|
187 | + ' ' . $e->getMessage() |
|
188 | + ), |
|
189 | + __FILE__, |
|
190 | + __FUNCTION__, |
|
191 | + __LINE__ |
|
192 | + ); |
|
193 | + return; |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * send_log |
|
200 | + * sends the espresso log to a remote URL via a PHP cURL request |
|
201 | + */ |
|
202 | + public function send_log() |
|
203 | + { |
|
204 | + |
|
205 | + if (empty($this->_remote_logging_url)) { |
|
206 | + return; |
|
207 | + } |
|
208 | + |
|
209 | + $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
210 | + $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
211 | + $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
212 | + $data .= '&time=' . time(); |
|
213 | + $data .= '&remote_log=' . $this->_log; |
|
214 | + $data .= '&request_array=' . json_encode($_REQUEST); |
|
215 | + $data .= '&action=save'; |
|
216 | + |
|
217 | + if (defined('EELOGGING_PASS')) { |
|
218 | + $data .= '&pass=' . EELOGGING_PASS; |
|
219 | + } |
|
220 | + if (defined('EELOGGING_KEY')) { |
|
221 | + $data .= '&key=' . EELOGGING_KEY; |
|
222 | + } |
|
223 | + |
|
224 | + $c = curl_init($this->_remote_logging_url); |
|
225 | + curl_setopt($c, CURLOPT_POST, true); |
|
226 | + curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
227 | + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
228 | + curl_exec($c); |
|
229 | + curl_close($c); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * write_debug |
|
235 | + * writes the contents of the current request's $_GET and $_POST arrays to a log file. |
|
236 | + * previous entries are overwritten |
|
237 | + */ |
|
238 | + public function write_debug() |
|
239 | + { |
|
240 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
241 | + $this->_debug_log = ''; |
|
242 | + foreach ($_GET as $key => $value) { |
|
243 | + $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
244 | + } |
|
245 | + foreach ($_POST as $key => $value) { |
|
246 | + $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
247 | + } |
|
248 | + try { |
|
249 | + EEH_File::write_to_file( |
|
250 | + $this->_logs_folder . $this->_debug_file, |
|
251 | + $this->_debug_log, |
|
252 | + 'Event Espresso Debug Log' |
|
253 | + ); |
|
254 | + } catch (EE_Error $e) { |
|
255 | + EE_Error::add_error( |
|
256 | + sprintf( |
|
257 | + __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
|
258 | + ' ' . $e->getMessage() |
|
259 | + ), |
|
260 | + __FILE__, |
|
261 | + __FUNCTION__, |
|
262 | + __LINE__ |
|
263 | + ); |
|
264 | + return; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * __clone |
|
272 | + */ |
|
273 | + public function __clone() |
|
274 | + { |
|
275 | + trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
276 | + } |
|
277 | 277 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public static function instance() |
67 | 67 | { |
68 | - if (! self::$_instance instanceof EE_Log) { |
|
68 | + if ( ! self::$_instance instanceof EE_Log) { |
|
69 | 69 | self::$_instance = new self(); |
70 | 70 | } |
71 | 71 | return self::$_instance; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | private function __construct() |
79 | 79 | { |
80 | 80 | |
81 | - if (! EE_Registry::instance()->CFG->admin->use_full_logging |
|
81 | + if ( ! EE_Registry::instance()->CFG->admin->use_full_logging |
|
82 | 82 | && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | - $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'; |
|
86 | + $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR.'logs/'; |
|
87 | 87 | $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
88 | 88 | $this->_log = ''; |
89 | 89 | $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | public function verify_filesystem() |
113 | 113 | { |
114 | 114 | try { |
115 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file); |
|
116 | - EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file); |
|
115 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_log_file); |
|
116 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_debug_file); |
|
117 | 117 | EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
118 | 118 | } catch (EE_Error $e) { |
119 | 119 | EE_Error::add_error( |
120 | 120 | sprintf( |
121 | 121 | __('Event Espresso logging could not be setup because: %s', 'event_espresso'), |
122 | - ' ' . $e->getMessage() |
|
122 | + ' '.$e->getMessage() |
|
123 | 123 | ), |
124 | 124 | __FILE__, |
125 | 125 | __FUNCTION__, |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | */ |
143 | 143 | private function _format_message($file = '', $function = '', $message = '', $type = '') |
144 | 144 | { |
145 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
146 | - $msg .= '[' . current_time('mysql') . '] '; |
|
145 | + $msg = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
146 | + $msg .= '['.current_time('mysql').'] '; |
|
147 | 147 | $msg .= ! empty($file) ? basename($file) : ''; |
148 | 148 | $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
149 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
149 | + $msg .= ! empty($function) ? $function.'()' : ''; |
|
150 | 150 | $msg .= PHP_EOL; |
151 | 151 | $type = ! empty($type) ? $type : 'log message'; |
152 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
152 | + $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : ''; |
|
153 | 153 | return $msg; |
154 | 154 | } |
155 | 155 | |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | { |
179 | 179 | try { |
180 | 180 | // get existing log file and append new log info |
181 | - $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log; |
|
182 | - EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log'); |
|
181 | + $this->_log = EEH_File::get_file_contents($this->_logs_folder.$this->_log_file).$this->_log; |
|
182 | + EEH_File::write_to_file($this->_logs_folder.$this->_log_file, $this->_log, 'Event Espresso Log'); |
|
183 | 183 | } catch (EE_Error $e) { |
184 | 184 | EE_Error::add_error( |
185 | 185 | sprintf( |
186 | 186 | __('Could not write to the Event Espresso log file because: %s', 'event_espresso'), |
187 | - ' ' . $e->getMessage() |
|
187 | + ' '.$e->getMessage() |
|
188 | 188 | ), |
189 | 189 | __FILE__, |
190 | 190 | __FUNCTION__, |
@@ -206,19 +206,19 @@ discard block |
||
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | - $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
210 | - $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
211 | - $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
212 | - $data .= '&time=' . time(); |
|
213 | - $data .= '&remote_log=' . $this->_log; |
|
214 | - $data .= '&request_array=' . json_encode($_REQUEST); |
|
209 | + $data = 'domain='.$_SERVER['HTTP_HOST']; |
|
210 | + $data .= '&ip='.$_SERVER['SERVER_ADDR']; |
|
211 | + $data .= '&server_type='.$_SERVER['SERVER_SOFTWARE']; |
|
212 | + $data .= '&time='.time(); |
|
213 | + $data .= '&remote_log='.$this->_log; |
|
214 | + $data .= '&request_array='.json_encode($_REQUEST); |
|
215 | 215 | $data .= '&action=save'; |
216 | 216 | |
217 | 217 | if (defined('EELOGGING_PASS')) { |
218 | - $data .= '&pass=' . EELOGGING_PASS; |
|
218 | + $data .= '&pass='.EELOGGING_PASS; |
|
219 | 219 | } |
220 | 220 | if (defined('EELOGGING_KEY')) { |
221 | - $data .= '&key=' . EELOGGING_KEY; |
|
221 | + $data .= '&key='.EELOGGING_KEY; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | $c = curl_init($this->_remote_logging_url); |
@@ -240,14 +240,14 @@ discard block |
||
240 | 240 | if (defined('WP_DEBUG') && WP_DEBUG) { |
241 | 241 | $this->_debug_log = ''; |
242 | 242 | foreach ($_GET as $key => $value) { |
243 | - $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
243 | + $this->_debug_log .= '$_GET["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
244 | 244 | } |
245 | 245 | foreach ($_POST as $key => $value) { |
246 | - $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
246 | + $this->_debug_log .= '$_POST["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
247 | 247 | } |
248 | 248 | try { |
249 | 249 | EEH_File::write_to_file( |
250 | - $this->_logs_folder . $this->_debug_file, |
|
250 | + $this->_logs_folder.$this->_debug_file, |
|
251 | 251 | $this->_debug_log, |
252 | 252 | 'Event Espresso Debug Log' |
253 | 253 | ); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | EE_Error::add_error( |
256 | 256 | sprintf( |
257 | 257 | __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), |
258 | - ' ' . $e->getMessage() |
|
258 | + ' '.$e->getMessage() |
|
259 | 259 | ), |
260 | 260 | __FILE__, |
261 | 261 | __FUNCTION__, |
@@ -11,670 +11,670 @@ discard block |
||
11 | 11 | class EEH_Debug_Tools |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * instance of the EEH_Autoloader object |
|
16 | - * |
|
17 | - * @var $_instance |
|
18 | - * @access private |
|
19 | - */ |
|
20 | - private static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $_memory_usage_points = array(); |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @singleton method used to instantiate class object |
|
31 | - * @access public |
|
32 | - * @return EEH_Debug_Tools |
|
33 | - */ |
|
34 | - public static function instance() |
|
35 | - { |
|
36 | - // check if class object is instantiated, and instantiated properly |
|
37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | - self::$_instance = new self(); |
|
39 | - } |
|
40 | - return self::$_instance; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * private class constructor |
|
47 | - */ |
|
48 | - private function __construct() |
|
49 | - { |
|
50 | - // load Kint PHP debugging library |
|
51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
52 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
53 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
54 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
55 | - // so we've moved it to our test folder so that it is not included with production releases |
|
56 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
58 | - } |
|
59 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
60 | - // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
61 | - // } |
|
62 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
63 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
64 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
65 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * show_db_name |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function show_db_name() |
|
76 | - { |
|
77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
79 | - . DB_NAME |
|
80 | - . '</p>'; |
|
81 | - } |
|
82 | - if (EE_DEBUG) { |
|
83 | - Benchmark::displayResults(); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * dump EE_Session object at bottom of page after everything else has happened |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function espresso_session_footer_dump() |
|
95 | - { |
|
96 | - if ((defined('WP_DEBUG') && WP_DEBUG) |
|
97 | - && ! defined('DOING_AJAX') |
|
98 | - && class_exists('Kint') |
|
99 | - && function_exists('wp_get_current_user') |
|
100 | - && current_user_can('update_core') |
|
101 | - && class_exists('EE_Registry') |
|
102 | - ) { |
|
103 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
104 | - Kint::dump(EE_Registry::instance()->SSN); |
|
105 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
106 | - $this->espresso_list_hooked_functions(); |
|
107 | - Benchmark::displayResults(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * List All Hooked Functions |
|
115 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
116 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
117 | - * |
|
118 | - * @param string $tag |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - public function espresso_list_hooked_functions($tag = '') |
|
122 | - { |
|
123 | - global $wp_filter; |
|
124 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
125 | - if ($tag) { |
|
126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | - if (! is_array($hook[ $tag ])) { |
|
128 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
129 | - return; |
|
130 | - } |
|
131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
132 | - } else { |
|
133 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
134 | - ksort($hook); |
|
135 | - } |
|
136 | - foreach ($hook as $tag_name => $priorities) { |
|
137 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
138 | - ksort($priorities); |
|
139 | - foreach ($priorities as $priority => $function) { |
|
140 | - echo $priority; |
|
141 | - foreach ($function as $name => $properties) { |
|
142 | - echo "\t$name<br />"; |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * registered_filter_callbacks |
|
152 | - * |
|
153 | - * @param string $hook_name |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public static function registered_filter_callbacks($hook_name = '') |
|
157 | - { |
|
158 | - $filters = array(); |
|
159 | - global $wp_filter; |
|
160 | - if (isset($wp_filter[ $hook_name ])) { |
|
161 | - $filters[ $hook_name ] = array(); |
|
162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
164 | - foreach ($callbacks as $callback) { |
|
165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - return $filters; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * captures plugin activation errors for debugging |
|
176 | - * |
|
177 | - * @return void |
|
178 | - * @throws EE_Error |
|
179 | - */ |
|
180 | - public static function ee_plugin_activation_errors() |
|
181 | - { |
|
182 | - if (WP_DEBUG) { |
|
183 | - $activation_errors = ob_get_contents(); |
|
184 | - if (! empty($activation_errors)) { |
|
185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
186 | - } |
|
187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
188 | - if (class_exists('EEH_File')) { |
|
189 | - try { |
|
190 | - EEH_File::ensure_file_exists_and_is_writable( |
|
191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
192 | - ); |
|
193 | - EEH_File::write_to_file( |
|
194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
195 | - $activation_errors |
|
196 | - ); |
|
197 | - } catch (EE_Error $e) { |
|
198 | - EE_Error::add_error( |
|
199 | - sprintf( |
|
200 | - __( |
|
201 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
202 | - 'event_espresso' |
|
203 | - ), |
|
204 | - $e->getMessage() |
|
205 | - ), |
|
206 | - __FILE__, |
|
207 | - __FUNCTION__, |
|
208 | - __LINE__ |
|
209 | - ); |
|
210 | - } |
|
211 | - } else { |
|
212 | - // old school attempt |
|
213 | - file_put_contents( |
|
214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
215 | - $activation_errors |
|
216 | - ); |
|
217 | - } |
|
218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
219 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
227 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
228 | - * or we want to make sure they use something the right way. |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @param string $function The function that was called |
|
232 | - * @param string $message A message explaining what has been done incorrectly |
|
233 | - * @param string $version The version of Event Espresso where the error was added |
|
234 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
235 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
236 | - * but not have any notices appear until a later version. This allows developers |
|
237 | - * extra time to update their code before notices appear. |
|
238 | - * @param int $error_type |
|
239 | - * @uses trigger_error() |
|
240 | - */ |
|
241 | - public function doing_it_wrong( |
|
242 | - $function, |
|
243 | - $message, |
|
244 | - $version, |
|
245 | - $applies_when = '', |
|
246 | - $error_type = null |
|
247 | - ) { |
|
248 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
249 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
250 | - // because we swapped the parameter order around for the last two params, |
|
251 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
252 | - if (is_int($applies_when)) { |
|
253 | - $error_type = $applies_when; |
|
254 | - $applies_when = espresso_version(); |
|
255 | - } |
|
256 | - // if not displaying notices yet, then just leave |
|
257 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
258 | - return; |
|
259 | - } |
|
260 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
261 | - $version = $version === null |
|
262 | - ? '' |
|
263 | - : sprintf( |
|
264 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
265 | - $version |
|
266 | - ); |
|
267 | - $error_message = sprintf( |
|
268 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
269 | - $function, |
|
270 | - '<strong>', |
|
271 | - '</strong>', |
|
272 | - $message, |
|
273 | - $version |
|
274 | - ); |
|
275 | - // don't trigger error if doing ajax, |
|
276 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
277 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
278 | - $error_message .= ' ' . esc_html__( |
|
279 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
280 | - 'event_espresso' |
|
281 | - ); |
|
282 | - $error_message .= '<ul><li>'; |
|
283 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
284 | - $error_message .= '</ul>'; |
|
285 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
286 | - // now we set this on the transient so it shows up on the next request. |
|
287 | - EE_Error::get_notices(false, true); |
|
288 | - } else { |
|
289 | - trigger_error($error_message, $error_type); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Logger helpers |
|
298 | - */ |
|
299 | - /** |
|
300 | - * debug |
|
301 | - * |
|
302 | - * @param string $class |
|
303 | - * @param string $func |
|
304 | - * @param string $line |
|
305 | - * @param array $info |
|
306 | - * @param bool $display_request |
|
307 | - * @param string $debug_index |
|
308 | - * @param string $debug_key |
|
309 | - * @throws EE_Error |
|
310 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
311 | - */ |
|
312 | - public static function log( |
|
313 | - $class = '', |
|
314 | - $func = '', |
|
315 | - $line = '', |
|
316 | - $info = array(), |
|
317 | - $display_request = false, |
|
318 | - $debug_index = '', |
|
319 | - $debug_key = 'EE_DEBUG_SPCO' |
|
320 | - ) { |
|
321 | - if (WP_DEBUG) { |
|
322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
323 | - $debug_data = get_option($debug_key, array()); |
|
324 | - $default_data = array( |
|
325 | - $class => $func . '() : ' . $line, |
|
326 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
327 | - ); |
|
328 | - // don't serialize objects |
|
329 | - $info = self::strip_objects($info); |
|
330 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
331 | - if (! isset($debug_data[ $index ])) { |
|
332 | - $debug_data[ $index ] = array(); |
|
333 | - } |
|
334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
335 | - update_option($debug_key, $debug_data); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * strip_objects |
|
343 | - * |
|
344 | - * @param array $info |
|
345 | - * @return array |
|
346 | - */ |
|
347 | - public static function strip_objects($info = array()) |
|
348 | - { |
|
349 | - foreach ($info as $key => $value) { |
|
350 | - if (is_array($value)) { |
|
351 | - $info[ $key ] = self::strip_objects($value); |
|
352 | - } elseif (is_object($value)) { |
|
353 | - $object_class = get_class($value); |
|
354 | - $info[ $object_class ] = array(); |
|
355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | - if (method_exists($value, 'ID')) { |
|
357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
358 | - } |
|
359 | - if (method_exists($value, 'status')) { |
|
360 | - $info[ $object_class ]['status'] = $value->status(); |
|
361 | - } elseif (method_exists($value, 'status_ID')) { |
|
362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
363 | - } |
|
364 | - unset($info[ $key ]); |
|
365 | - } |
|
366 | - } |
|
367 | - return (array) $info; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @param mixed $var |
|
374 | - * @param string $var_name |
|
375 | - * @param string $file |
|
376 | - * @param int|string $line |
|
377 | - * @param int|string $heading_tag |
|
378 | - * @param bool $die |
|
379 | - * @param string $margin |
|
380 | - */ |
|
381 | - public static function printv( |
|
382 | - $var, |
|
383 | - $var_name = '', |
|
384 | - $file = '', |
|
385 | - $line = '', |
|
386 | - $heading_tag = 5, |
|
387 | - $die = false, |
|
388 | - $margin = '' |
|
389 | - ) { |
|
390 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
391 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
392 | - $is_method = method_exists($var_name, $var); |
|
393 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
394 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
395 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
396 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
397 | - $result .= $is_method |
|
398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
400 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
401 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
402 | - if ($die) { |
|
403 | - die($result); |
|
404 | - } |
|
405 | - echo $result; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - protected static function headingTag($heading_tag) |
|
410 | - { |
|
411 | - $heading_tag = absint($heading_tag); |
|
412 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - protected static function headingSpacer($heading_tag) |
|
417 | - { |
|
418 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
419 | - ? "\n" |
|
420 | - : ''; |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - protected static function plainOutput() |
|
425 | - { |
|
426 | - return defined('EE_TESTS_DIR') |
|
427 | - || (defined('DOING_AJAX') && DOING_AJAX) |
|
428 | - || ( |
|
429 | - isset($_SERVER['REQUEST_URI']) |
|
430 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
431 | - ); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $var_name |
|
437 | - * @param string $heading_tag |
|
438 | - * @param string $margin |
|
439 | - * @param int $line |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | - { |
|
444 | - if (EEH_Debug_Tools::plainOutput()) { |
|
445 | - $heading = ''; |
|
446 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | - $heading .= "\n"; |
|
448 | - } |
|
449 | - $heading .= "\n{$line}) {$var_name}"; |
|
450 | - return $heading; |
|
451 | - } |
|
452 | - $margin = "25px 0 0 {$margin}"; |
|
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $heading_tag |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - protected static function headingX($heading_tag = 'h5') |
|
463 | - { |
|
464 | - if (EEH_Debug_Tools::plainOutput()) { |
|
465 | - return ''; |
|
466 | - } |
|
467 | - return '</' . $heading_tag . '>'; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $content |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - protected static function grey_span($content = '') |
|
477 | - { |
|
478 | - if (EEH_Debug_Tools::plainOutput()) { |
|
479 | - return $content; |
|
480 | - } |
|
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $file |
|
488 | - * @param int $line |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - protected static function file_and_line($file, $line, $heading_tag) |
|
492 | - { |
|
493 | - if ($file === '' || $line === '') { |
|
494 | - return ''; |
|
495 | - } |
|
496 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | - if (EEH_Debug_Tools::plainOutput()) { |
|
498 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | - return " ({$file})"; |
|
500 | - } |
|
501 | - return ''; |
|
502 | - } |
|
503 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | - . $file |
|
505 | - . '<br />line no: ' |
|
506 | - . $line |
|
507 | - . '</span>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param string $content |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - protected static function orange_span($content = '') |
|
517 | - { |
|
518 | - if (EEH_Debug_Tools::plainOutput()) { |
|
519 | - return $content; |
|
520 | - } |
|
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param mixed $var |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - protected static function pre_span($var) |
|
531 | - { |
|
532 | - ob_start(); |
|
533 | - var_dump($var); |
|
534 | - $var = ob_get_clean(); |
|
535 | - if (EEH_Debug_Tools::plainOutput()) { |
|
536 | - return $var; |
|
537 | - } |
|
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @param mixed $var |
|
545 | - * @param string $var_name |
|
546 | - * @param string $file |
|
547 | - * @param int|string $line |
|
548 | - * @param int|string $heading_tag |
|
549 | - * @param bool $die |
|
550 | - */ |
|
551 | - public static function printr( |
|
552 | - $var, |
|
553 | - $var_name = '', |
|
554 | - $file = '', |
|
555 | - $line = '', |
|
556 | - $heading_tag = 5, |
|
557 | - $die = false |
|
558 | - ) { |
|
559 | - // return; |
|
560 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | - $margin = is_admin() ? ' 180px' : '0'; |
|
562 | - // $print_r = false; |
|
563 | - if (is_string($var)) { |
|
564 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | - return; |
|
566 | - } |
|
567 | - if (is_object($var)) { |
|
568 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | - // $print_r = true; |
|
570 | - } elseif (is_array($var)) { |
|
571 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | - // $print_r = true; |
|
573 | - } elseif (is_numeric($var)) { |
|
574 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | - } elseif ($var === null) { |
|
576 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | - } |
|
578 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | - EEH_Debug_Tools::pre_span($var) |
|
584 | - ); |
|
585 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | - if ($die) { |
|
588 | - die($result); |
|
589 | - } |
|
590 | - echo $result; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /******************** deprecated ********************/ |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - */ |
|
602 | - public function reset_times() |
|
603 | - { |
|
604 | - Benchmark::resetTimes(); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @deprecated 4.9.39.rc.034 |
|
611 | - * @param null $timer_name |
|
612 | - */ |
|
613 | - public function start_timer($timer_name = null) |
|
614 | - { |
|
615 | - Benchmark::startTimer($timer_name); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @deprecated 4.9.39.rc.034 |
|
622 | - * @param string $timer_name |
|
623 | - */ |
|
624 | - public function stop_timer($timer_name = '') |
|
625 | - { |
|
626 | - Benchmark::stopTimer($timer_name); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * @deprecated 4.9.39.rc.034 |
|
633 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - public function measure_memory($label, $output_now = false) |
|
638 | - { |
|
639 | - Benchmark::measureMemory($label, $output_now); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @deprecated 4.9.39.rc.034 |
|
646 | - * @param int $size |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function convert($size) |
|
650 | - { |
|
651 | - return Benchmark::convert($size); |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @deprecated 4.9.39.rc.034 |
|
658 | - * @param bool $output_now |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function show_times($output_now = true) |
|
662 | - { |
|
663 | - return Benchmark::displayResults($output_now); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * @deprecated 4.9.39.rc.034 |
|
670 | - * @param string $timer_name |
|
671 | - * @param float $total_time |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function format_time($timer_name, $total_time) |
|
675 | - { |
|
676 | - return Benchmark::formatTime($timer_name, $total_time); |
|
677 | - } |
|
14 | + /** |
|
15 | + * instance of the EEH_Autoloader object |
|
16 | + * |
|
17 | + * @var $_instance |
|
18 | + * @access private |
|
19 | + */ |
|
20 | + private static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $_memory_usage_points = array(); |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @singleton method used to instantiate class object |
|
31 | + * @access public |
|
32 | + * @return EEH_Debug_Tools |
|
33 | + */ |
|
34 | + public static function instance() |
|
35 | + { |
|
36 | + // check if class object is instantiated, and instantiated properly |
|
37 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | + self::$_instance = new self(); |
|
39 | + } |
|
40 | + return self::$_instance; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * private class constructor |
|
47 | + */ |
|
48 | + private function __construct() |
|
49 | + { |
|
50 | + // load Kint PHP debugging library |
|
51 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
52 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
53 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
54 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
55 | + // so we've moved it to our test folder so that it is not included with production releases |
|
56 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
57 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
58 | + } |
|
59 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
60 | + // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
61 | + // } |
|
62 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
63 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
64 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
65 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * show_db_name |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function show_db_name() |
|
76 | + { |
|
77 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
79 | + . DB_NAME |
|
80 | + . '</p>'; |
|
81 | + } |
|
82 | + if (EE_DEBUG) { |
|
83 | + Benchmark::displayResults(); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * dump EE_Session object at bottom of page after everything else has happened |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function espresso_session_footer_dump() |
|
95 | + { |
|
96 | + if ((defined('WP_DEBUG') && WP_DEBUG) |
|
97 | + && ! defined('DOING_AJAX') |
|
98 | + && class_exists('Kint') |
|
99 | + && function_exists('wp_get_current_user') |
|
100 | + && current_user_can('update_core') |
|
101 | + && class_exists('EE_Registry') |
|
102 | + ) { |
|
103 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
104 | + Kint::dump(EE_Registry::instance()->SSN); |
|
105 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
106 | + $this->espresso_list_hooked_functions(); |
|
107 | + Benchmark::displayResults(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * List All Hooked Functions |
|
115 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
116 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
117 | + * |
|
118 | + * @param string $tag |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + public function espresso_list_hooked_functions($tag = '') |
|
122 | + { |
|
123 | + global $wp_filter; |
|
124 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
125 | + if ($tag) { |
|
126 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | + if (! is_array($hook[ $tag ])) { |
|
128 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
129 | + return; |
|
130 | + } |
|
131 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
132 | + } else { |
|
133 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
134 | + ksort($hook); |
|
135 | + } |
|
136 | + foreach ($hook as $tag_name => $priorities) { |
|
137 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
138 | + ksort($priorities); |
|
139 | + foreach ($priorities as $priority => $function) { |
|
140 | + echo $priority; |
|
141 | + foreach ($function as $name => $properties) { |
|
142 | + echo "\t$name<br />"; |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * registered_filter_callbacks |
|
152 | + * |
|
153 | + * @param string $hook_name |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public static function registered_filter_callbacks($hook_name = '') |
|
157 | + { |
|
158 | + $filters = array(); |
|
159 | + global $wp_filter; |
|
160 | + if (isset($wp_filter[ $hook_name ])) { |
|
161 | + $filters[ $hook_name ] = array(); |
|
162 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | + $filters[ $hook_name ][ $priority ] = array(); |
|
164 | + foreach ($callbacks as $callback) { |
|
165 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + return $filters; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * captures plugin activation errors for debugging |
|
176 | + * |
|
177 | + * @return void |
|
178 | + * @throws EE_Error |
|
179 | + */ |
|
180 | + public static function ee_plugin_activation_errors() |
|
181 | + { |
|
182 | + if (WP_DEBUG) { |
|
183 | + $activation_errors = ob_get_contents(); |
|
184 | + if (! empty($activation_errors)) { |
|
185 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
186 | + } |
|
187 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
188 | + if (class_exists('EEH_File')) { |
|
189 | + try { |
|
190 | + EEH_File::ensure_file_exists_and_is_writable( |
|
191 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
192 | + ); |
|
193 | + EEH_File::write_to_file( |
|
194 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
195 | + $activation_errors |
|
196 | + ); |
|
197 | + } catch (EE_Error $e) { |
|
198 | + EE_Error::add_error( |
|
199 | + sprintf( |
|
200 | + __( |
|
201 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
202 | + 'event_espresso' |
|
203 | + ), |
|
204 | + $e->getMessage() |
|
205 | + ), |
|
206 | + __FILE__, |
|
207 | + __FUNCTION__, |
|
208 | + __LINE__ |
|
209 | + ); |
|
210 | + } |
|
211 | + } else { |
|
212 | + // old school attempt |
|
213 | + file_put_contents( |
|
214 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
215 | + $activation_errors |
|
216 | + ); |
|
217 | + } |
|
218 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
219 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
227 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
228 | + * or we want to make sure they use something the right way. |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @param string $function The function that was called |
|
232 | + * @param string $message A message explaining what has been done incorrectly |
|
233 | + * @param string $version The version of Event Espresso where the error was added |
|
234 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
235 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
236 | + * but not have any notices appear until a later version. This allows developers |
|
237 | + * extra time to update their code before notices appear. |
|
238 | + * @param int $error_type |
|
239 | + * @uses trigger_error() |
|
240 | + */ |
|
241 | + public function doing_it_wrong( |
|
242 | + $function, |
|
243 | + $message, |
|
244 | + $version, |
|
245 | + $applies_when = '', |
|
246 | + $error_type = null |
|
247 | + ) { |
|
248 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
249 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
250 | + // because we swapped the parameter order around for the last two params, |
|
251 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
252 | + if (is_int($applies_when)) { |
|
253 | + $error_type = $applies_when; |
|
254 | + $applies_when = espresso_version(); |
|
255 | + } |
|
256 | + // if not displaying notices yet, then just leave |
|
257 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
258 | + return; |
|
259 | + } |
|
260 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
261 | + $version = $version === null |
|
262 | + ? '' |
|
263 | + : sprintf( |
|
264 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
265 | + $version |
|
266 | + ); |
|
267 | + $error_message = sprintf( |
|
268 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
269 | + $function, |
|
270 | + '<strong>', |
|
271 | + '</strong>', |
|
272 | + $message, |
|
273 | + $version |
|
274 | + ); |
|
275 | + // don't trigger error if doing ajax, |
|
276 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
277 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
278 | + $error_message .= ' ' . esc_html__( |
|
279 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
280 | + 'event_espresso' |
|
281 | + ); |
|
282 | + $error_message .= '<ul><li>'; |
|
283 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
284 | + $error_message .= '</ul>'; |
|
285 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
286 | + // now we set this on the transient so it shows up on the next request. |
|
287 | + EE_Error::get_notices(false, true); |
|
288 | + } else { |
|
289 | + trigger_error($error_message, $error_type); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Logger helpers |
|
298 | + */ |
|
299 | + /** |
|
300 | + * debug |
|
301 | + * |
|
302 | + * @param string $class |
|
303 | + * @param string $func |
|
304 | + * @param string $line |
|
305 | + * @param array $info |
|
306 | + * @param bool $display_request |
|
307 | + * @param string $debug_index |
|
308 | + * @param string $debug_key |
|
309 | + * @throws EE_Error |
|
310 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
311 | + */ |
|
312 | + public static function log( |
|
313 | + $class = '', |
|
314 | + $func = '', |
|
315 | + $line = '', |
|
316 | + $info = array(), |
|
317 | + $display_request = false, |
|
318 | + $debug_index = '', |
|
319 | + $debug_key = 'EE_DEBUG_SPCO' |
|
320 | + ) { |
|
321 | + if (WP_DEBUG) { |
|
322 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
323 | + $debug_data = get_option($debug_key, array()); |
|
324 | + $default_data = array( |
|
325 | + $class => $func . '() : ' . $line, |
|
326 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
327 | + ); |
|
328 | + // don't serialize objects |
|
329 | + $info = self::strip_objects($info); |
|
330 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
331 | + if (! isset($debug_data[ $index ])) { |
|
332 | + $debug_data[ $index ] = array(); |
|
333 | + } |
|
334 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
335 | + update_option($debug_key, $debug_data); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * strip_objects |
|
343 | + * |
|
344 | + * @param array $info |
|
345 | + * @return array |
|
346 | + */ |
|
347 | + public static function strip_objects($info = array()) |
|
348 | + { |
|
349 | + foreach ($info as $key => $value) { |
|
350 | + if (is_array($value)) { |
|
351 | + $info[ $key ] = self::strip_objects($value); |
|
352 | + } elseif (is_object($value)) { |
|
353 | + $object_class = get_class($value); |
|
354 | + $info[ $object_class ] = array(); |
|
355 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | + if (method_exists($value, 'ID')) { |
|
357 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
358 | + } |
|
359 | + if (method_exists($value, 'status')) { |
|
360 | + $info[ $object_class ]['status'] = $value->status(); |
|
361 | + } elseif (method_exists($value, 'status_ID')) { |
|
362 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
363 | + } |
|
364 | + unset($info[ $key ]); |
|
365 | + } |
|
366 | + } |
|
367 | + return (array) $info; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @param mixed $var |
|
374 | + * @param string $var_name |
|
375 | + * @param string $file |
|
376 | + * @param int|string $line |
|
377 | + * @param int|string $heading_tag |
|
378 | + * @param bool $die |
|
379 | + * @param string $margin |
|
380 | + */ |
|
381 | + public static function printv( |
|
382 | + $var, |
|
383 | + $var_name = '', |
|
384 | + $file = '', |
|
385 | + $line = '', |
|
386 | + $heading_tag = 5, |
|
387 | + $die = false, |
|
388 | + $margin = '' |
|
389 | + ) { |
|
390 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
391 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
392 | + $is_method = method_exists($var_name, $var); |
|
393 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
394 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
395 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
396 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
397 | + $result .= $is_method |
|
398 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
400 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
401 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
402 | + if ($die) { |
|
403 | + die($result); |
|
404 | + } |
|
405 | + echo $result; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + protected static function headingTag($heading_tag) |
|
410 | + { |
|
411 | + $heading_tag = absint($heading_tag); |
|
412 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + protected static function headingSpacer($heading_tag) |
|
417 | + { |
|
418 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
419 | + ? "\n" |
|
420 | + : ''; |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + protected static function plainOutput() |
|
425 | + { |
|
426 | + return defined('EE_TESTS_DIR') |
|
427 | + || (defined('DOING_AJAX') && DOING_AJAX) |
|
428 | + || ( |
|
429 | + isset($_SERVER['REQUEST_URI']) |
|
430 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
431 | + ); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $var_name |
|
437 | + * @param string $heading_tag |
|
438 | + * @param string $margin |
|
439 | + * @param int $line |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | + { |
|
444 | + if (EEH_Debug_Tools::plainOutput()) { |
|
445 | + $heading = ''; |
|
446 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | + $heading .= "\n"; |
|
448 | + } |
|
449 | + $heading .= "\n{$line}) {$var_name}"; |
|
450 | + return $heading; |
|
451 | + } |
|
452 | + $margin = "25px 0 0 {$margin}"; |
|
453 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $heading_tag |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + protected static function headingX($heading_tag = 'h5') |
|
463 | + { |
|
464 | + if (EEH_Debug_Tools::plainOutput()) { |
|
465 | + return ''; |
|
466 | + } |
|
467 | + return '</' . $heading_tag . '>'; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $content |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + protected static function grey_span($content = '') |
|
477 | + { |
|
478 | + if (EEH_Debug_Tools::plainOutput()) { |
|
479 | + return $content; |
|
480 | + } |
|
481 | + return '<span style="color:#999">' . $content . '</span>'; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $file |
|
488 | + * @param int $line |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + protected static function file_and_line($file, $line, $heading_tag) |
|
492 | + { |
|
493 | + if ($file === '' || $line === '') { |
|
494 | + return ''; |
|
495 | + } |
|
496 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | + if (EEH_Debug_Tools::plainOutput()) { |
|
498 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | + return " ({$file})"; |
|
500 | + } |
|
501 | + return ''; |
|
502 | + } |
|
503 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | + . $file |
|
505 | + . '<br />line no: ' |
|
506 | + . $line |
|
507 | + . '</span>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param string $content |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + protected static function orange_span($content = '') |
|
517 | + { |
|
518 | + if (EEH_Debug_Tools::plainOutput()) { |
|
519 | + return $content; |
|
520 | + } |
|
521 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param mixed $var |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + protected static function pre_span($var) |
|
531 | + { |
|
532 | + ob_start(); |
|
533 | + var_dump($var); |
|
534 | + $var = ob_get_clean(); |
|
535 | + if (EEH_Debug_Tools::plainOutput()) { |
|
536 | + return $var; |
|
537 | + } |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @param mixed $var |
|
545 | + * @param string $var_name |
|
546 | + * @param string $file |
|
547 | + * @param int|string $line |
|
548 | + * @param int|string $heading_tag |
|
549 | + * @param bool $die |
|
550 | + */ |
|
551 | + public static function printr( |
|
552 | + $var, |
|
553 | + $var_name = '', |
|
554 | + $file = '', |
|
555 | + $line = '', |
|
556 | + $heading_tag = 5, |
|
557 | + $die = false |
|
558 | + ) { |
|
559 | + // return; |
|
560 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | + $margin = is_admin() ? ' 180px' : '0'; |
|
562 | + // $print_r = false; |
|
563 | + if (is_string($var)) { |
|
564 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | + return; |
|
566 | + } |
|
567 | + if (is_object($var)) { |
|
568 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | + // $print_r = true; |
|
570 | + } elseif (is_array($var)) { |
|
571 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | + // $print_r = true; |
|
573 | + } elseif (is_numeric($var)) { |
|
574 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | + } elseif ($var === null) { |
|
576 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | + } |
|
578 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | + EEH_Debug_Tools::pre_span($var) |
|
584 | + ); |
|
585 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | + if ($die) { |
|
588 | + die($result); |
|
589 | + } |
|
590 | + echo $result; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /******************** deprecated ********************/ |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + */ |
|
602 | + public function reset_times() |
|
603 | + { |
|
604 | + Benchmark::resetTimes(); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @deprecated 4.9.39.rc.034 |
|
611 | + * @param null $timer_name |
|
612 | + */ |
|
613 | + public function start_timer($timer_name = null) |
|
614 | + { |
|
615 | + Benchmark::startTimer($timer_name); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @deprecated 4.9.39.rc.034 |
|
622 | + * @param string $timer_name |
|
623 | + */ |
|
624 | + public function stop_timer($timer_name = '') |
|
625 | + { |
|
626 | + Benchmark::stopTimer($timer_name); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * @deprecated 4.9.39.rc.034 |
|
633 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + public function measure_memory($label, $output_now = false) |
|
638 | + { |
|
639 | + Benchmark::measureMemory($label, $output_now); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @deprecated 4.9.39.rc.034 |
|
646 | + * @param int $size |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function convert($size) |
|
650 | + { |
|
651 | + return Benchmark::convert($size); |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @deprecated 4.9.39.rc.034 |
|
658 | + * @param bool $output_now |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function show_times($output_now = true) |
|
662 | + { |
|
663 | + return Benchmark::displayResults($output_now); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * @deprecated 4.9.39.rc.034 |
|
670 | + * @param string $timer_name |
|
671 | + * @param float $total_time |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function format_time($timer_name, $total_time) |
|
675 | + { |
|
676 | + return Benchmark::formatTime($timer_name, $total_time); |
|
677 | + } |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | |
@@ -684,31 +684,31 @@ discard block |
||
684 | 684 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
685 | 685 | */ |
686 | 686 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
687 | - function dump_wp_query() |
|
688 | - { |
|
689 | - global $wp_query; |
|
690 | - d($wp_query); |
|
691 | - } |
|
687 | + function dump_wp_query() |
|
688 | + { |
|
689 | + global $wp_query; |
|
690 | + d($wp_query); |
|
691 | + } |
|
692 | 692 | } |
693 | 693 | /** |
694 | 694 | * borrowed from Kint Debugger |
695 | 695 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
696 | 696 | */ |
697 | 697 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
698 | - function dump_wp() |
|
699 | - { |
|
700 | - global $wp; |
|
701 | - d($wp); |
|
702 | - } |
|
698 | + function dump_wp() |
|
699 | + { |
|
700 | + global $wp; |
|
701 | + d($wp); |
|
702 | + } |
|
703 | 703 | } |
704 | 704 | /** |
705 | 705 | * borrowed from Kint Debugger |
706 | 706 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
707 | 707 | */ |
708 | 708 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
709 | - function dump_post() |
|
710 | - { |
|
711 | - global $post; |
|
712 | - d($post); |
|
713 | - } |
|
709 | + function dump_post() |
|
710 | + { |
|
711 | + global $post; |
|
712 | + d($post); |
|
713 | + } |
|
714 | 714 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public static function instance() |
35 | 35 | { |
36 | 36 | // check if class object is instantiated, and instantiated properly |
37 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
37 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
38 | 38 | self::$_instance = new self(); |
39 | 39 | } |
40 | 40 | return self::$_instance; |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | private function __construct() |
49 | 49 | { |
50 | 50 | // load Kint PHP debugging library |
51 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) { |
|
51 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) { |
|
52 | 52 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
53 | 53 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
54 | 54 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
55 | 55 | // so we've moved it to our test folder so that it is not included with production releases |
56 | 56 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
57 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
57 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
58 | 58 | } |
59 | 59 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
60 | 60 | // add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public static function show_db_name() |
76 | 76 | { |
77 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
77 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
78 | 78 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
79 | 79 | . DB_NAME |
80 | 80 | . '</p>'; |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | global $wp_filter; |
124 | 124 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
125 | 125 | if ($tag) { |
126 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
127 | - if (! is_array($hook[ $tag ])) { |
|
126 | + $hook[$tag] = $wp_filter[$tag]; |
|
127 | + if ( ! is_array($hook[$tag])) { |
|
128 | 128 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
129 | 129 | return; |
130 | 130 | } |
131 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
131 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
132 | 132 | } else { |
133 | 133 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
134 | 134 | ksort($hook); |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | { |
158 | 158 | $filters = array(); |
159 | 159 | global $wp_filter; |
160 | - if (isset($wp_filter[ $hook_name ])) { |
|
161 | - $filters[ $hook_name ] = array(); |
|
162 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
163 | - $filters[ $hook_name ][ $priority ] = array(); |
|
160 | + if (isset($wp_filter[$hook_name])) { |
|
161 | + $filters[$hook_name] = array(); |
|
162 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
163 | + $filters[$hook_name][$priority] = array(); |
|
164 | 164 | foreach ($callbacks as $callback) { |
165 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
165 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | { |
182 | 182 | if (WP_DEBUG) { |
183 | 183 | $activation_errors = ob_get_contents(); |
184 | - if (! empty($activation_errors)) { |
|
185 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
184 | + if ( ! empty($activation_errors)) { |
|
185 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
186 | 186 | } |
187 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
187 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
188 | 188 | if (class_exists('EEH_File')) { |
189 | 189 | try { |
190 | 190 | EEH_File::ensure_file_exists_and_is_writable( |
191 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
191 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
192 | 192 | ); |
193 | 193 | EEH_File::write_to_file( |
194 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
194 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
195 | 195 | $activation_errors |
196 | 196 | ); |
197 | 197 | } catch (EE_Error $e) { |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | } else { |
212 | 212 | // old school attempt |
213 | 213 | file_put_contents( |
214 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
214 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
215 | 215 | $activation_errors |
216 | 216 | ); |
217 | 217 | } |
218 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
218 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
219 | 219 | update_option('ee_plugin_activation_errors', $activation_errors); |
220 | 220 | } |
221 | 221 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | // don't trigger error if doing ajax, |
276 | 276 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
277 | 277 | if (defined('DOING_AJAX') && DOING_AJAX) { |
278 | - $error_message .= ' ' . esc_html__( |
|
278 | + $error_message .= ' '.esc_html__( |
|
279 | 279 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
280 | 280 | 'event_espresso' |
281 | 281 | ); |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | $debug_key = 'EE_DEBUG_SPCO' |
320 | 320 | ) { |
321 | 321 | if (WP_DEBUG) { |
322 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
322 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
323 | 323 | $debug_data = get_option($debug_key, array()); |
324 | 324 | $default_data = array( |
325 | - $class => $func . '() : ' . $line, |
|
325 | + $class => $func.'() : '.$line, |
|
326 | 326 | 'REQ' => $display_request ? $_REQUEST : '', |
327 | 327 | ); |
328 | 328 | // don't serialize objects |
329 | 329 | $info = self::strip_objects($info); |
330 | 330 | $index = ! empty($debug_index) ? $debug_index : 0; |
331 | - if (! isset($debug_data[ $index ])) { |
|
332 | - $debug_data[ $index ] = array(); |
|
331 | + if ( ! isset($debug_data[$index])) { |
|
332 | + $debug_data[$index] = array(); |
|
333 | 333 | } |
334 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
334 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
335 | 335 | update_option($debug_key, $debug_data); |
336 | 336 | } |
337 | 337 | } |
@@ -348,20 +348,20 @@ discard block |
||
348 | 348 | { |
349 | 349 | foreach ($info as $key => $value) { |
350 | 350 | if (is_array($value)) { |
351 | - $info[ $key ] = self::strip_objects($value); |
|
351 | + $info[$key] = self::strip_objects($value); |
|
352 | 352 | } elseif (is_object($value)) { |
353 | 353 | $object_class = get_class($value); |
354 | - $info[ $object_class ] = array(); |
|
355 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
354 | + $info[$object_class] = array(); |
|
355 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
356 | 356 | if (method_exists($value, 'ID')) { |
357 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
357 | + $info[$object_class]['ID'] = $value->ID(); |
|
358 | 358 | } |
359 | 359 | if (method_exists($value, 'status')) { |
360 | - $info[ $object_class ]['status'] = $value->status(); |
|
360 | + $info[$object_class]['status'] = $value->status(); |
|
361 | 361 | } elseif (method_exists($value, 'status_ID')) { |
362 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
362 | + $info[$object_class]['status'] = $value->status_ID(); |
|
363 | 363 | } |
364 | - unset($info[ $key ]); |
|
364 | + unset($info[$key]); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | return (array) $info; |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
396 | 396 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
397 | 397 | $result .= $is_method |
398 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
399 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
398 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
399 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
400 | 400 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
401 | 401 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
402 | 402 | if ($die) { |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | return $heading; |
451 | 451 | } |
452 | 452 | $margin = "25px 0 0 {$margin}"; |
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
453 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | if (EEH_Debug_Tools::plainOutput()) { |
465 | 465 | return ''; |
466 | 466 | } |
467 | - return '</' . $heading_tag . '>'; |
|
467 | + return '</'.$heading_tag.'>'; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | if (EEH_Debug_Tools::plainOutput()) { |
479 | 479 | return $content; |
480 | 480 | } |
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
481 | + return '<span style="color:#999">'.$content.'</span>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | if (EEH_Debug_Tools::plainOutput()) { |
519 | 519 | return $content; |
520 | 520 | } |
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
521 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | if (EEH_Debug_Tools::plainOutput()) { |
536 | 536 | return $var; |
537 | 537 | } |
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
580 | 580 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
581 | 581 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
583 | 583 | EEH_Debug_Tools::pre_span($var) |
584 | 584 | ); |
585 | 585 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -5,35 +5,35 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
6 | 6 | |
7 | 7 | if (! function_exists('espresso_get_template_part')) { |
8 | - /** |
|
9 | - * espresso_get_template_part |
|
10 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
11 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
12 | - * |
|
13 | - * @param string $slug The slug name for the generic template. |
|
14 | - * @param string $name The name of the specialised template. |
|
15 | - * @return string the html output for the formatted money value |
|
16 | - */ |
|
17 | - function espresso_get_template_part($slug = null, $name = null) |
|
18 | - { |
|
19 | - EEH_Template::get_template_part($slug, $name); |
|
20 | - } |
|
8 | + /** |
|
9 | + * espresso_get_template_part |
|
10 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
11 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
12 | + * |
|
13 | + * @param string $slug The slug name for the generic template. |
|
14 | + * @param string $name The name of the specialised template. |
|
15 | + * @return string the html output for the formatted money value |
|
16 | + */ |
|
17 | + function espresso_get_template_part($slug = null, $name = null) |
|
18 | + { |
|
19 | + EEH_Template::get_template_part($slug, $name); |
|
20 | + } |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | 24 | if (! function_exists('espresso_get_object_css_class')) { |
25 | - /** |
|
26 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
27 | - * |
|
28 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
29 | - * @param string $prefix added to the beginning of the generated class |
|
30 | - * @param string $suffix added to the end of the generated class |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
34 | - { |
|
35 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
36 | - } |
|
25 | + /** |
|
26 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
27 | + * |
|
28 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
29 | + * @param string $prefix added to the beginning of the generated class |
|
30 | + * @param string $suffix added to the end of the generated class |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
34 | + { |
|
35 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -48,672 +48,672 @@ discard block |
||
48 | 48 | class EEH_Template |
49 | 49 | { |
50 | 50 | |
51 | - private static $_espresso_themes = array(); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
56 | - * |
|
57 | - * @return boolean |
|
58 | - */ |
|
59 | - public static function is_espresso_theme() |
|
60 | - { |
|
61 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
66 | - * load it's functions.php file ( if not already loaded ) |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public static function load_espresso_theme_functions() |
|
71 | - { |
|
72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public static function get_espresso_themes() |
|
86 | - { |
|
87 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
89 | - if (empty($espresso_themes)) { |
|
90 | - return array(); |
|
91 | - } |
|
92 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
93 | - unset($espresso_themes[ $key ]); |
|
94 | - } |
|
95 | - EEH_Template::$_espresso_themes = array(); |
|
96 | - foreach ($espresso_themes as $espresso_theme) { |
|
97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
98 | - } |
|
99 | - } |
|
100 | - return EEH_Template::$_espresso_themes; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * EEH_Template::get_template_part |
|
106 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
107 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
108 | - * filtering based off of the entire template part name |
|
109 | - * |
|
110 | - * @param string $slug The slug name for the generic template. |
|
111 | - * @param string $name The name of the specialised template. |
|
112 | - * @param array $template_args |
|
113 | - * @param bool $return_string |
|
114 | - * @return string the html output for the formatted money value |
|
115 | - */ |
|
116 | - public static function get_template_part( |
|
117 | - $slug = null, |
|
118 | - $name = null, |
|
119 | - $template_args = array(), |
|
120 | - $return_string = false |
|
121 | - ) { |
|
122 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
123 | - $templates = array(); |
|
124 | - $name = (string) $name; |
|
125 | - if ($name != '') { |
|
126 | - $templates[] = "{$slug}-{$name}.php"; |
|
127 | - } |
|
128 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
129 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
130 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * locate_template |
|
137 | - * locate a template file by looking in the following places, in the following order: |
|
138 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
139 | - * <assumed full absolute server path> |
|
140 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
141 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
142 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
143 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
144 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
145 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
146 | - * Example: |
|
147 | - * You are using the WordPress Twenty Sixteen theme, |
|
148 | - * and you want to customize the "some-event.template.php" template, |
|
149 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
150 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
151 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
152 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
153 | - * /relative/path/to/some-event.template.php |
|
154 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
155 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
156 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
157 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
158 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
159 | - * Had you passed an absolute path to your template that was in some other location, |
|
160 | - * ie: "/absolute/path/to/some-event.template.php" |
|
161 | - * then the search would have been : |
|
162 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
163 | - * /absolute/path/to/some-event.template.php |
|
164 | - * and stopped there upon finding it in the second location |
|
165 | - * |
|
166 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
167 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
168 | - * @param boolean $load whether to pass the located template path on to the |
|
169 | - * EEH_Template::display_template() method or simply return it |
|
170 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
171 | - * string |
|
172 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
173 | - * generate a custom template or not. Used in places where you don't actually |
|
174 | - * load the template, you just want to know if there's a custom version of it. |
|
175 | - * @return mixed |
|
176 | - * @throws DomainException |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - */ |
|
181 | - public static function locate_template( |
|
182 | - $templates = array(), |
|
183 | - $template_args = array(), |
|
184 | - $load = true, |
|
185 | - $return_string = true, |
|
186 | - $check_if_custom = false |
|
187 | - ) { |
|
188 | - // first use WP locate_template to check for template in the current theme folder |
|
189 | - $template_path = locate_template($templates); |
|
190 | - |
|
191 | - if ($check_if_custom && ! empty($template_path)) { |
|
192 | - return true; |
|
193 | - } |
|
194 | - |
|
195 | - // not in the theme |
|
196 | - if (empty($template_path)) { |
|
197 | - // not even a template to look for ? |
|
198 | - if (empty($templates)) { |
|
199 | - // get post_type |
|
200 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
201 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
202 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
203 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
204 | - ); |
|
205 | - // get array of EE Custom Post Types |
|
206 | - $EE_CPTs = $custom_post_types->getDefinitions(); |
|
207 | - // build template name based on request |
|
208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
209 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
210 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
212 | - } |
|
213 | - } |
|
214 | - // currently active EE template theme |
|
215 | - $current_theme = EE_Config::get_current_theme(); |
|
216 | - |
|
217 | - // array of paths to folders that may contain templates |
|
218 | - $template_folder_paths = array( |
|
219 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
221 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
222 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
223 | - ); |
|
224 | - |
|
225 | - // add core plugin folders for checking only if we're not $check_if_custom |
|
226 | - if (! $check_if_custom) { |
|
227 | - $core_paths = array( |
|
228 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
229 | - EE_PUBLIC . $current_theme, |
|
230 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
231 | - EE_TEMPLATES . $current_theme, |
|
232 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
233 | - EE_PLUGIN_DIR_PATH, |
|
234 | - ); |
|
235 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
236 | - } |
|
237 | - |
|
238 | - // now filter that array |
|
239 | - $template_folder_paths = apply_filters( |
|
240 | - 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
241 | - $template_folder_paths |
|
242 | - ); |
|
243 | - $templates = is_array($templates) ? $templates : array($templates); |
|
244 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
245 | - // array to hold all possible template paths |
|
246 | - $full_template_paths = array(); |
|
247 | - |
|
248 | - // loop through $templates |
|
249 | - foreach ($templates as $template) { |
|
250 | - // normalize directory separators |
|
251 | - $template = EEH_File::standardise_directory_separators($template); |
|
252 | - $file_name = basename($template); |
|
253 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
254 | - // while looping through all template folder paths |
|
255 | - foreach ($template_folder_paths as $template_folder_path) { |
|
256 | - // normalize directory separators |
|
257 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
258 | - // determine if any common base path exists between the two paths |
|
259 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
260 | - array($template_folder_path, $template_path_minus_file_name) |
|
261 | - ); |
|
262 | - if ($common_base_path !== '') { |
|
263 | - // both paths have a common base, so just tack the filename onto our search path |
|
264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | - } else { |
|
266 | - // no common base path, so let's just concatenate |
|
267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | - } |
|
269 | - // build up our template locations array by adding our resolved paths |
|
270 | - $full_template_paths[] = $resolved_path; |
|
271 | - } |
|
272 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
273 | - array_unshift($full_template_paths, $template); |
|
274 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
276 | - } |
|
277 | - // filter final array of full template paths |
|
278 | - $full_template_paths = apply_filters( |
|
279 | - 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | - $full_template_paths, |
|
281 | - $file_name |
|
282 | - ); |
|
283 | - // now loop through our final array of template location paths and check each location |
|
284 | - foreach ((array) $full_template_paths as $full_template_path) { |
|
285 | - if (is_readable($full_template_path)) { |
|
286 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
287 | - break; |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - // hook that can be used to display the full template path that will be used |
|
293 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
294 | - |
|
295 | - // if we got it and you want to see it... |
|
296 | - if ($template_path && $load && ! $check_if_custom) { |
|
297 | - if ($return_string) { |
|
298 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
299 | - } else { |
|
300 | - EEH_Template::display_template($template_path, $template_args, false); |
|
301 | - } |
|
302 | - } |
|
303 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * _find_common_base_path |
|
309 | - * given two paths, this determines if there is a common base path between the two |
|
310 | - * |
|
311 | - * @param array $paths |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - protected static function _find_common_base_path($paths) |
|
315 | - { |
|
316 | - $last_offset = 0; |
|
317 | - $common_base_path = ''; |
|
318 | - while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
319 | - $dir_length = $index - $last_offset + 1; |
|
320 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
321 | - foreach ($paths as $path) { |
|
322 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
323 | - return $common_base_path; |
|
324 | - } |
|
325 | - } |
|
326 | - $common_base_path .= $directory; |
|
327 | - $last_offset = $index + 1; |
|
328 | - } |
|
329 | - return substr($common_base_path, 0, -1); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * load and display a template |
|
335 | - * |
|
336 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
337 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
338 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
339 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
340 | - * not found or is not readable |
|
341 | - * @return mixed string |
|
342 | - * @throws \DomainException |
|
343 | - */ |
|
344 | - public static function display_template( |
|
345 | - $template_path = false, |
|
346 | - $template_args = array(), |
|
347 | - $return_string = false, |
|
348 | - $throw_exceptions = false |
|
349 | - ) { |
|
350 | - |
|
351 | - /** |
|
352 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
353 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
354 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
355 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
356 | - * using this. |
|
357 | - * |
|
358 | - * @since 4.6.0 |
|
359 | - */ |
|
360 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
361 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
362 | - |
|
363 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
364 | - if (! $template_path || ! is_readable($template_path)) { |
|
365 | - return ''; |
|
366 | - } |
|
367 | - // if $template_args are not in an array, then make it so |
|
368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
369 | - $template_args = array($template_args); |
|
370 | - } |
|
371 | - extract($template_args, EXTR_SKIP); |
|
372 | - // ignore whether template is accessible ? |
|
373 | - if ($throw_exceptions && ! is_readable($template_path)) { |
|
374 | - throw new \DomainException( |
|
375 | - esc_html__( |
|
376 | - 'Invalid, unreadable, or missing file.', |
|
377 | - 'event_espresso' |
|
378 | - ) |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - if ($return_string) { |
|
384 | - // because we want to return a string, we are going to capture the output |
|
385 | - ob_start(); |
|
386 | - include($template_path); |
|
387 | - return ob_get_clean(); |
|
388 | - } else { |
|
389 | - include($template_path); |
|
390 | - } |
|
391 | - return ''; |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
397 | - * |
|
398 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
399 | - * @param string $prefix added to the beginning of the generated class |
|
400 | - * @param string $suffix added to the end of the generated class |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
404 | - { |
|
405 | - // in the beginning... |
|
406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
407 | - // da muddle |
|
408 | - $class = ''; |
|
409 | - // the end |
|
410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
411 | - // is the passed object an EE object ? |
|
412 | - if ($object instanceof EE_Base_Class) { |
|
413 | - // grab the exact type of object |
|
414 | - $obj_class = get_class($object); |
|
415 | - // depending on the type of object... |
|
416 | - switch ($obj_class) { |
|
417 | - // no specifics just yet... |
|
418 | - default: |
|
419 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
421 | - } |
|
422 | - } |
|
423 | - return $prefix . $class . $suffix; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * EEH_Template::format_currency |
|
430 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
431 | - * the country currency settings from the supplied country ISO code |
|
432 | - * |
|
433 | - * @param float $amount raw money value |
|
434 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
435 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
436 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
437 | - * @param string $cur_code_span_class |
|
438 | - * @return string the html output for the formatted money value |
|
439 | - * @throws \EE_Error |
|
440 | - */ |
|
441 | - public static function format_currency( |
|
442 | - $amount = null, |
|
443 | - $return_raw = false, |
|
444 | - $display_code = true, |
|
445 | - $CNT_ISO = '', |
|
446 | - $cur_code_span_class = 'currency-code' |
|
447 | - ) { |
|
448 | - // ensure amount was received |
|
449 | - if ($amount === null) { |
|
450 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
451 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
452 | - return ''; |
|
453 | - } |
|
454 | - // ensure amount is float |
|
455 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
456 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
457 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
458 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
459 | - // still a number or was amount converted to a string like "free" ? |
|
460 | - if (is_float($amount_formatted)) { |
|
461 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
462 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
463 | - // verify results |
|
464 | - if (! $mny instanceof EE_Currency_Config) { |
|
465 | - // set default config country currency settings |
|
466 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
467 | - ? EE_Registry::instance()->CFG->currency |
|
468 | - : new EE_Currency_Config(); |
|
469 | - } |
|
470 | - // format float |
|
471 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
472 | - // add formatting ? |
|
473 | - if (! $return_raw) { |
|
474 | - // add currency sign |
|
475 | - if ($mny->sign_b4) { |
|
476 | - if ($amount >= 0) { |
|
477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
478 | - } else { |
|
479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
480 | - } |
|
481 | - } else { |
|
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | - } |
|
484 | - |
|
485 | - // filter to allow global setting of display_code |
|
486 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | - |
|
488 | - // add currency code ? |
|
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | - } |
|
491 | - // filter results |
|
492 | - $amount_formatted = apply_filters( |
|
493 | - 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
494 | - $amount_formatted, |
|
495 | - $mny, |
|
496 | - $return_raw |
|
497 | - ); |
|
498 | - } |
|
499 | - // clean up vars |
|
500 | - unset($mny); |
|
501 | - // return formatted currency amount |
|
502 | - return $amount_formatted; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
508 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
509 | - * related status model or model object (i.e. in documentation etc.) |
|
510 | - * |
|
511 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
512 | - * match, then 'Unknown' will be returned. |
|
513 | - * @param boolean $plural Whether to return plural or not |
|
514 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
515 | - * @return string The localized label for the status id. |
|
516 | - */ |
|
517 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
518 | - { |
|
519 | - /** @type EEM_Status $EEM_Status */ |
|
520 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
521 | - $status = $EEM_Status->localized_status( |
|
522 | - array($status_id => __('unknown', 'event_espresso')), |
|
523 | - $plural, |
|
524 | - $schema |
|
525 | - ); |
|
526 | - return $status[ $status_id ]; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * This helper just returns a button or link for the given parameters |
|
532 | - * |
|
533 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
534 | - * @param string $label What is the label you want displayed for the button |
|
535 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
536 | - * @param string $icon |
|
537 | - * @param string $title |
|
538 | - * @return string the html output for the button |
|
539 | - */ |
|
540 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
541 | - { |
|
542 | - $icon_html = ''; |
|
543 | - if (! empty($icon)) { |
|
544 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
545 | - $dashicons = array_filter($dashicons); |
|
546 | - $count = count($dashicons); |
|
547 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
548 | - foreach ($dashicons as $dashicon) { |
|
549 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
551 | - } |
|
552 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
553 | - } |
|
554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
556 | - return $button; |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * This returns a generated link that will load the related help tab on admin pages. |
|
562 | - * |
|
563 | - * @param string $help_tab_id the id for the connected help tab |
|
564 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
565 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
566 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
567 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
568 | - * @return string generated link |
|
569 | - */ |
|
570 | - public static function get_help_tab_link( |
|
571 | - $help_tab_id, |
|
572 | - $page = false, |
|
573 | - $action = false, |
|
574 | - $icon_style = false, |
|
575 | - $help_text = false |
|
576 | - ) { |
|
577 | - |
|
578 | - if (! $page) { |
|
579 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
580 | - } |
|
581 | - |
|
582 | - if (! $action) { |
|
583 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
584 | - } |
|
585 | - |
|
586 | - $action = empty($action) ? 'default' : $action; |
|
587 | - |
|
588 | - |
|
589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
590 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
591 | - $help_text = ! $help_text ? '' : $help_text; |
|
592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
593 | - 'Click to open the \'Help\' tab for more information about this feature.', |
|
594 | - 'event_espresso' |
|
595 | - ) . '" > ' . $help_text . ' </a>'; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
601 | - * |
|
602 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
603 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
604 | - * @param EE_Help_Tour |
|
605 | - * @return string html |
|
606 | - */ |
|
607 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
608 | - { |
|
609 | - $id = $tour->get_slug(); |
|
610 | - $stops = $tour->get_stops(); |
|
611 | - |
|
612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
613 | - |
|
614 | - foreach ($stops as $stop) { |
|
615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
617 | - |
|
618 | - // if container is set to modal then let's make sure we set the options accordingly |
|
619 | - if (empty($data_id) && empty($data_class)) { |
|
620 | - $stop['options']['modal'] = true; |
|
621 | - $stop['options']['expose'] = true; |
|
622 | - } |
|
623 | - |
|
624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
626 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
627 | - |
|
628 | - // options |
|
629 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
630 | - $options = ' data-options="'; |
|
631 | - foreach ($stop['options'] as $option => $value) { |
|
632 | - $options .= $option . ':' . $value . ';'; |
|
633 | - } |
|
634 | - $options .= '"'; |
|
635 | - } else { |
|
636 | - $options = ''; |
|
637 | - } |
|
638 | - |
|
639 | - // let's put all together |
|
640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
641 | - } |
|
642 | - |
|
643 | - $content .= '</ol>'; |
|
644 | - return $content; |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * This is a helper method to generate a status legend for a given status array. |
|
650 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
651 | - * status_array. |
|
652 | - * |
|
653 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
654 | - * array( |
|
655 | - * 'status_item' => 'status_name' |
|
656 | - * ) |
|
657 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
658 | - * the legend. |
|
659 | - * @throws EE_Error |
|
660 | - * @return string html structure for status. |
|
661 | - */ |
|
662 | - public static function status_legend($status_array, $active_status = '') |
|
663 | - { |
|
664 | - if (! is_array($status_array)) { |
|
665 | - throw new EE_Error(esc_html__( |
|
666 | - 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
667 | - 'event_espresso' |
|
668 | - )); |
|
669 | - } |
|
670 | - |
|
671 | - $setup_array = array(); |
|
672 | - foreach ($status_array as $item => $status) { |
|
673 | - $setup_array[ $item ] = array( |
|
674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
675 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
676 | - 'status' => $status, |
|
677 | - ); |
|
678 | - } |
|
679 | - |
|
680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
683 | - foreach ($setup_array as $item => $details) { |
|
684 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | - $content .= '</dt>' . "\n"; |
|
689 | - } |
|
690 | - $content .= '</dl>' . "\n"; |
|
691 | - $content .= '</div>' . "\n"; |
|
692 | - return $content; |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
698 | - * that's nice for presenting in the wp admin |
|
699 | - * |
|
700 | - * @param mixed $data |
|
701 | - * @return string |
|
702 | - */ |
|
703 | - public static function layout_array_as_table($data) |
|
704 | - { |
|
705 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
706 | - $data = (array) $data; |
|
707 | - } |
|
708 | - ob_start(); |
|
709 | - if (is_array($data)) { |
|
710 | - if (EEH_Array::is_associative_array($data)) { |
|
711 | - ?> |
|
51 | + private static $_espresso_themes = array(); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
56 | + * |
|
57 | + * @return boolean |
|
58 | + */ |
|
59 | + public static function is_espresso_theme() |
|
60 | + { |
|
61 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
66 | + * load it's functions.php file ( if not already loaded ) |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public static function load_espresso_theme_functions() |
|
71 | + { |
|
72 | + if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public static function get_espresso_themes() |
|
86 | + { |
|
87 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
88 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
89 | + if (empty($espresso_themes)) { |
|
90 | + return array(); |
|
91 | + } |
|
92 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
93 | + unset($espresso_themes[ $key ]); |
|
94 | + } |
|
95 | + EEH_Template::$_espresso_themes = array(); |
|
96 | + foreach ($espresso_themes as $espresso_theme) { |
|
97 | + EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
98 | + } |
|
99 | + } |
|
100 | + return EEH_Template::$_espresso_themes; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * EEH_Template::get_template_part |
|
106 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
107 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
108 | + * filtering based off of the entire template part name |
|
109 | + * |
|
110 | + * @param string $slug The slug name for the generic template. |
|
111 | + * @param string $name The name of the specialised template. |
|
112 | + * @param array $template_args |
|
113 | + * @param bool $return_string |
|
114 | + * @return string the html output for the formatted money value |
|
115 | + */ |
|
116 | + public static function get_template_part( |
|
117 | + $slug = null, |
|
118 | + $name = null, |
|
119 | + $template_args = array(), |
|
120 | + $return_string = false |
|
121 | + ) { |
|
122 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
123 | + $templates = array(); |
|
124 | + $name = (string) $name; |
|
125 | + if ($name != '') { |
|
126 | + $templates[] = "{$slug}-{$name}.php"; |
|
127 | + } |
|
128 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
129 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
130 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * locate_template |
|
137 | + * locate a template file by looking in the following places, in the following order: |
|
138 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
139 | + * <assumed full absolute server path> |
|
140 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
141 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
142 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
143 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
144 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
145 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
146 | + * Example: |
|
147 | + * You are using the WordPress Twenty Sixteen theme, |
|
148 | + * and you want to customize the "some-event.template.php" template, |
|
149 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
150 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
151 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
152 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
153 | + * /relative/path/to/some-event.template.php |
|
154 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
155 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
156 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
157 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
158 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
159 | + * Had you passed an absolute path to your template that was in some other location, |
|
160 | + * ie: "/absolute/path/to/some-event.template.php" |
|
161 | + * then the search would have been : |
|
162 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
163 | + * /absolute/path/to/some-event.template.php |
|
164 | + * and stopped there upon finding it in the second location |
|
165 | + * |
|
166 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
167 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
168 | + * @param boolean $load whether to pass the located template path on to the |
|
169 | + * EEH_Template::display_template() method or simply return it |
|
170 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
171 | + * string |
|
172 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
173 | + * generate a custom template or not. Used in places where you don't actually |
|
174 | + * load the template, you just want to know if there's a custom version of it. |
|
175 | + * @return mixed |
|
176 | + * @throws DomainException |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + */ |
|
181 | + public static function locate_template( |
|
182 | + $templates = array(), |
|
183 | + $template_args = array(), |
|
184 | + $load = true, |
|
185 | + $return_string = true, |
|
186 | + $check_if_custom = false |
|
187 | + ) { |
|
188 | + // first use WP locate_template to check for template in the current theme folder |
|
189 | + $template_path = locate_template($templates); |
|
190 | + |
|
191 | + if ($check_if_custom && ! empty($template_path)) { |
|
192 | + return true; |
|
193 | + } |
|
194 | + |
|
195 | + // not in the theme |
|
196 | + if (empty($template_path)) { |
|
197 | + // not even a template to look for ? |
|
198 | + if (empty($templates)) { |
|
199 | + // get post_type |
|
200 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
201 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
202 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
203 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
204 | + ); |
|
205 | + // get array of EE Custom Post Types |
|
206 | + $EE_CPTs = $custom_post_types->getDefinitions(); |
|
207 | + // build template name based on request |
|
208 | + if (isset($EE_CPTs[ $post_type ])) { |
|
209 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
210 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
211 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
212 | + } |
|
213 | + } |
|
214 | + // currently active EE template theme |
|
215 | + $current_theme = EE_Config::get_current_theme(); |
|
216 | + |
|
217 | + // array of paths to folders that may contain templates |
|
218 | + $template_folder_paths = array( |
|
219 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
220 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
221 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
222 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
223 | + ); |
|
224 | + |
|
225 | + // add core plugin folders for checking only if we're not $check_if_custom |
|
226 | + if (! $check_if_custom) { |
|
227 | + $core_paths = array( |
|
228 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
229 | + EE_PUBLIC . $current_theme, |
|
230 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
231 | + EE_TEMPLATES . $current_theme, |
|
232 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
233 | + EE_PLUGIN_DIR_PATH, |
|
234 | + ); |
|
235 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
236 | + } |
|
237 | + |
|
238 | + // now filter that array |
|
239 | + $template_folder_paths = apply_filters( |
|
240 | + 'FHEE__EEH_Template__locate_template__template_folder_paths', |
|
241 | + $template_folder_paths |
|
242 | + ); |
|
243 | + $templates = is_array($templates) ? $templates : array($templates); |
|
244 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
245 | + // array to hold all possible template paths |
|
246 | + $full_template_paths = array(); |
|
247 | + |
|
248 | + // loop through $templates |
|
249 | + foreach ($templates as $template) { |
|
250 | + // normalize directory separators |
|
251 | + $template = EEH_File::standardise_directory_separators($template); |
|
252 | + $file_name = basename($template); |
|
253 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
254 | + // while looping through all template folder paths |
|
255 | + foreach ($template_folder_paths as $template_folder_path) { |
|
256 | + // normalize directory separators |
|
257 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
258 | + // determine if any common base path exists between the two paths |
|
259 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
260 | + array($template_folder_path, $template_path_minus_file_name) |
|
261 | + ); |
|
262 | + if ($common_base_path !== '') { |
|
263 | + // both paths have a common base, so just tack the filename onto our search path |
|
264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | + } else { |
|
266 | + // no common base path, so let's just concatenate |
|
267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | + } |
|
269 | + // build up our template locations array by adding our resolved paths |
|
270 | + $full_template_paths[] = $resolved_path; |
|
271 | + } |
|
272 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
273 | + array_unshift($full_template_paths, $template); |
|
274 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
275 | + array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
276 | + } |
|
277 | + // filter final array of full template paths |
|
278 | + $full_template_paths = apply_filters( |
|
279 | + 'FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | + $full_template_paths, |
|
281 | + $file_name |
|
282 | + ); |
|
283 | + // now loop through our final array of template location paths and check each location |
|
284 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
285 | + if (is_readable($full_template_path)) { |
|
286 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
287 | + break; |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + // hook that can be used to display the full template path that will be used |
|
293 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
294 | + |
|
295 | + // if we got it and you want to see it... |
|
296 | + if ($template_path && $load && ! $check_if_custom) { |
|
297 | + if ($return_string) { |
|
298 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
299 | + } else { |
|
300 | + EEH_Template::display_template($template_path, $template_args, false); |
|
301 | + } |
|
302 | + } |
|
303 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * _find_common_base_path |
|
309 | + * given two paths, this determines if there is a common base path between the two |
|
310 | + * |
|
311 | + * @param array $paths |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + protected static function _find_common_base_path($paths) |
|
315 | + { |
|
316 | + $last_offset = 0; |
|
317 | + $common_base_path = ''; |
|
318 | + while (($index = strpos($paths[0], '/', $last_offset)) !== false) { |
|
319 | + $dir_length = $index - $last_offset + 1; |
|
320 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
321 | + foreach ($paths as $path) { |
|
322 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
323 | + return $common_base_path; |
|
324 | + } |
|
325 | + } |
|
326 | + $common_base_path .= $directory; |
|
327 | + $last_offset = $index + 1; |
|
328 | + } |
|
329 | + return substr($common_base_path, 0, -1); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * load and display a template |
|
335 | + * |
|
336 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
337 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
338 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
339 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
340 | + * not found or is not readable |
|
341 | + * @return mixed string |
|
342 | + * @throws \DomainException |
|
343 | + */ |
|
344 | + public static function display_template( |
|
345 | + $template_path = false, |
|
346 | + $template_args = array(), |
|
347 | + $return_string = false, |
|
348 | + $throw_exceptions = false |
|
349 | + ) { |
|
350 | + |
|
351 | + /** |
|
352 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
353 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
354 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
355 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
356 | + * using this. |
|
357 | + * |
|
358 | + * @since 4.6.0 |
|
359 | + */ |
|
360 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
361 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
362 | + |
|
363 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
364 | + if (! $template_path || ! is_readable($template_path)) { |
|
365 | + return ''; |
|
366 | + } |
|
367 | + // if $template_args are not in an array, then make it so |
|
368 | + if (! is_array($template_args) && ! is_object($template_args)) { |
|
369 | + $template_args = array($template_args); |
|
370 | + } |
|
371 | + extract($template_args, EXTR_SKIP); |
|
372 | + // ignore whether template is accessible ? |
|
373 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
374 | + throw new \DomainException( |
|
375 | + esc_html__( |
|
376 | + 'Invalid, unreadable, or missing file.', |
|
377 | + 'event_espresso' |
|
378 | + ) |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + if ($return_string) { |
|
384 | + // because we want to return a string, we are going to capture the output |
|
385 | + ob_start(); |
|
386 | + include($template_path); |
|
387 | + return ob_get_clean(); |
|
388 | + } else { |
|
389 | + include($template_path); |
|
390 | + } |
|
391 | + return ''; |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
397 | + * |
|
398 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
399 | + * @param string $prefix added to the beginning of the generated class |
|
400 | + * @param string $suffix added to the end of the generated class |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
404 | + { |
|
405 | + // in the beginning... |
|
406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
407 | + // da muddle |
|
408 | + $class = ''; |
|
409 | + // the end |
|
410 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
411 | + // is the passed object an EE object ? |
|
412 | + if ($object instanceof EE_Base_Class) { |
|
413 | + // grab the exact type of object |
|
414 | + $obj_class = get_class($object); |
|
415 | + // depending on the type of object... |
|
416 | + switch ($obj_class) { |
|
417 | + // no specifics just yet... |
|
418 | + default: |
|
419 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
420 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
421 | + } |
|
422 | + } |
|
423 | + return $prefix . $class . $suffix; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * EEH_Template::format_currency |
|
430 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
431 | + * the country currency settings from the supplied country ISO code |
|
432 | + * |
|
433 | + * @param float $amount raw money value |
|
434 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
435 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
436 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
437 | + * @param string $cur_code_span_class |
|
438 | + * @return string the html output for the formatted money value |
|
439 | + * @throws \EE_Error |
|
440 | + */ |
|
441 | + public static function format_currency( |
|
442 | + $amount = null, |
|
443 | + $return_raw = false, |
|
444 | + $display_code = true, |
|
445 | + $CNT_ISO = '', |
|
446 | + $cur_code_span_class = 'currency-code' |
|
447 | + ) { |
|
448 | + // ensure amount was received |
|
449 | + if ($amount === null) { |
|
450 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
451 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
452 | + return ''; |
|
453 | + } |
|
454 | + // ensure amount is float |
|
455 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
456 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
457 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
458 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
459 | + // still a number or was amount converted to a string like "free" ? |
|
460 | + if (is_float($amount_formatted)) { |
|
461 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
462 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
463 | + // verify results |
|
464 | + if (! $mny instanceof EE_Currency_Config) { |
|
465 | + // set default config country currency settings |
|
466 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
467 | + ? EE_Registry::instance()->CFG->currency |
|
468 | + : new EE_Currency_Config(); |
|
469 | + } |
|
470 | + // format float |
|
471 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
472 | + // add formatting ? |
|
473 | + if (! $return_raw) { |
|
474 | + // add currency sign |
|
475 | + if ($mny->sign_b4) { |
|
476 | + if ($amount >= 0) { |
|
477 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
478 | + } else { |
|
479 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
480 | + } |
|
481 | + } else { |
|
482 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | + } |
|
484 | + |
|
485 | + // filter to allow global setting of display_code |
|
486 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | + |
|
488 | + // add currency code ? |
|
489 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | + } |
|
491 | + // filter results |
|
492 | + $amount_formatted = apply_filters( |
|
493 | + 'FHEE__EEH_Template__format_currency__amount_formatted', |
|
494 | + $amount_formatted, |
|
495 | + $mny, |
|
496 | + $return_raw |
|
497 | + ); |
|
498 | + } |
|
499 | + // clean up vars |
|
500 | + unset($mny); |
|
501 | + // return formatted currency amount |
|
502 | + return $amount_formatted; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
508 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
509 | + * related status model or model object (i.e. in documentation etc.) |
|
510 | + * |
|
511 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
512 | + * match, then 'Unknown' will be returned. |
|
513 | + * @param boolean $plural Whether to return plural or not |
|
514 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
515 | + * @return string The localized label for the status id. |
|
516 | + */ |
|
517 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
518 | + { |
|
519 | + /** @type EEM_Status $EEM_Status */ |
|
520 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
521 | + $status = $EEM_Status->localized_status( |
|
522 | + array($status_id => __('unknown', 'event_espresso')), |
|
523 | + $plural, |
|
524 | + $schema |
|
525 | + ); |
|
526 | + return $status[ $status_id ]; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * This helper just returns a button or link for the given parameters |
|
532 | + * |
|
533 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
534 | + * @param string $label What is the label you want displayed for the button |
|
535 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
536 | + * @param string $icon |
|
537 | + * @param string $title |
|
538 | + * @return string the html output for the button |
|
539 | + */ |
|
540 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
541 | + { |
|
542 | + $icon_html = ''; |
|
543 | + if (! empty($icon)) { |
|
544 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
545 | + $dashicons = array_filter($dashicons); |
|
546 | + $count = count($dashicons); |
|
547 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
548 | + foreach ($dashicons as $dashicon) { |
|
549 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
550 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
551 | + } |
|
552 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
553 | + } |
|
554 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
556 | + return $button; |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * This returns a generated link that will load the related help tab on admin pages. |
|
562 | + * |
|
563 | + * @param string $help_tab_id the id for the connected help tab |
|
564 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
565 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
566 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
567 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
568 | + * @return string generated link |
|
569 | + */ |
|
570 | + public static function get_help_tab_link( |
|
571 | + $help_tab_id, |
|
572 | + $page = false, |
|
573 | + $action = false, |
|
574 | + $icon_style = false, |
|
575 | + $help_text = false |
|
576 | + ) { |
|
577 | + |
|
578 | + if (! $page) { |
|
579 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
580 | + } |
|
581 | + |
|
582 | + if (! $action) { |
|
583 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
584 | + } |
|
585 | + |
|
586 | + $action = empty($action) ? 'default' : $action; |
|
587 | + |
|
588 | + |
|
589 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
590 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
591 | + $help_text = ! $help_text ? '' : $help_text; |
|
592 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
593 | + 'Click to open the \'Help\' tab for more information about this feature.', |
|
594 | + 'event_espresso' |
|
595 | + ) . '" > ' . $help_text . ' </a>'; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
601 | + * |
|
602 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
603 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
604 | + * @param EE_Help_Tour |
|
605 | + * @return string html |
|
606 | + */ |
|
607 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
608 | + { |
|
609 | + $id = $tour->get_slug(); |
|
610 | + $stops = $tour->get_stops(); |
|
611 | + |
|
612 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
613 | + |
|
614 | + foreach ($stops as $stop) { |
|
615 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
617 | + |
|
618 | + // if container is set to modal then let's make sure we set the options accordingly |
|
619 | + if (empty($data_id) && empty($data_class)) { |
|
620 | + $stop['options']['modal'] = true; |
|
621 | + $stop['options']['expose'] = true; |
|
622 | + } |
|
623 | + |
|
624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
626 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
627 | + |
|
628 | + // options |
|
629 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
630 | + $options = ' data-options="'; |
|
631 | + foreach ($stop['options'] as $option => $value) { |
|
632 | + $options .= $option . ':' . $value . ';'; |
|
633 | + } |
|
634 | + $options .= '"'; |
|
635 | + } else { |
|
636 | + $options = ''; |
|
637 | + } |
|
638 | + |
|
639 | + // let's put all together |
|
640 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
641 | + } |
|
642 | + |
|
643 | + $content .= '</ol>'; |
|
644 | + return $content; |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * This is a helper method to generate a status legend for a given status array. |
|
650 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
651 | + * status_array. |
|
652 | + * |
|
653 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
654 | + * array( |
|
655 | + * 'status_item' => 'status_name' |
|
656 | + * ) |
|
657 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
658 | + * the legend. |
|
659 | + * @throws EE_Error |
|
660 | + * @return string html structure for status. |
|
661 | + */ |
|
662 | + public static function status_legend($status_array, $active_status = '') |
|
663 | + { |
|
664 | + if (! is_array($status_array)) { |
|
665 | + throw new EE_Error(esc_html__( |
|
666 | + 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
667 | + 'event_espresso' |
|
668 | + )); |
|
669 | + } |
|
670 | + |
|
671 | + $setup_array = array(); |
|
672 | + foreach ($status_array as $item => $status) { |
|
673 | + $setup_array[ $item ] = array( |
|
674 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
675 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
676 | + 'status' => $status, |
|
677 | + ); |
|
678 | + } |
|
679 | + |
|
680 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
683 | + foreach ($setup_array as $item => $details) { |
|
684 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
685 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | + $content .= '</dt>' . "\n"; |
|
689 | + } |
|
690 | + $content .= '</dl>' . "\n"; |
|
691 | + $content .= '</div>' . "\n"; |
|
692 | + return $content; |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
698 | + * that's nice for presenting in the wp admin |
|
699 | + * |
|
700 | + * @param mixed $data |
|
701 | + * @return string |
|
702 | + */ |
|
703 | + public static function layout_array_as_table($data) |
|
704 | + { |
|
705 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
706 | + $data = (array) $data; |
|
707 | + } |
|
708 | + ob_start(); |
|
709 | + if (is_array($data)) { |
|
710 | + if (EEH_Array::is_associative_array($data)) { |
|
711 | + ?> |
|
712 | 712 | <table class="widefat"> |
713 | 713 | <tbody> |
714 | 714 | <?php |
715 | - foreach ($data as $data_key => $data_values) { |
|
716 | - ?> |
|
715 | + foreach ($data as $data_key => $data_values) { |
|
716 | + ?> |
|
717 | 717 | <tr> |
718 | 718 | <td> |
719 | 719 | <?php echo $data_key; ?> |
@@ -723,291 +723,291 @@ discard block |
||
723 | 723 | </td> |
724 | 724 | </tr> |
725 | 725 | <?php |
726 | - } ?> |
|
726 | + } ?> |
|
727 | 727 | </tbody> |
728 | 728 | </table> |
729 | 729 | <?php |
730 | - } else { |
|
731 | - ?> |
|
730 | + } else { |
|
731 | + ?> |
|
732 | 732 | <ul> |
733 | 733 | <?php |
734 | - foreach ($data as $datum) { |
|
735 | - echo "<li>"; |
|
736 | - echo self::layout_array_as_table($datum); |
|
737 | - echo "</li>"; |
|
738 | - } ?> |
|
734 | + foreach ($data as $datum) { |
|
735 | + echo "<li>"; |
|
736 | + echo self::layout_array_as_table($datum); |
|
737 | + echo "</li>"; |
|
738 | + } ?> |
|
739 | 739 | </ul> |
740 | 740 | <?php |
741 | - } |
|
742 | - } else { |
|
743 | - // simple value |
|
744 | - echo esc_html($data); |
|
745 | - } |
|
746 | - return ob_get_clean(); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
752 | - * |
|
753 | - * @since 4.4.0 |
|
754 | - * @see self:get_paging_html() for argument docs. |
|
755 | - * @param $total_items |
|
756 | - * @param $current |
|
757 | - * @param $per_page |
|
758 | - * @param $url |
|
759 | - * @param bool $show_num_field |
|
760 | - * @param string $paged_arg_name |
|
761 | - * @param array $items_label |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public static function paging_html( |
|
765 | - $total_items, |
|
766 | - $current, |
|
767 | - $per_page, |
|
768 | - $url, |
|
769 | - $show_num_field = true, |
|
770 | - $paged_arg_name = 'paged', |
|
771 | - $items_label = array() |
|
772 | - ) { |
|
773 | - echo self::get_paging_html( |
|
774 | - $total_items, |
|
775 | - $current, |
|
776 | - $per_page, |
|
777 | - $url, |
|
778 | - $show_num_field, |
|
779 | - $paged_arg_name, |
|
780 | - $items_label |
|
781 | - ); |
|
782 | - } |
|
783 | - |
|
784 | - |
|
785 | - /** |
|
786 | - * A method for generating paging similar to WP_List_Table |
|
787 | - * |
|
788 | - * @since 4.4.0 |
|
789 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
790 | - * @param integer $total_items How many total items there are to page. |
|
791 | - * @param integer $current What the current page is. |
|
792 | - * @param integer $per_page How many items per page. |
|
793 | - * @param string $url What the base url for page links is. |
|
794 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
795 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
796 | - * @param array $items_label An array of singular/plural values for the items label: |
|
797 | - * array( |
|
798 | - * 'single' => 'item', |
|
799 | - * 'plural' => 'items' |
|
800 | - * ) |
|
801 | - * @return string |
|
802 | - */ |
|
803 | - public static function get_paging_html( |
|
804 | - $total_items, |
|
805 | - $current, |
|
806 | - $per_page, |
|
807 | - $url, |
|
808 | - $show_num_field = true, |
|
809 | - $paged_arg_name = 'paged', |
|
810 | - $items_label = array() |
|
811 | - ) { |
|
812 | - $page_links = array(); |
|
813 | - $disable_first = $disable_last = ''; |
|
814 | - $total_items = (int) $total_items; |
|
815 | - $per_page = (int) $per_page; |
|
816 | - $current = (int) $current; |
|
817 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
818 | - |
|
819 | - // filter items_label |
|
820 | - $items_label = apply_filters( |
|
821 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
822 | - $items_label |
|
823 | - ); |
|
824 | - |
|
825 | - if (empty($items_label) |
|
826 | - || ! is_array($items_label) |
|
827 | - || ! isset($items_label['single']) |
|
828 | - || ! isset($items_label['plural']) |
|
829 | - ) { |
|
830 | - $items_label = array( |
|
831 | - 'single' => __('1 item', 'event_espresso'), |
|
832 | - 'plural' => __('%s items', 'event_espresso'), |
|
833 | - ); |
|
834 | - } else { |
|
835 | - $items_label = array( |
|
836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
838 | - ); |
|
839 | - } |
|
840 | - |
|
841 | - $total_pages = ceil($total_items / $per_page); |
|
842 | - |
|
843 | - if ($total_pages <= 1) { |
|
844 | - return ''; |
|
845 | - } |
|
846 | - |
|
847 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
848 | - |
|
849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
850 | - |
|
851 | - if ($current === 1) { |
|
852 | - $disable_first = ' disabled'; |
|
853 | - } |
|
854 | - if ($current == $total_pages) { |
|
855 | - $disable_last = ' disabled'; |
|
856 | - } |
|
857 | - |
|
858 | - $page_links[] = sprintf( |
|
859 | - "<a class='%s' title='%s' href='%s'>%s</a>", |
|
860 | - 'first-page' . $disable_first, |
|
861 | - esc_attr__('Go to the first page', 'event_espresso'), |
|
862 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
863 | - '«' |
|
864 | - ); |
|
865 | - |
|
866 | - $page_links[] = sprintf( |
|
867 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
868 | - 'prev-page' . $disable_first, |
|
869 | - esc_attr__('Go to the previous page', 'event_espresso'), |
|
870 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
871 | - '‹' |
|
872 | - ); |
|
873 | - |
|
874 | - if (! $show_num_field) { |
|
875 | - $html_current_page = $current; |
|
876 | - } else { |
|
877 | - $html_current_page = sprintf( |
|
878 | - "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
879 | - esc_attr__('Current page', 'event_espresso'), |
|
880 | - $current, |
|
881 | - strlen($total_pages) |
|
882 | - ); |
|
883 | - } |
|
884 | - |
|
885 | - $html_total_pages = sprintf( |
|
886 | - '<span class="total-pages">%s</span>', |
|
887 | - number_format_i18n($total_pages) |
|
888 | - ); |
|
889 | - $page_links[] = sprintf( |
|
890 | - _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
891 | - $html_current_page, |
|
892 | - $html_total_pages, |
|
893 | - '<span class="paging-input">', |
|
894 | - '</span>' |
|
895 | - ); |
|
896 | - |
|
897 | - $page_links[] = sprintf( |
|
898 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
899 | - 'next-page' . $disable_last, |
|
900 | - esc_attr__('Go to the next page', 'event_espresso'), |
|
901 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
902 | - '›' |
|
903 | - ); |
|
904 | - |
|
905 | - $page_links[] = sprintf( |
|
906 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
907 | - 'last-page' . $disable_last, |
|
908 | - esc_attr__('Go to the last page', 'event_espresso'), |
|
909 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
910 | - '»' |
|
911 | - ); |
|
912 | - |
|
913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
914 | - // set page class |
|
915 | - if ($total_pages) { |
|
916 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
917 | - } else { |
|
918 | - $page_class = ' no-pages'; |
|
919 | - } |
|
920 | - |
|
921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
922 | - } |
|
923 | - |
|
924 | - |
|
925 | - /** |
|
926 | - * @param string $wrap_class |
|
927 | - * @param string $wrap_id |
|
928 | - * @return string |
|
929 | - */ |
|
930 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
931 | - { |
|
932 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
933 | - if (! $admin && |
|
934 | - ! apply_filters( |
|
935 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
936 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
937 | - ) |
|
938 | - ) { |
|
939 | - return ''; |
|
940 | - } |
|
941 | - $tag = $admin ? 'span' : 'div'; |
|
942 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
943 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
944 | - $attributes .= ! empty($wrap_class) |
|
945 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
946 | - : ' class="powered-by-event-espresso-credit"'; |
|
947 | - $query_args = array_merge( |
|
948 | - array( |
|
949 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
950 | - 'utm_source' => 'powered_by_event_espresso', |
|
951 | - 'utm_medium' => 'link', |
|
952 | - 'utm_campaign' => 'powered_by', |
|
953 | - ), |
|
954 | - $query_args |
|
955 | - ); |
|
956 | - $powered_by = apply_filters( |
|
957 | - 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | - ); |
|
960 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
961 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
962 | - return (string) apply_filters( |
|
963 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
964 | - sprintf( |
|
965 | - esc_html_x( |
|
966 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
967 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
968 | - 'event_espresso' |
|
969 | - ), |
|
970 | - "<{$tag}{$attributes}>", |
|
971 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
972 | - $admin ? '' : '<br />' |
|
973 | - ), |
|
974 | - $wrap_class, |
|
975 | - $wrap_id |
|
976 | - ); |
|
977 | - } |
|
741 | + } |
|
742 | + } else { |
|
743 | + // simple value |
|
744 | + echo esc_html($data); |
|
745 | + } |
|
746 | + return ob_get_clean(); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
752 | + * |
|
753 | + * @since 4.4.0 |
|
754 | + * @see self:get_paging_html() for argument docs. |
|
755 | + * @param $total_items |
|
756 | + * @param $current |
|
757 | + * @param $per_page |
|
758 | + * @param $url |
|
759 | + * @param bool $show_num_field |
|
760 | + * @param string $paged_arg_name |
|
761 | + * @param array $items_label |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public static function paging_html( |
|
765 | + $total_items, |
|
766 | + $current, |
|
767 | + $per_page, |
|
768 | + $url, |
|
769 | + $show_num_field = true, |
|
770 | + $paged_arg_name = 'paged', |
|
771 | + $items_label = array() |
|
772 | + ) { |
|
773 | + echo self::get_paging_html( |
|
774 | + $total_items, |
|
775 | + $current, |
|
776 | + $per_page, |
|
777 | + $url, |
|
778 | + $show_num_field, |
|
779 | + $paged_arg_name, |
|
780 | + $items_label |
|
781 | + ); |
|
782 | + } |
|
783 | + |
|
784 | + |
|
785 | + /** |
|
786 | + * A method for generating paging similar to WP_List_Table |
|
787 | + * |
|
788 | + * @since 4.4.0 |
|
789 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
790 | + * @param integer $total_items How many total items there are to page. |
|
791 | + * @param integer $current What the current page is. |
|
792 | + * @param integer $per_page How many items per page. |
|
793 | + * @param string $url What the base url for page links is. |
|
794 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
795 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
796 | + * @param array $items_label An array of singular/plural values for the items label: |
|
797 | + * array( |
|
798 | + * 'single' => 'item', |
|
799 | + * 'plural' => 'items' |
|
800 | + * ) |
|
801 | + * @return string |
|
802 | + */ |
|
803 | + public static function get_paging_html( |
|
804 | + $total_items, |
|
805 | + $current, |
|
806 | + $per_page, |
|
807 | + $url, |
|
808 | + $show_num_field = true, |
|
809 | + $paged_arg_name = 'paged', |
|
810 | + $items_label = array() |
|
811 | + ) { |
|
812 | + $page_links = array(); |
|
813 | + $disable_first = $disable_last = ''; |
|
814 | + $total_items = (int) $total_items; |
|
815 | + $per_page = (int) $per_page; |
|
816 | + $current = (int) $current; |
|
817 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
818 | + |
|
819 | + // filter items_label |
|
820 | + $items_label = apply_filters( |
|
821 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
822 | + $items_label |
|
823 | + ); |
|
824 | + |
|
825 | + if (empty($items_label) |
|
826 | + || ! is_array($items_label) |
|
827 | + || ! isset($items_label['single']) |
|
828 | + || ! isset($items_label['plural']) |
|
829 | + ) { |
|
830 | + $items_label = array( |
|
831 | + 'single' => __('1 item', 'event_espresso'), |
|
832 | + 'plural' => __('%s items', 'event_espresso'), |
|
833 | + ); |
|
834 | + } else { |
|
835 | + $items_label = array( |
|
836 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
838 | + ); |
|
839 | + } |
|
840 | + |
|
841 | + $total_pages = ceil($total_items / $per_page); |
|
842 | + |
|
843 | + if ($total_pages <= 1) { |
|
844 | + return ''; |
|
845 | + } |
|
846 | + |
|
847 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
848 | + |
|
849 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
850 | + |
|
851 | + if ($current === 1) { |
|
852 | + $disable_first = ' disabled'; |
|
853 | + } |
|
854 | + if ($current == $total_pages) { |
|
855 | + $disable_last = ' disabled'; |
|
856 | + } |
|
857 | + |
|
858 | + $page_links[] = sprintf( |
|
859 | + "<a class='%s' title='%s' href='%s'>%s</a>", |
|
860 | + 'first-page' . $disable_first, |
|
861 | + esc_attr__('Go to the first page', 'event_espresso'), |
|
862 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
863 | + '«' |
|
864 | + ); |
|
865 | + |
|
866 | + $page_links[] = sprintf( |
|
867 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
868 | + 'prev-page' . $disable_first, |
|
869 | + esc_attr__('Go to the previous page', 'event_espresso'), |
|
870 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
871 | + '‹' |
|
872 | + ); |
|
873 | + |
|
874 | + if (! $show_num_field) { |
|
875 | + $html_current_page = $current; |
|
876 | + } else { |
|
877 | + $html_current_page = sprintf( |
|
878 | + "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
879 | + esc_attr__('Current page', 'event_espresso'), |
|
880 | + $current, |
|
881 | + strlen($total_pages) |
|
882 | + ); |
|
883 | + } |
|
884 | + |
|
885 | + $html_total_pages = sprintf( |
|
886 | + '<span class="total-pages">%s</span>', |
|
887 | + number_format_i18n($total_pages) |
|
888 | + ); |
|
889 | + $page_links[] = sprintf( |
|
890 | + _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
|
891 | + $html_current_page, |
|
892 | + $html_total_pages, |
|
893 | + '<span class="paging-input">', |
|
894 | + '</span>' |
|
895 | + ); |
|
896 | + |
|
897 | + $page_links[] = sprintf( |
|
898 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
899 | + 'next-page' . $disable_last, |
|
900 | + esc_attr__('Go to the next page', 'event_espresso'), |
|
901 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
902 | + '›' |
|
903 | + ); |
|
904 | + |
|
905 | + $page_links[] = sprintf( |
|
906 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
907 | + 'last-page' . $disable_last, |
|
908 | + esc_attr__('Go to the last page', 'event_espresso'), |
|
909 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
910 | + '»' |
|
911 | + ); |
|
912 | + |
|
913 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
914 | + // set page class |
|
915 | + if ($total_pages) { |
|
916 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
917 | + } else { |
|
918 | + $page_class = ' no-pages'; |
|
919 | + } |
|
920 | + |
|
921 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
922 | + } |
|
923 | + |
|
924 | + |
|
925 | + /** |
|
926 | + * @param string $wrap_class |
|
927 | + * @param string $wrap_id |
|
928 | + * @return string |
|
929 | + */ |
|
930 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
931 | + { |
|
932 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
933 | + if (! $admin && |
|
934 | + ! apply_filters( |
|
935 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
936 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
937 | + ) |
|
938 | + ) { |
|
939 | + return ''; |
|
940 | + } |
|
941 | + $tag = $admin ? 'span' : 'div'; |
|
942 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
943 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
944 | + $attributes .= ! empty($wrap_class) |
|
945 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
946 | + : ' class="powered-by-event-espresso-credit"'; |
|
947 | + $query_args = array_merge( |
|
948 | + array( |
|
949 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
950 | + 'utm_source' => 'powered_by_event_espresso', |
|
951 | + 'utm_medium' => 'link', |
|
952 | + 'utm_campaign' => 'powered_by', |
|
953 | + ), |
|
954 | + $query_args |
|
955 | + ); |
|
956 | + $powered_by = apply_filters( |
|
957 | + 'FHEE__EEH_Template__powered_by_event_espresso_text', |
|
958 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | + ); |
|
960 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
961 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
962 | + return (string) apply_filters( |
|
963 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
964 | + sprintf( |
|
965 | + esc_html_x( |
|
966 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
967 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
968 | + 'event_espresso' |
|
969 | + ), |
|
970 | + "<{$tag}{$attributes}>", |
|
971 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
972 | + $admin ? '' : '<br />' |
|
973 | + ), |
|
974 | + $wrap_class, |
|
975 | + $wrap_id |
|
976 | + ); |
|
977 | + } |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | |
981 | 981 | |
982 | 982 | |
983 | 983 | if (! function_exists('espresso_pagination')) { |
984 | - /** |
|
985 | - * espresso_pagination |
|
986 | - * |
|
987 | - * @access public |
|
988 | - * @return void |
|
989 | - */ |
|
990 | - function espresso_pagination() |
|
991 | - { |
|
992 | - global $wp_query; |
|
993 | - $big = 999999999; // need an unlikely integer |
|
994 | - $pagination = paginate_links( |
|
995 | - array( |
|
996 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
997 | - 'format' => '?paged=%#%', |
|
998 | - 'current' => max(1, get_query_var('paged')), |
|
999 | - 'total' => $wp_query->max_num_pages, |
|
1000 | - 'show_all' => true, |
|
1001 | - 'end_size' => 10, |
|
1002 | - 'mid_size' => 6, |
|
1003 | - 'prev_next' => true, |
|
1004 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
1005 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
1006 | - 'type' => 'plain', |
|
1007 | - 'add_args' => false, |
|
1008 | - 'add_fragment' => '', |
|
1009 | - ) |
|
1010 | - ); |
|
1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1012 | - } |
|
984 | + /** |
|
985 | + * espresso_pagination |
|
986 | + * |
|
987 | + * @access public |
|
988 | + * @return void |
|
989 | + */ |
|
990 | + function espresso_pagination() |
|
991 | + { |
|
992 | + global $wp_query; |
|
993 | + $big = 999999999; // need an unlikely integer |
|
994 | + $pagination = paginate_links( |
|
995 | + array( |
|
996 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
997 | + 'format' => '?paged=%#%', |
|
998 | + 'current' => max(1, get_query_var('paged')), |
|
999 | + 'total' => $wp_query->max_num_pages, |
|
1000 | + 'show_all' => true, |
|
1001 | + 'end_size' => 10, |
|
1002 | + 'mid_size' => 6, |
|
1003 | + 'prev_next' => true, |
|
1004 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
1005 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
1006 | + 'type' => 'plain', |
|
1007 | + 'add_args' => false, |
|
1008 | + 'add_fragment' => '', |
|
1009 | + ) |
|
1010 | + ); |
|
1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1012 | + } |
|
1013 | 1013 | } |
1014 | 1014 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | 5 | use EventEspresso\core\services\loaders\LoaderFactory; |
6 | 6 | |
7 | -if (! function_exists('espresso_get_template_part')) { |
|
7 | +if ( ! function_exists('espresso_get_template_part')) { |
|
8 | 8 | /** |
9 | 9 | * espresso_get_template_part |
10 | 10 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | -if (! function_exists('espresso_get_object_css_class')) { |
|
24 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
25 | 25 | /** |
26 | 26 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
27 | 27 | * |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function load_espresso_theme_functions() |
71 | 71 | { |
72 | - if (! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) { |
|
74 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php'); |
|
72 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
73 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) { |
|
74 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php'); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | public static function get_espresso_themes() |
86 | 86 | { |
87 | 87 | if (empty(EEH_Template::$_espresso_themes)) { |
88 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
88 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
89 | 89 | if (empty($espresso_themes)) { |
90 | 90 | return array(); |
91 | 91 | } |
92 | 92 | if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
93 | - unset($espresso_themes[ $key ]); |
|
93 | + unset($espresso_themes[$key]); |
|
94 | 94 | } |
95 | 95 | EEH_Template::$_espresso_themes = array(); |
96 | 96 | foreach ($espresso_themes as $espresso_theme) { |
97 | - EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme; |
|
97 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | return EEH_Template::$_espresso_themes; |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | // get array of EE Custom Post Types |
206 | 206 | $EE_CPTs = $custom_post_types->getDefinitions(); |
207 | 207 | // build template name based on request |
208 | - if (isset($EE_CPTs[ $post_type ])) { |
|
208 | + if (isset($EE_CPTs[$post_type])) { |
|
209 | 209 | $archive_or_single = is_archive() ? 'archive' : ''; |
210 | 210 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
211 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
211 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | // currently active EE template theme |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | // array of paths to folders that may contain templates |
218 | 218 | $template_folder_paths = array( |
219 | 219 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
220 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
220 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
221 | 221 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
222 | 222 | EVENT_ESPRESSO_TEMPLATE_DIR, |
223 | 223 | ); |
224 | 224 | |
225 | 225 | // add core plugin folders for checking only if we're not $check_if_custom |
226 | - if (! $check_if_custom) { |
|
227 | - $core_paths = array( |
|
226 | + if ( ! $check_if_custom) { |
|
227 | + $core_paths = array( |
|
228 | 228 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
229 | - EE_PUBLIC . $current_theme, |
|
229 | + EE_PUBLIC.$current_theme, |
|
230 | 230 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
231 | - EE_TEMPLATES . $current_theme, |
|
231 | + EE_TEMPLATES.$current_theme, |
|
232 | 232 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
233 | 233 | EE_PLUGIN_DIR_PATH, |
234 | 234 | ); |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | ); |
262 | 262 | if ($common_base_path !== '') { |
263 | 263 | // both paths have a common base, so just tack the filename onto our search path |
264 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
264 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
265 | 265 | } else { |
266 | 266 | // no common base path, so let's just concatenate |
267 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
267 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
268 | 268 | } |
269 | 269 | // build up our template locations array by adding our resolved paths |
270 | 270 | $full_template_paths[] = $resolved_path; |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
273 | 273 | array_unshift($full_template_paths, $template); |
274 | 274 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
275 | - array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name); |
|
275 | + array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name); |
|
276 | 276 | } |
277 | 277 | // filter final array of full template paths |
278 | 278 | $full_template_paths = apply_filters( |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
362 | 362 | |
363 | 363 | // you gimme nuttin - YOU GET NUTTIN !! |
364 | - if (! $template_path || ! is_readable($template_path)) { |
|
364 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
365 | 365 | return ''; |
366 | 366 | } |
367 | 367 | // if $template_args are not in an array, then make it so |
368 | - if (! is_array($template_args) && ! is_object($template_args)) { |
|
368 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
369 | 369 | $template_args = array($template_args); |
370 | 370 | } |
371 | 371 | extract($template_args, EXTR_SKIP); |
@@ -403,11 +403,11 @@ discard block |
||
403 | 403 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
404 | 404 | { |
405 | 405 | // in the beginning... |
406 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
406 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
407 | 407 | // da muddle |
408 | 408 | $class = ''; |
409 | 409 | // the end |
410 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
410 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
411 | 411 | // is the passed object an EE object ? |
412 | 412 | if ($object instanceof EE_Base_Class) { |
413 | 413 | // grab the exact type of object |
@@ -417,10 +417,10 @@ discard block |
||
417 | 417 | // no specifics just yet... |
418 | 418 | default: |
419 | 419 | $class = strtolower(str_replace('_', '-', $obj_class)); |
420 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
420 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
421 | 421 | } |
422 | 422 | } |
423 | - return $prefix . $class . $suffix; |
|
423 | + return $prefix.$class.$suffix; |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | // was a country ISO code passed ? if so generate currency config object for that country |
462 | 462 | $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
463 | 463 | // verify results |
464 | - if (! $mny instanceof EE_Currency_Config) { |
|
464 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
465 | 465 | // set default config country currency settings |
466 | 466 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
467 | 467 | ? EE_Registry::instance()->CFG->currency |
@@ -470,23 +470,23 @@ discard block |
||
470 | 470 | // format float |
471 | 471 | $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
472 | 472 | // add formatting ? |
473 | - if (! $return_raw) { |
|
473 | + if ( ! $return_raw) { |
|
474 | 474 | // add currency sign |
475 | 475 | if ($mny->sign_b4) { |
476 | 476 | if ($amount >= 0) { |
477 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
478 | 478 | } else { |
479 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
480 | 480 | } |
481 | 481 | } else { |
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
482 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | // filter to allow global setting of display_code |
486 | 486 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
487 | 487 | |
488 | 488 | // add currency code ? |
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
489 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
490 | 490 | } |
491 | 491 | // filter results |
492 | 492 | $amount_formatted = apply_filters( |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $plural, |
524 | 524 | $schema |
525 | 525 | ); |
526 | - return $status[ $status_id ]; |
|
526 | + return $status[$status_id]; |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | |
@@ -540,19 +540,19 @@ discard block |
||
540 | 540 | public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
541 | 541 | { |
542 | 542 | $icon_html = ''; |
543 | - if (! empty($icon)) { |
|
543 | + if ( ! empty($icon)) { |
|
544 | 544 | $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
545 | 545 | $dashicons = array_filter($dashicons); |
546 | 546 | $count = count($dashicons); |
547 | 547 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
548 | 548 | foreach ($dashicons as $dashicon) { |
549 | 549 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
550 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
550 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
551 | 551 | } |
552 | 552 | $icon_html .= $count > 1 ? '</span>' : ''; |
553 | 553 | } |
554 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
555 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
554 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
555 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
556 | 556 | return $button; |
557 | 557 | } |
558 | 558 | |
@@ -575,24 +575,24 @@ discard block |
||
575 | 575 | $help_text = false |
576 | 576 | ) { |
577 | 577 | |
578 | - if (! $page) { |
|
578 | + if ( ! $page) { |
|
579 | 579 | $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
580 | 580 | } |
581 | 581 | |
582 | - if (! $action) { |
|
582 | + if ( ! $action) { |
|
583 | 583 | $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
584 | 584 | } |
585 | 585 | |
586 | 586 | $action = empty($action) ? 'default' : $action; |
587 | 587 | |
588 | 588 | |
589 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
589 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
590 | 590 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
591 | 591 | $help_text = ! $help_text ? '' : $help_text; |
592 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__( |
|
592 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__( |
|
593 | 593 | 'Click to open the \'Help\' tab for more information about this feature.', |
594 | 594 | 'event_espresso' |
595 | - ) . '" > ' . $help_text . ' </a>'; |
|
595 | + ).'" > '.$help_text.' </a>'; |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | $id = $tour->get_slug(); |
610 | 610 | $stops = $tour->get_stops(); |
611 | 611 | |
612 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
612 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
613 | 613 | |
614 | 614 | foreach ($stops as $stop) { |
615 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
616 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
615 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
616 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
617 | 617 | |
618 | 618 | // if container is set to modal then let's make sure we set the options accordingly |
619 | 619 | if (empty($data_id) && empty($data_class)) { |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | $stop['options']['expose'] = true; |
622 | 622 | } |
623 | 623 | |
624 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
625 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
624 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
625 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
626 | 626 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
627 | 627 | |
628 | 628 | // options |
629 | 629 | if (isset($stop['options']) && is_array($stop['options'])) { |
630 | 630 | $options = ' data-options="'; |
631 | 631 | foreach ($stop['options'] as $option => $value) { |
632 | - $options .= $option . ':' . $value . ';'; |
|
632 | + $options .= $option.':'.$value.';'; |
|
633 | 633 | } |
634 | 634 | $options .= '"'; |
635 | 635 | } else { |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | } |
638 | 638 | |
639 | 639 | // let's put all together |
640 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
640 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | $content .= '</ol>'; |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | */ |
662 | 662 | public static function status_legend($status_array, $active_status = '') |
663 | 663 | { |
664 | - if (! is_array($status_array)) { |
|
664 | + if ( ! is_array($status_array)) { |
|
665 | 665 | throw new EE_Error(esc_html__( |
666 | 666 | 'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
667 | 667 | 'event_espresso' |
@@ -670,25 +670,25 @@ discard block |
||
670 | 670 | |
671 | 671 | $setup_array = array(); |
672 | 672 | foreach ($status_array as $item => $status) { |
673 | - $setup_array[ $item ] = array( |
|
674 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
673 | + $setup_array[$item] = array( |
|
674 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
675 | 675 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
676 | 676 | 'status' => $status, |
677 | 677 | ); |
678 | 678 | } |
679 | 679 | |
680 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
681 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
682 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
680 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
681 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
682 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
683 | 683 | foreach ($setup_array as $item => $details) { |
684 | 684 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
685 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
686 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
687 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
688 | - $content .= '</dt>' . "\n"; |
|
685 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
686 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
687 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
688 | + $content .= '</dt>'."\n"; |
|
689 | 689 | } |
690 | - $content .= '</dl>' . "\n"; |
|
691 | - $content .= '</div>' . "\n"; |
|
690 | + $content .= '</dl>'."\n"; |
|
691 | + $content .= '</div>'."\n"; |
|
692 | 692 | return $content; |
693 | 693 | } |
694 | 694 | |
@@ -833,8 +833,8 @@ discard block |
||
833 | 833 | ); |
834 | 834 | } else { |
835 | 835 | $items_label = array( |
836 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
837 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
836 | + 'single' => '1 '.esc_html($items_label['single']), |
|
837 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
838 | 838 | ); |
839 | 839 | } |
840 | 840 | |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | |
847 | 847 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
848 | 848 | |
849 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
849 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
850 | 850 | |
851 | 851 | if ($current === 1) { |
852 | 852 | $disable_first = ' disabled'; |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | |
858 | 858 | $page_links[] = sprintf( |
859 | 859 | "<a class='%s' title='%s' href='%s'>%s</a>", |
860 | - 'first-page' . $disable_first, |
|
860 | + 'first-page'.$disable_first, |
|
861 | 861 | esc_attr__('Go to the first page', 'event_espresso'), |
862 | 862 | esc_url(remove_query_arg($paged_arg_name, $url)), |
863 | 863 | '«' |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | |
866 | 866 | $page_links[] = sprintf( |
867 | 867 | '<a class="%s" title="%s" href="%s">%s</a>', |
868 | - 'prev-page' . $disable_first, |
|
868 | + 'prev-page'.$disable_first, |
|
869 | 869 | esc_attr__('Go to the previous page', 'event_espresso'), |
870 | 870 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
871 | 871 | '‹' |
872 | 872 | ); |
873 | 873 | |
874 | - if (! $show_num_field) { |
|
874 | + if ( ! $show_num_field) { |
|
875 | 875 | $html_current_page = $current; |
876 | 876 | } else { |
877 | 877 | $html_current_page = sprintf( |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | '<span class="total-pages">%s</span>', |
887 | 887 | number_format_i18n($total_pages) |
888 | 888 | ); |
889 | - $page_links[] = sprintf( |
|
889 | + $page_links[] = sprintf( |
|
890 | 890 | _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'), |
891 | 891 | $html_current_page, |
892 | 892 | $html_total_pages, |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | |
897 | 897 | $page_links[] = sprintf( |
898 | 898 | '<a class="%s" title="%s" href="%s">%s</a>', |
899 | - 'next-page' . $disable_last, |
|
899 | + 'next-page'.$disable_last, |
|
900 | 900 | esc_attr__('Go to the next page', 'event_espresso'), |
901 | 901 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
902 | 902 | '›' |
@@ -904,13 +904,13 @@ discard block |
||
904 | 904 | |
905 | 905 | $page_links[] = sprintf( |
906 | 906 | '<a class="%s" title="%s" href="%s">%s</a>', |
907 | - 'last-page' . $disable_last, |
|
907 | + 'last-page'.$disable_last, |
|
908 | 908 | esc_attr__('Go to the last page', 'event_espresso'), |
909 | 909 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
910 | 910 | '»' |
911 | 911 | ); |
912 | 912 | |
913 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
913 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
914 | 914 | // set page class |
915 | 915 | if ($total_pages) { |
916 | 916 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | $page_class = ' no-pages'; |
919 | 919 | } |
920 | 920 | |
921 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
921 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
922 | 922 | } |
923 | 923 | |
924 | 924 | |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
931 | 931 | { |
932 | 932 | $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
933 | - if (! $admin && |
|
933 | + if ( ! $admin && |
|
934 | 934 | ! apply_filters( |
935 | 935 | 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
936 | 936 | EE_Registry::instance()->CFG->admin->show_reg_footer |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | ); |
956 | 956 | $powered_by = apply_filters( |
957 | 957 | 'FHEE__EEH_Template__powered_by_event_espresso_text', |
958 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
958 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso' |
|
959 | 959 | ); |
960 | 960 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
961 | 961 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | |
981 | 981 | |
982 | 982 | |
983 | -if (! function_exists('espresso_pagination')) { |
|
983 | +if ( ! function_exists('espresso_pagination')) { |
|
984 | 984 | /** |
985 | 985 | * espresso_pagination |
986 | 986 | * |
@@ -1008,6 +1008,6 @@ discard block |
||
1008 | 1008 | 'add_fragment' => '', |
1009 | 1009 | ) |
1010 | 1010 | ); |
1011 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
1011 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
1012 | 1012 | } |
1013 | 1013 | } |
1014 | 1014 | \ No newline at end of file |
@@ -24,666 +24,666 @@ |
||
24 | 24 | class EEH_File extends EEH_Base implements EEHI_File |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string $_credentials_form |
|
29 | - */ |
|
30 | - private static $_credentials_form; |
|
31 | - |
|
32 | - protected static $_wp_filesystem_direct; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param string|null $filepath the filepath we want to work in. If its in the |
|
36 | - * wp uploads directory, we'll want to just use the filesystem directly. |
|
37 | - * If not provided, we have to assume its not in the uploads directory |
|
38 | - * @throws EE_Error if filesystem credentials are required |
|
39 | - * @return WP_Filesystem_Base |
|
40 | - */ |
|
41 | - private static function _get_wp_filesystem($filepath = null) |
|
42 | - { |
|
43 | - if (apply_filters( |
|
44 | - 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
45 | - $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
46 | - $filepath |
|
47 | - ) ) { |
|
48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | - $method = 'direct'; |
|
51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
52 | - // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
53 | - if (! defined('FS_CHMOD_DIR')) { |
|
54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
55 | - } |
|
56 | - if (! defined('FS_CHMOD_FILE')) { |
|
57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
58 | - } |
|
59 | - require_once($wp_filesystem_direct_file); |
|
60 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
61 | - } |
|
62 | - return EEH_File::$_wp_filesystem_direct; |
|
63 | - } |
|
64 | - global $wp_filesystem; |
|
65 | - // no filesystem setup ??? |
|
66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | - // if some eager beaver's just trying to get in there too early... |
|
68 | - // let them do it, because we are one of those eager beavers! :P |
|
69 | - /** |
|
70 | - * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
71 | - * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
72 | - * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
73 | - * 'wp_loaded' is too much work on a BETA milestone. |
|
74 | - * So this fix is expected to work if the WP files are owned by the server user, |
|
75 | - * but probably not if the user needs to enter their FTP credentials to modify files |
|
76 | - * and there may be troubles if the WP files are owned by a different user |
|
77 | - * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
78 | - */ |
|
79 | - if (false && ! did_action('wp_loaded')) { |
|
80 | - $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
81 | - if (WP_DEBUG) { |
|
82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | - } |
|
84 | - throw new EE_Error($msg); |
|
85 | - } else { |
|
86 | - // should be loaded if we are past the wp_loaded hook... |
|
87 | - if (! function_exists('WP_Filesystem')) { |
|
88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
90 | - } |
|
91 | - // turn on output buffering so that we can capture the credentials form |
|
92 | - ob_start(); |
|
93 | - $credentials = request_filesystem_credentials(''); |
|
94 | - // store credentials form for the time being |
|
95 | - EEH_File::$_credentials_form = ob_get_clean(); |
|
96 | - // basically check for direct or previously configured access |
|
97 | - if (! WP_Filesystem($credentials)) { |
|
98 | - // if credentials do NOT exist |
|
99 | - if ($credentials === false) { |
|
100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
101 | - throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
102 | - } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
104 | - throw new EE_Error( |
|
105 | - sprintf( |
|
106 | - __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
107 | - $wp_filesystem->errors->get_error_message() |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - return $wp_filesystem; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * display_request_filesystem_credentials_form |
|
119 | - */ |
|
120 | - public static function display_request_filesystem_credentials_form() |
|
121 | - { |
|
122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * verify_filepath_and_permissions |
|
131 | - * checks that a file is readable and has sufficient file permissions set to access |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @param string $full_file_path - full server path to the folder or file |
|
135 | - * @param string $file_name - name of file if checking a file |
|
136 | - * @param string $file_ext - file extension (ie: "php") if checking a file |
|
137 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
138 | - * @throws EE_Error if filesystem credentials are required |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
142 | - { |
|
143 | - // load WP_Filesystem and set file permissions |
|
144 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
145 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
148 | - $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
149 | - $msg = sprintf( |
|
150 | - __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
151 | - $file_name, |
|
152 | - '<br />' |
|
153 | - ); |
|
154 | - if (EEH_File::exists($full_file_path)) { |
|
155 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
156 | - } else { |
|
157 | - // no file permissions means the file was not found |
|
158 | - $msg .= sprintf( |
|
159 | - __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
160 | - $full_file_path |
|
161 | - ); |
|
162 | - } |
|
163 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
164 | - throw new EE_Error($msg . '||' . $msg); |
|
165 | - } |
|
166 | - return false; |
|
167 | - } |
|
168 | - return true; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
175 | - * |
|
176 | - * @access private |
|
177 | - * @param string $full_file_path - full server path to the folder or file |
|
178 | - * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
179 | - * @throws EE_Error if filesystem credentials are required |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
183 | - { |
|
184 | - // load WP_Filesystem and set file permissions |
|
185 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
186 | - // check file permissions |
|
187 | - $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
188 | - if ($perms) { |
|
189 | - // file permissions exist, but way be set incorrectly |
|
190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
191 | - $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
192 | - return sprintf( |
|
193 | - __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
194 | - $type_of_file, |
|
195 | - $perms |
|
196 | - ); |
|
197 | - } else { |
|
198 | - // file exists but file permissions could not be read ?!?! |
|
199 | - return sprintf( |
|
200 | - __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
201 | - $full_file_path |
|
202 | - ); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * ensure_folder_exists_and_is_writable |
|
210 | - * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
211 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
212 | - * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
213 | - * @param string $folder |
|
214 | - * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
215 | - * can't write to it |
|
216 | - * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
217 | - */ |
|
218 | - public static function ensure_folder_exists_and_is_writable($folder = '') |
|
219 | - { |
|
220 | - if (empty($folder)) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - // remove ending / |
|
224 | - $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
225 | - $parent_folder = EEH_File::get_parent_folder($folder); |
|
226 | - // add / to folder |
|
227 | - $folder = EEH_File::end_with_directory_separator($folder); |
|
228 | - $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | - // ok so it doesn't exist. Does its parent? Can we write to it? |
|
231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | - return false; |
|
233 | - } |
|
234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | - return false; |
|
236 | - } else { |
|
237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
239 | - $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
240 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
241 | - throw new EE_Error($msg); |
|
242 | - } |
|
243 | - return false; |
|
244 | - } |
|
245 | - EEH_File::add_index_file($folder); |
|
246 | - } |
|
247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | - return false; |
|
249 | - } |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * verify_is_writable - checks if a file or folder is writable |
|
257 | - * @param string $full_path - full server path to file or folder |
|
258 | - * @param string $file_or_folder - whether checking a file or folder |
|
259 | - * @throws EE_Error if filesystem credentials are required |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
263 | - { |
|
264 | - // load WP_Filesystem and set file permissions |
|
265 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
266 | - $full_path = EEH_File::standardise_directory_separators($full_path); |
|
267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
269 | - $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
270 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
271 | - throw new EE_Error($msg); |
|
272 | - } |
|
273 | - return false; |
|
274 | - } |
|
275 | - return true; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * ensure_file_exists_and_is_writable |
|
282 | - * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
283 | - * Also ensures all the parent folders exist, and if not tries to create them. |
|
284 | - * @param string $full_file_path |
|
285 | - * @throws EE_Error if filesystem credentials are required |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
289 | - { |
|
290 | - // load WP_Filesystem and set file permissions |
|
291 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
292 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
293 | - $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
294 | - if (! EEH_File::exists($full_file_path)) { |
|
295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | - return false; |
|
297 | - } |
|
298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
300 | - $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
301 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
302 | - throw new EE_Error($msg); |
|
303 | - } |
|
304 | - return false; |
|
305 | - } |
|
306 | - } |
|
307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | - return false; |
|
309 | - } |
|
310 | - return true; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
315 | - * If provided a folder, gets its parent folder. |
|
316 | - * @param string $file_or_folder_path |
|
317 | - * @return string parent folder, ENDING with a directory separator |
|
318 | - */ |
|
319 | - public static function get_parent_folder($file_or_folder_path) |
|
320 | - { |
|
321 | - // find the last /, ignoring a / on the very end |
|
322 | - // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
323 | - // parent folder, "/var/something/" |
|
324 | - $ds = strlen($file_or_folder_path) > 1 |
|
325 | - ? strrpos($file_or_folder_path, '/', -2) |
|
326 | - : strlen($file_or_folder_path); |
|
327 | - return substr($file_or_folder_path, 0, $ds + 1); |
|
328 | - } |
|
329 | - |
|
330 | - // public static function ensure_folder_exists_recursively( $folder ) { |
|
331 | - // |
|
332 | - // } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * get_file_contents |
|
338 | - * @param string $full_file_path |
|
339 | - * @throws EE_Error if filesystem credentials are required |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public static function get_file_contents($full_file_path = '') |
|
343 | - { |
|
344 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
345 | - if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
346 | - // load WP_Filesystem and set file permissions |
|
347 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
348 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
349 | - } |
|
350 | - return ''; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * write_file |
|
357 | - * @param string $full_file_path |
|
358 | - * @param string $file_contents - the content to be written to the file |
|
359 | - * @param string $file_type |
|
360 | - * @throws EE_Error if filesystem credentials are required |
|
361 | - * @return bool |
|
362 | - */ |
|
363 | - public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
364 | - { |
|
365 | - $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
367 | - $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
370 | - $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
371 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
372 | - throw new EE_Error($msg); |
|
373 | - } |
|
374 | - return false; |
|
375 | - } |
|
376 | - // load WP_Filesystem and set file permissions |
|
377 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
378 | - // write the file |
|
379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
381 | - $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
382 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
383 | - throw new EE_Error($msg); |
|
384 | - } |
|
385 | - return false; |
|
386 | - } |
|
387 | - return true; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Wrapper for WP_Filesystem_Base::delete |
|
392 | - * |
|
393 | - * @param string $filepath |
|
394 | - * @param boolean $recursive |
|
395 | - * @param boolean|string $type 'd' for directory, 'f' for file |
|
396 | - * @throws EE_Error if filesystem credentials are required |
|
397 | - * @return boolean |
|
398 | - */ |
|
399 | - public static function delete($filepath, $recursive = false, $type = false) |
|
400 | - { |
|
401 | - $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
402 | - return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * exists |
|
409 | - * checks if a file exists using the WP filesystem |
|
410 | - * @param string $full_file_path |
|
411 | - * @throws EE_Error if filesystem credentials are required |
|
412 | - * @return bool |
|
413 | - */ |
|
414 | - public static function exists($full_file_path = '') |
|
415 | - { |
|
416 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
417 | - return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * is_readable |
|
424 | - * checks if a file is_readable using the WP filesystem |
|
425 | - * |
|
426 | - * @param string $full_file_path |
|
427 | - * @throws EE_Error if filesystem credentials are required |
|
428 | - * @return bool |
|
429 | - */ |
|
430 | - public static function is_readable($full_file_path = '') |
|
431 | - { |
|
432 | - $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
433 | - if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
434 | - return true; |
|
435 | - } else { |
|
436 | - return false; |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * remove_filename_from_filepath |
|
444 | - * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
445 | - * |
|
446 | - * @param string $full_file_path |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public static function remove_filename_from_filepath($full_file_path = '') |
|
450 | - { |
|
451 | - return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * get_filename_from_filepath. Arguably the same as basename() |
|
457 | - * |
|
458 | - * @param string $full_file_path |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public static function get_filename_from_filepath($full_file_path = '') |
|
462 | - { |
|
463 | - return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * get_file_extension |
|
469 | - * |
|
470 | - * @param string $full_file_path |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public static function get_file_extension($full_file_path = '') |
|
474 | - { |
|
475 | - return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
482 | - * @param string $folder |
|
483 | - * @throws EE_Error if filesystem credentials are required |
|
484 | - * @return bool |
|
485 | - */ |
|
486 | - public static function add_htaccess_deny_from_all($folder = '') |
|
487 | - { |
|
488 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
491 | - return false; |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - return true; |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * Adds an index file to this folder, so folks can't list all the file's contents |
|
500 | - * @param string $folder |
|
501 | - * @throws EE_Error if filesystem credentials are required |
|
502 | - * @return boolean |
|
503 | - */ |
|
504 | - public static function add_index_file($folder) |
|
505 | - { |
|
506 | - $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | - return false; |
|
510 | - } |
|
511 | - } |
|
512 | - return true; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
519 | - * extract that classname. |
|
520 | - * @param string $file_path |
|
521 | - * @return string |
|
522 | - */ |
|
523 | - public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
524 | - { |
|
525 | - // extract file from path |
|
526 | - $filename = basename($file_path); |
|
527 | - // now remove the first period and everything after |
|
528 | - $pos_of_first_period = strpos($filename, '.'); |
|
529 | - return substr($filename, 0, $pos_of_first_period); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * standardise_directory_separators |
|
536 | - * convert all directory separators in a file path. |
|
537 | - * @param string $file_path |
|
538 | - * @return string |
|
539 | - */ |
|
540 | - public static function standardise_directory_separators($file_path) |
|
541 | - { |
|
542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * end_with_directory_separator |
|
549 | - * ensures that file path ends with '/' |
|
550 | - * @param string $file_path |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public static function end_with_directory_separator($file_path) |
|
554 | - { |
|
555 | - return rtrim($file_path, '/\\') . '/'; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
562 | - * @param $file_path |
|
563 | - * @return string |
|
564 | - */ |
|
565 | - public static function standardise_and_end_with_directory_separator($file_path) |
|
566 | - { |
|
567 | - return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * takes the folder name (with or without trailing slash) and finds the files it in, |
|
574 | - * and what the class's name inside of each should be. |
|
575 | - * @param array $folder_paths |
|
576 | - * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
577 | - * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
578 | - * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
579 | - * @throws EE_Error if filesystem credentials are required |
|
580 | - * @return array if $index_numerically == TRUE keys are numeric , |
|
581 | - * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
582 | - * and values are their filepaths |
|
583 | - */ |
|
584 | - public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
585 | - { |
|
586 | - $class_to_folder_path = array(); |
|
587 | - foreach ($folder_paths as $folder_path) { |
|
588 | - $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
589 | - // load WP_Filesystem and set file permissions |
|
590 | - $files_in_folder = glob($folder_path . '*'); |
|
591 | - $class_to_folder_path = array(); |
|
592 | - if ($files_in_folder) { |
|
593 | - foreach ($files_in_folder as $file_path) { |
|
594 | - // only add files, not folders |
|
595 | - if (! is_dir($file_path)) { |
|
596 | - if ($index_numerically) { |
|
597 | - $class_to_folder_path[] = $file_path; |
|
598 | - } else { |
|
599 | - $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
601 | - } |
|
602 | - } |
|
603 | - } |
|
604 | - } |
|
605 | - } |
|
606 | - return $class_to_folder_path; |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
613 | - * @param string $source_file |
|
614 | - * @param string $destination_file |
|
615 | - * @param boolean $overwrite |
|
616 | - * @throws EE_Error if filesystem credentials are required |
|
617 | - * @return boolean success |
|
618 | - */ |
|
619 | - public static function copy($source_file, $destination_file, $overwrite = false) |
|
620 | - { |
|
621 | - $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
622 | - if (! EEH_File::exists($full_source_path)) { |
|
623 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
624 | - $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
625 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
626 | - throw new EE_Error($msg); |
|
627 | - } |
|
628 | - return false; |
|
629 | - } |
|
630 | - |
|
631 | - $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
632 | - $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
633 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
636 | - $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
637 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
638 | - throw new EE_Error($msg); |
|
639 | - } |
|
640 | - return false; |
|
641 | - } |
|
642 | - |
|
643 | - // load WP_Filesystem and set file permissions |
|
644 | - $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
645 | - // write the file |
|
646 | - if (! $wp_filesystem->copy( |
|
647 | - EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
648 | - EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
649 | - $overwrite |
|
650 | - )) { |
|
651 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
652 | - $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
653 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
654 | - throw new EE_Error($msg); |
|
655 | - } |
|
656 | - return false; |
|
657 | - } |
|
658 | - return true; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Reports whether or not the filepath is in the EE uploads folder or not |
|
663 | - * @param string $filepath |
|
664 | - * @return boolean |
|
665 | - */ |
|
666 | - public static function is_in_uploads_folder($filepath) |
|
667 | - { |
|
668 | - $uploads = wp_upload_dir(); |
|
669 | - return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Given a "local" filepath (what you probably thought was the only filepath), |
|
674 | - * converts it into a "remote" filepath (the filepath the currently-in-use |
|
675 | - * $wp_filesystem needs to use access the folder or file). |
|
676 | - * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
677 | - * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
678 | - * is in use, so you need to provide it |
|
679 | - * @param string $local_filepath the filepath to the folder/file locally |
|
680 | - * @throws EE_Error if filesystem credentials are required |
|
681 | - * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
682 | - * ftp or ssh, will use to access the folder |
|
683 | - */ |
|
684 | - public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
685 | - { |
|
686 | - $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | - } |
|
27 | + /** |
|
28 | + * @var string $_credentials_form |
|
29 | + */ |
|
30 | + private static $_credentials_form; |
|
31 | + |
|
32 | + protected static $_wp_filesystem_direct; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param string|null $filepath the filepath we want to work in. If its in the |
|
36 | + * wp uploads directory, we'll want to just use the filesystem directly. |
|
37 | + * If not provided, we have to assume its not in the uploads directory |
|
38 | + * @throws EE_Error if filesystem credentials are required |
|
39 | + * @return WP_Filesystem_Base |
|
40 | + */ |
|
41 | + private static function _get_wp_filesystem($filepath = null) |
|
42 | + { |
|
43 | + if (apply_filters( |
|
44 | + 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
|
45 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
46 | + $filepath |
|
47 | + ) ) { |
|
48 | + if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | + $method = 'direct'; |
|
51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
52 | + // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
|
53 | + if (! defined('FS_CHMOD_DIR')) { |
|
54 | + define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
55 | + } |
|
56 | + if (! defined('FS_CHMOD_FILE')) { |
|
57 | + define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
58 | + } |
|
59 | + require_once($wp_filesystem_direct_file); |
|
60 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
61 | + } |
|
62 | + return EEH_File::$_wp_filesystem_direct; |
|
63 | + } |
|
64 | + global $wp_filesystem; |
|
65 | + // no filesystem setup ??? |
|
66 | + if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | + // if some eager beaver's just trying to get in there too early... |
|
68 | + // let them do it, because we are one of those eager beavers! :P |
|
69 | + /** |
|
70 | + * more explanations are probably merited. http://codex.wordpress.org/Filesystem_API#Initializing_WP_Filesystem_Base |
|
71 | + * says WP_Filesystem should be used after 'wp_loaded', but currently EE's activation process |
|
72 | + * is setup to mostly happen on 'init', and refactoring to have it happen on |
|
73 | + * 'wp_loaded' is too much work on a BETA milestone. |
|
74 | + * So this fix is expected to work if the WP files are owned by the server user, |
|
75 | + * but probably not if the user needs to enter their FTP credentials to modify files |
|
76 | + * and there may be troubles if the WP files are owned by a different user |
|
77 | + * than the server user. But both of these issues should exist in 4.4 and earlier too |
|
78 | + */ |
|
79 | + if (false && ! did_action('wp_loaded')) { |
|
80 | + $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
|
81 | + if (WP_DEBUG) { |
|
82 | + $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | + } |
|
84 | + throw new EE_Error($msg); |
|
85 | + } else { |
|
86 | + // should be loaded if we are past the wp_loaded hook... |
|
87 | + if (! function_exists('WP_Filesystem')) { |
|
88 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | + require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
90 | + } |
|
91 | + // turn on output buffering so that we can capture the credentials form |
|
92 | + ob_start(); |
|
93 | + $credentials = request_filesystem_credentials(''); |
|
94 | + // store credentials form for the time being |
|
95 | + EEH_File::$_credentials_form = ob_get_clean(); |
|
96 | + // basically check for direct or previously configured access |
|
97 | + if (! WP_Filesystem($credentials)) { |
|
98 | + // if credentials do NOT exist |
|
99 | + if ($credentials === false) { |
|
100 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
101 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
102 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
103 | + add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
104 | + throw new EE_Error( |
|
105 | + sprintf( |
|
106 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
107 | + $wp_filesystem->errors->get_error_message() |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + return $wp_filesystem; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * display_request_filesystem_credentials_form |
|
119 | + */ |
|
120 | + public static function display_request_filesystem_credentials_form() |
|
121 | + { |
|
122 | + if (! empty(EEH_File::$_credentials_form)) { |
|
123 | + echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * verify_filepath_and_permissions |
|
131 | + * checks that a file is readable and has sufficient file permissions set to access |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @param string $full_file_path - full server path to the folder or file |
|
135 | + * @param string $file_name - name of file if checking a file |
|
136 | + * @param string $file_ext - file extension (ie: "php") if checking a file |
|
137 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
138 | + * @throws EE_Error if filesystem credentials are required |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') |
|
142 | + { |
|
143 | + // load WP_Filesystem and set file permissions |
|
144 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
145 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
146 | + if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | + $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
148 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
149 | + $msg = sprintf( |
|
150 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
151 | + $file_name, |
|
152 | + '<br />' |
|
153 | + ); |
|
154 | + if (EEH_File::exists($full_file_path)) { |
|
155 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
156 | + } else { |
|
157 | + // no file permissions means the file was not found |
|
158 | + $msg .= sprintf( |
|
159 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
160 | + $full_file_path |
|
161 | + ); |
|
162 | + } |
|
163 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
164 | + throw new EE_Error($msg . '||' . $msg); |
|
165 | + } |
|
166 | + return false; |
|
167 | + } |
|
168 | + return true; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * _permissions_error_for_unreadable_filepath - attempts to determine why permissions are set incorrectly for a file or folder |
|
175 | + * |
|
176 | + * @access private |
|
177 | + * @param string $full_file_path - full server path to the folder or file |
|
178 | + * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
|
179 | + * @throws EE_Error if filesystem credentials are required |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') |
|
183 | + { |
|
184 | + // load WP_Filesystem and set file permissions |
|
185 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
186 | + // check file permissions |
|
187 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
188 | + if ($perms) { |
|
189 | + // file permissions exist, but way be set incorrectly |
|
190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
191 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
192 | + return sprintf( |
|
193 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
194 | + $type_of_file, |
|
195 | + $perms |
|
196 | + ); |
|
197 | + } else { |
|
198 | + // file exists but file permissions could not be read ?!?! |
|
199 | + return sprintf( |
|
200 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
201 | + $full_file_path |
|
202 | + ); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * ensure_folder_exists_and_is_writable |
|
210 | + * ensures that a folder exists and is writable, will attempt to create folder if it does not exist |
|
211 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
212 | + * Also, if this function creates the folder, adds a .htaccess file and index.html file |
|
213 | + * @param string $folder |
|
214 | + * @throws EE_Error if the folder exists and is writeable, but for some reason we |
|
215 | + * can't write to it |
|
216 | + * @return bool false if folder isn't writable; true if it exists and is writeable, |
|
217 | + */ |
|
218 | + public static function ensure_folder_exists_and_is_writable($folder = '') |
|
219 | + { |
|
220 | + if (empty($folder)) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + // remove ending / |
|
224 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
225 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
226 | + // add / to folder |
|
227 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
228 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
229 | + if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | + // ok so it doesn't exist. Does its parent? Can we write to it? |
|
231 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | + return false; |
|
233 | + } |
|
234 | + if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | + return false; |
|
236 | + } else { |
|
237 | + if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
239 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
240 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
241 | + throw new EE_Error($msg); |
|
242 | + } |
|
243 | + return false; |
|
244 | + } |
|
245 | + EEH_File::add_index_file($folder); |
|
246 | + } |
|
247 | + } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | + return false; |
|
249 | + } |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * verify_is_writable - checks if a file or folder is writable |
|
257 | + * @param string $full_path - full server path to file or folder |
|
258 | + * @param string $file_or_folder - whether checking a file or folder |
|
259 | + * @throws EE_Error if filesystem credentials are required |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') |
|
263 | + { |
|
264 | + // load WP_Filesystem and set file permissions |
|
265 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
266 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
267 | + if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
269 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
270 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
271 | + throw new EE_Error($msg); |
|
272 | + } |
|
273 | + return false; |
|
274 | + } |
|
275 | + return true; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * ensure_file_exists_and_is_writable |
|
282 | + * ensures that a file exists and is writable, will attempt to create file if it does not exist. |
|
283 | + * Also ensures all the parent folders exist, and if not tries to create them. |
|
284 | + * @param string $full_file_path |
|
285 | + * @throws EE_Error if filesystem credentials are required |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') |
|
289 | + { |
|
290 | + // load WP_Filesystem and set file permissions |
|
291 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
292 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
293 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
294 | + if (! EEH_File::exists($full_file_path)) { |
|
295 | + if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | + return false; |
|
297 | + } |
|
298 | + if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
300 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
301 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
302 | + throw new EE_Error($msg); |
|
303 | + } |
|
304 | + return false; |
|
305 | + } |
|
306 | + } |
|
307 | + if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | + return false; |
|
309 | + } |
|
310 | + return true; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets the parent folder. If provided with file, gets the folder that contains it. |
|
315 | + * If provided a folder, gets its parent folder. |
|
316 | + * @param string $file_or_folder_path |
|
317 | + * @return string parent folder, ENDING with a directory separator |
|
318 | + */ |
|
319 | + public static function get_parent_folder($file_or_folder_path) |
|
320 | + { |
|
321 | + // find the last /, ignoring a / on the very end |
|
322 | + // eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
|
323 | + // parent folder, "/var/something/" |
|
324 | + $ds = strlen($file_or_folder_path) > 1 |
|
325 | + ? strrpos($file_or_folder_path, '/', -2) |
|
326 | + : strlen($file_or_folder_path); |
|
327 | + return substr($file_or_folder_path, 0, $ds + 1); |
|
328 | + } |
|
329 | + |
|
330 | + // public static function ensure_folder_exists_recursively( $folder ) { |
|
331 | + // |
|
332 | + // } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * get_file_contents |
|
338 | + * @param string $full_file_path |
|
339 | + * @throws EE_Error if filesystem credentials are required |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public static function get_file_contents($full_file_path = '') |
|
343 | + { |
|
344 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
345 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
346 | + // load WP_Filesystem and set file permissions |
|
347 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
348 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
349 | + } |
|
350 | + return ''; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * write_file |
|
357 | + * @param string $full_file_path |
|
358 | + * @param string $file_contents - the content to be written to the file |
|
359 | + * @param string $file_type |
|
360 | + * @throws EE_Error if filesystem credentials are required |
|
361 | + * @return bool |
|
362 | + */ |
|
363 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
|
364 | + { |
|
365 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
367 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
368 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
370 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
371 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
372 | + throw new EE_Error($msg); |
|
373 | + } |
|
374 | + return false; |
|
375 | + } |
|
376 | + // load WP_Filesystem and set file permissions |
|
377 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
378 | + // write the file |
|
379 | + if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
381 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
382 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
383 | + throw new EE_Error($msg); |
|
384 | + } |
|
385 | + return false; |
|
386 | + } |
|
387 | + return true; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Wrapper for WP_Filesystem_Base::delete |
|
392 | + * |
|
393 | + * @param string $filepath |
|
394 | + * @param boolean $recursive |
|
395 | + * @param boolean|string $type 'd' for directory, 'f' for file |
|
396 | + * @throws EE_Error if filesystem credentials are required |
|
397 | + * @return boolean |
|
398 | + */ |
|
399 | + public static function delete($filepath, $recursive = false, $type = false) |
|
400 | + { |
|
401 | + $wp_filesystem = EEH_File::_get_wp_filesystem(); |
|
402 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? true : false; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * exists |
|
409 | + * checks if a file exists using the WP filesystem |
|
410 | + * @param string $full_file_path |
|
411 | + * @throws EE_Error if filesystem credentials are required |
|
412 | + * @return bool |
|
413 | + */ |
|
414 | + public static function exists($full_file_path = '') |
|
415 | + { |
|
416 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
417 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? true : false; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * is_readable |
|
424 | + * checks if a file is_readable using the WP filesystem |
|
425 | + * |
|
426 | + * @param string $full_file_path |
|
427 | + * @throws EE_Error if filesystem credentials are required |
|
428 | + * @return bool |
|
429 | + */ |
|
430 | + public static function is_readable($full_file_path = '') |
|
431 | + { |
|
432 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
433 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
434 | + return true; |
|
435 | + } else { |
|
436 | + return false; |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * remove_filename_from_filepath |
|
444 | + * given a full path to a file including the filename itself, this removes the filename and returns the path, up to, but NOT including the filename OR slash |
|
445 | + * |
|
446 | + * @param string $full_file_path |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public static function remove_filename_from_filepath($full_file_path = '') |
|
450 | + { |
|
451 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * get_filename_from_filepath. Arguably the same as basename() |
|
457 | + * |
|
458 | + * @param string $full_file_path |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public static function get_filename_from_filepath($full_file_path = '') |
|
462 | + { |
|
463 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * get_file_extension |
|
469 | + * |
|
470 | + * @param string $full_file_path |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public static function get_file_extension($full_file_path = '') |
|
474 | + { |
|
475 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * add_htaccess_deny_from_all so the webserver cannot access this folder |
|
482 | + * @param string $folder |
|
483 | + * @throws EE_Error if filesystem credentials are required |
|
484 | + * @return bool |
|
485 | + */ |
|
486 | + public static function add_htaccess_deny_from_all($folder = '') |
|
487 | + { |
|
488 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
489 | + if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | + if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
491 | + return false; |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + return true; |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * Adds an index file to this folder, so folks can't list all the file's contents |
|
500 | + * @param string $folder |
|
501 | + * @throws EE_Error if filesystem credentials are required |
|
502 | + * @return boolean |
|
503 | + */ |
|
504 | + public static function add_index_file($folder) |
|
505 | + { |
|
506 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
507 | + if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | + if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | + return false; |
|
510 | + } |
|
511 | + } |
|
512 | + return true; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Given that the file in $file_path has the normal name, (ie, CLASSNAME.whatever.php), |
|
519 | + * extract that classname. |
|
520 | + * @param string $file_path |
|
521 | + * @return string |
|
522 | + */ |
|
523 | + public static function get_classname_from_filepath_with_standard_filename($file_path) |
|
524 | + { |
|
525 | + // extract file from path |
|
526 | + $filename = basename($file_path); |
|
527 | + // now remove the first period and everything after |
|
528 | + $pos_of_first_period = strpos($filename, '.'); |
|
529 | + return substr($filename, 0, $pos_of_first_period); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * standardise_directory_separators |
|
536 | + * convert all directory separators in a file path. |
|
537 | + * @param string $file_path |
|
538 | + * @return string |
|
539 | + */ |
|
540 | + public static function standardise_directory_separators($file_path) |
|
541 | + { |
|
542 | + return str_replace(array( '\\', '/' ), '/', $file_path); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * end_with_directory_separator |
|
549 | + * ensures that file path ends with '/' |
|
550 | + * @param string $file_path |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public static function end_with_directory_separator($file_path) |
|
554 | + { |
|
555 | + return rtrim($file_path, '/\\') . '/'; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * shorthand for both EEH_FIle::end_with_directory_separator AND EEH_File::standardise_directory_separators |
|
562 | + * @param $file_path |
|
563 | + * @return string |
|
564 | + */ |
|
565 | + public static function standardise_and_end_with_directory_separator($file_path) |
|
566 | + { |
|
567 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * takes the folder name (with or without trailing slash) and finds the files it in, |
|
574 | + * and what the class's name inside of each should be. |
|
575 | + * @param array $folder_paths |
|
576 | + * @param boolean $index_numerically if TRUE, the returned array will be indexed numerically; |
|
577 | + * if FALSE (Default), returned array will be indexed by the filenames minus extensions. |
|
578 | + * Set it TRUE if you know there are files in the directory with the same name but different extensions |
|
579 | + * @throws EE_Error if filesystem credentials are required |
|
580 | + * @return array if $index_numerically == TRUE keys are numeric , |
|
581 | + * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
|
582 | + * and values are their filepaths |
|
583 | + */ |
|
584 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = false) |
|
585 | + { |
|
586 | + $class_to_folder_path = array(); |
|
587 | + foreach ($folder_paths as $folder_path) { |
|
588 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
589 | + // load WP_Filesystem and set file permissions |
|
590 | + $files_in_folder = glob($folder_path . '*'); |
|
591 | + $class_to_folder_path = array(); |
|
592 | + if ($files_in_folder) { |
|
593 | + foreach ($files_in_folder as $file_path) { |
|
594 | + // only add files, not folders |
|
595 | + if (! is_dir($file_path)) { |
|
596 | + if ($index_numerically) { |
|
597 | + $class_to_folder_path[] = $file_path; |
|
598 | + } else { |
|
599 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
600 | + $class_to_folder_path[ $classname ] = $file_path; |
|
601 | + } |
|
602 | + } |
|
603 | + } |
|
604 | + } |
|
605 | + } |
|
606 | + return $class_to_folder_path; |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Copies a file. Mostly a wrapper of WP_Filesystem::copy |
|
613 | + * @param string $source_file |
|
614 | + * @param string $destination_file |
|
615 | + * @param boolean $overwrite |
|
616 | + * @throws EE_Error if filesystem credentials are required |
|
617 | + * @return boolean success |
|
618 | + */ |
|
619 | + public static function copy($source_file, $destination_file, $overwrite = false) |
|
620 | + { |
|
621 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
622 | + if (! EEH_File::exists($full_source_path)) { |
|
623 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
624 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
625 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
626 | + throw new EE_Error($msg); |
|
627 | + } |
|
628 | + return false; |
|
629 | + } |
|
630 | + |
|
631 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
632 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
633 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
634 | + if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
636 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
637 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
638 | + throw new EE_Error($msg); |
|
639 | + } |
|
640 | + return false; |
|
641 | + } |
|
642 | + |
|
643 | + // load WP_Filesystem and set file permissions |
|
644 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
645 | + // write the file |
|
646 | + if (! $wp_filesystem->copy( |
|
647 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
648 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
649 | + $overwrite |
|
650 | + )) { |
|
651 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
652 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
653 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
654 | + throw new EE_Error($msg); |
|
655 | + } |
|
656 | + return false; |
|
657 | + } |
|
658 | + return true; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Reports whether or not the filepath is in the EE uploads folder or not |
|
663 | + * @param string $filepath |
|
664 | + * @return boolean |
|
665 | + */ |
|
666 | + public static function is_in_uploads_folder($filepath) |
|
667 | + { |
|
668 | + $uploads = wp_upload_dir(); |
|
669 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Given a "local" filepath (what you probably thought was the only filepath), |
|
674 | + * converts it into a "remote" filepath (the filepath the currently-in-use |
|
675 | + * $wp_filesystem needs to use access the folder or file). |
|
676 | + * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins |
|
677 | + * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one |
|
678 | + * is in use, so you need to provide it |
|
679 | + * @param string $local_filepath the filepath to the folder/file locally |
|
680 | + * @throws EE_Error if filesystem credentials are required |
|
681 | + * @return string the remote filepath (eg the filepath the filesystem method, eg |
|
682 | + * ftp or ssh, will use to access the folder |
|
683 | + */ |
|
684 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) |
|
685 | + { |
|
686 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
687 | + return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | + } |
|
689 | 689 | } |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
45 | 45 | $filepath && EEH_File::is_in_uploads_folder($filepath), |
46 | 46 | $filepath |
47 | - ) ) { |
|
48 | - if (! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
47 | + )) { |
|
48 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
49 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
50 | 50 | $method = 'direct'; |
51 | - $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); |
|
51 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
52 | 52 | // check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
53 | - if (! defined('FS_CHMOD_DIR')) { |
|
54 | - define('FS_CHMOD_DIR', ( fileperms(ABSPATH) & 0777 | 0755 )); |
|
53 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
54 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
55 | 55 | } |
56 | - if (! defined('FS_CHMOD_FILE')) { |
|
57 | - define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644 )); |
|
56 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
57 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
58 | 58 | } |
59 | 59 | require_once($wp_filesystem_direct_file); |
60 | 60 | EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | global $wp_filesystem; |
65 | 65 | // no filesystem setup ??? |
66 | - if (! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
66 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
67 | 67 | // if some eager beaver's just trying to get in there too early... |
68 | 68 | // let them do it, because we are one of those eager beavers! :P |
69 | 69 | /** |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | if (false && ! did_action('wp_loaded')) { |
80 | 80 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
81 | 81 | if (WP_DEBUG) { |
82 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
82 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
83 | 83 | } |
84 | 84 | throw new EE_Error($msg); |
85 | 85 | } else { |
86 | 86 | // should be loaded if we are past the wp_loaded hook... |
87 | - if (! function_exists('WP_Filesystem')) { |
|
88 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
89 | - require_once(ABSPATH . 'wp-admin/includes/template.php'); |
|
87 | + if ( ! function_exists('WP_Filesystem')) { |
|
88 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
89 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
90 | 90 | } |
91 | 91 | // turn on output buffering so that we can capture the credentials form |
92 | 92 | ob_start(); |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | // store credentials form for the time being |
95 | 95 | EEH_File::$_credentials_form = ob_get_clean(); |
96 | 96 | // basically check for direct or previously configured access |
97 | - if (! WP_Filesystem($credentials)) { |
|
97 | + if ( ! WP_Filesystem($credentials)) { |
|
98 | 98 | // if credentials do NOT exist |
99 | 99 | if ($credentials === false) { |
100 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
100 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
101 | 101 | throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
102 | 102 | } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
103 | - add_action('admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999); |
|
103 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
104 | 104 | throw new EE_Error( |
105 | 105 | sprintf( |
106 | 106 | __('WP Filesystem Error: $1%s', 'event_espresso'), |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public static function display_request_filesystem_credentials_form() |
121 | 121 | { |
122 | - if (! empty(EEH_File::$_credentials_form)) { |
|
123 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
122 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
123 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | // load WP_Filesystem and set file permissions |
144 | 144 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
145 | 145 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
146 | - if (! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | - $file_name = ! empty($type_of_file) ? $file_name . ' ' . $type_of_file : $file_name; |
|
146 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
147 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
148 | 148 | $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
149 | 149 | $msg = sprintf( |
150 | 150 | __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | ); |
162 | 162 | } |
163 | 163 | if (defined('WP_DEBUG') && WP_DEBUG) { |
164 | - throw new EE_Error($msg . '||' . $msg); |
|
164 | + throw new EE_Error($msg.'||'.$msg); |
|
165 | 165 | } |
166 | 166 | return false; |
167 | 167 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
188 | 188 | if ($perms) { |
189 | 189 | // file permissions exist, but way be set incorrectly |
190 | - $type_of_file = ! empty($type_of_file) ? $type_of_file . ' ' : ''; |
|
190 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
191 | 191 | $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
192 | 192 | return sprintf( |
193 | 193 | __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
@@ -226,15 +226,15 @@ discard block |
||
226 | 226 | // add / to folder |
227 | 227 | $folder = EEH_File::end_with_directory_separator($folder); |
228 | 228 | $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
229 | - if (! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
229 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | 230 | // ok so it doesn't exist. Does its parent? Can we write to it? |
231 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
231 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | - if (! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
234 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
235 | 235 | return false; |
236 | 236 | } else { |
237 | - if (! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
237 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
238 | 238 | if (defined('WP_DEBUG') && WP_DEBUG) { |
239 | 239 | $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
240 | 240 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | EEH_File::add_index_file($folder); |
246 | 246 | } |
247 | - } elseif (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
247 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | return true; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | // load WP_Filesystem and set file permissions |
265 | 265 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
266 | 266 | $full_path = EEH_File::standardise_directory_separators($full_path); |
267 | - if (! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
267 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
268 | 268 | if (defined('WP_DEBUG') && WP_DEBUG) { |
269 | 269 | $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
270 | 270 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
@@ -291,11 +291,11 @@ discard block |
||
291 | 291 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
292 | 292 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
293 | 293 | $parent_folder = EEH_File::get_parent_folder($full_file_path); |
294 | - if (! EEH_File::exists($full_file_path)) { |
|
295 | - if (! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
294 | + if ( ! EEH_File::exists($full_file_path)) { |
|
295 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | - if (! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
298 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
299 | 299 | if (defined('WP_DEBUG') && WP_DEBUG) { |
300 | 300 | $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
301 | 301 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | } |
307 | - if (! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
307 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | return true; |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') |
364 | 364 | { |
365 | 365 | $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
366 | - $file_type = ! empty($file_type) ? rtrim($file_type, ' ') . ' ' : ''; |
|
366 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
367 | 367 | $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
368 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
368 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
369 | 369 | if (defined('WP_DEBUG') && WP_DEBUG) { |
370 | 370 | $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
371 | 371 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | // load WP_Filesystem and set file permissions |
377 | 377 | $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
378 | 378 | // write the file |
379 | - if (! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
379 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
380 | 380 | if (defined('WP_DEBUG') && WP_DEBUG) { |
381 | 381 | $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
382 | 382 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
@@ -486,8 +486,8 @@ discard block |
||
486 | 486 | public static function add_htaccess_deny_from_all($folder = '') |
487 | 487 | { |
488 | 488 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
489 | - if (! EEH_File::exists($folder . '.htaccess')) { |
|
490 | - if (! EEH_File::write_to_file($folder . '.htaccess', 'deny from all', '.htaccess')) { |
|
489 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
490 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
491 | 491 | return false; |
492 | 492 | } |
493 | 493 | } |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | public static function add_index_file($folder) |
505 | 505 | { |
506 | 506 | $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
507 | - if (! EEH_File::exists($folder . 'index.php')) { |
|
508 | - if (! EEH_File::write_to_file($folder . 'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
507 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
508 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
509 | 509 | return false; |
510 | 510 | } |
511 | 511 | } |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public static function standardise_directory_separators($file_path) |
541 | 541 | { |
542 | - return str_replace(array( '\\', '/' ), '/', $file_path); |
|
542 | + return str_replace(array('\\', '/'), '/', $file_path); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | */ |
553 | 553 | public static function end_with_directory_separator($file_path) |
554 | 554 | { |
555 | - return rtrim($file_path, '/\\') . '/'; |
|
555 | + return rtrim($file_path, '/\\').'/'; |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | |
@@ -587,17 +587,17 @@ discard block |
||
587 | 587 | foreach ($folder_paths as $folder_path) { |
588 | 588 | $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
589 | 589 | // load WP_Filesystem and set file permissions |
590 | - $files_in_folder = glob($folder_path . '*'); |
|
590 | + $files_in_folder = glob($folder_path.'*'); |
|
591 | 591 | $class_to_folder_path = array(); |
592 | 592 | if ($files_in_folder) { |
593 | 593 | foreach ($files_in_folder as $file_path) { |
594 | 594 | // only add files, not folders |
595 | - if (! is_dir($file_path)) { |
|
595 | + if ( ! is_dir($file_path)) { |
|
596 | 596 | if ($index_numerically) { |
597 | 597 | $class_to_folder_path[] = $file_path; |
598 | 598 | } else { |
599 | 599 | $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
600 | - $class_to_folder_path[ $classname ] = $file_path; |
|
600 | + $class_to_folder_path[$classname] = $file_path; |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | } |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | public static function copy($source_file, $destination_file, $overwrite = false) |
620 | 620 | { |
621 | 621 | $full_source_path = EEH_File::standardise_directory_separators($source_file); |
622 | - if (! EEH_File::exists($full_source_path)) { |
|
622 | + if ( ! EEH_File::exists($full_source_path)) { |
|
623 | 623 | if (defined('WP_DEBUG') && WP_DEBUG) { |
624 | 624 | $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
625 | 625 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
632 | 632 | $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
633 | 633 | EEH_File::ensure_folder_exists_and_is_writable($folder); |
634 | - if (! EEH_File::verify_is_writable($folder, 'folder')) { |
|
634 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
635 | 635 | if (defined('WP_DEBUG') && WP_DEBUG) { |
636 | 636 | $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
637 | 637 | $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | // load WP_Filesystem and set file permissions |
644 | 644 | $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
645 | 645 | // write the file |
646 | - if (! $wp_filesystem->copy( |
|
646 | + if ( ! $wp_filesystem->copy( |
|
647 | 647 | EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
648 | 648 | EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
649 | 649 | $overwrite |
@@ -684,6 +684,6 @@ discard block |
||
684 | 684 | public static function convert_local_filepath_to_remote_filepath($local_filepath) |
685 | 685 | { |
686 | 686 | $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
687 | - return str_replace(WP_CONTENT_DIR . '/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
687 | + return str_replace(WP_CONTENT_DIR.'/', $wp_filesystem->wp_content_dir(), $local_filepath); |
|
688 | 688 | } |
689 | 689 | } |
@@ -15,296 +15,296 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_System object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * $_autoloaders |
|
28 | - * @var array $_autoloaders |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - private static $_autoloaders; |
|
32 | - |
|
33 | - /** |
|
34 | - * set to "paths" to display autoloader class => path mappings |
|
35 | - * set to "times" to display autoloader loading times |
|
36 | - * set to "all" to display both |
|
37 | - * |
|
38 | - * @var string $debug |
|
39 | - * @access private |
|
40 | - */ |
|
41 | - public static $debug = false; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * class constructor |
|
46 | - * |
|
47 | - * @access private |
|
48 | - * @return \EEH_Autoloader |
|
49 | - * @throws Exception |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - if (self::$_autoloaders === null) { |
|
54 | - self::$_autoloaders = array(); |
|
55 | - $this->_register_custom_autoloaders(); |
|
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @access public |
|
64 | - * @return EEH_Autoloader |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - // check if class object is instantiated |
|
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | - self::$_instance = new self(); |
|
71 | - } |
|
72 | - return self::$_instance; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * espresso_autoloader |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @param $class_name |
|
82 | - * @internal param $className |
|
83 | - * @internal param string $class_name - simple class name ie: session |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function espresso_autoloader($class_name) |
|
87 | - { |
|
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * register_autoloader |
|
97 | - * |
|
98 | - * @access public |
|
99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | - * @param bool $debug **deprecated** |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | - { |
|
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | - foreach ($class_paths as $class => $path) { |
|
108 | - // skip all files that are not PHP |
|
109 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
110 | - continue; |
|
111 | - } |
|
112 | - // don't give up! you gotta... |
|
113 | - // get some class |
|
114 | - if (empty($class)) { |
|
115 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
116 | - } |
|
117 | - // one day you will find the path young grasshopper |
|
118 | - if (empty($path)) { |
|
119 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
120 | - } |
|
121 | - // is file readable ? |
|
122 | - if ($read_check && ! is_readable($path)) { |
|
123 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
124 | - } |
|
125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * get_autoloaders |
|
139 | - * |
|
140 | - * @access public |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public static function get_autoloaders() |
|
144 | - { |
|
145 | - return self::$_autoloaders; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * register core, model and class 'autoloaders' |
|
151 | - * |
|
152 | - * @access private |
|
153 | - * @return void |
|
154 | - * @throws EE_Error |
|
155 | - */ |
|
156 | - private function _register_custom_autoloaders() |
|
157 | - { |
|
158 | - EEH_Autoloader::$debug = ''; |
|
159 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
164 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
165 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
167 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
168 | - EEH_Debug_Tools::instance()->show_times(); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * register core, model and class 'autoloaders' |
|
176 | - * |
|
177 | - * @access public |
|
178 | - */ |
|
179 | - public static function register_helpers_autoloaders() |
|
180 | - { |
|
181 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * register core, model and class 'autoloaders' |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public static function register_form_sections_autoloaders() |
|
194 | - { |
|
195 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * register core, model and class 'autoloaders' |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @return void |
|
204 | - * @throws EE_Error |
|
205 | - */ |
|
206 | - public static function register_line_item_display_autoloaders() |
|
207 | - { |
|
208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * register core, model and class 'autoloaders' |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public static function register_line_item_filter_autoloaders() |
|
220 | - { |
|
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * register template part 'autoloaders' |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @return void |
|
230 | - * @throws EE_Error |
|
231 | - */ |
|
232 | - public static function register_template_part_autoloaders() |
|
233 | - { |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return void |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - public static function register_business_classes() |
|
243 | - { |
|
244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
251 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
252 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
253 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
254 | - * time the autoloader is used |
|
255 | - * |
|
256 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
257 | - * @param bool $recursive |
|
258 | - * @param bool $debug **deprecated** |
|
259 | - * @throws \EE_Error |
|
260 | - */ |
|
261 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
262 | - { |
|
263 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
264 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
265 | - } |
|
266 | - // make sure last char is a / |
|
267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
268 | - $class_to_filepath_map = array(); |
|
269 | - $exclude = array( 'index' ); |
|
270 | - // get all the files in that folder that end in php |
|
271 | - $filepaths = glob($folder.'*'); |
|
272 | - |
|
273 | - if (empty($filepaths)) { |
|
274 | - return; |
|
275 | - } |
|
276 | - |
|
277 | - foreach ($filepaths as $filepath) { |
|
278 | - if (substr($filepath, -4, 4) === '.php') { |
|
279 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
280 | - if (! in_array($class_name, $exclude)) { |
|
281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
282 | - } |
|
283 | - } elseif ($recursive) { |
|
284 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
285 | - } |
|
286 | - } |
|
287 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
288 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
289 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
290 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * add_alias |
|
298 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
299 | - * |
|
300 | - * @access public |
|
301 | - * @param string $class_name - simple class name ie: EE_Session |
|
302 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
303 | - */ |
|
304 | - public static function add_alias($class_name, $alias) |
|
305 | - { |
|
306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
308 | - } |
|
309 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_System object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * $_autoloaders |
|
28 | + * @var array $_autoloaders |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + private static $_autoloaders; |
|
32 | + |
|
33 | + /** |
|
34 | + * set to "paths" to display autoloader class => path mappings |
|
35 | + * set to "times" to display autoloader loading times |
|
36 | + * set to "all" to display both |
|
37 | + * |
|
38 | + * @var string $debug |
|
39 | + * @access private |
|
40 | + */ |
|
41 | + public static $debug = false; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * class constructor |
|
46 | + * |
|
47 | + * @access private |
|
48 | + * @return \EEH_Autoloader |
|
49 | + * @throws Exception |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + if (self::$_autoloaders === null) { |
|
54 | + self::$_autoloaders = array(); |
|
55 | + $this->_register_custom_autoloaders(); |
|
56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @access public |
|
64 | + * @return EEH_Autoloader |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + // check if class object is instantiated |
|
69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | + self::$_instance = new self(); |
|
71 | + } |
|
72 | + return self::$_instance; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * espresso_autoloader |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @param $class_name |
|
82 | + * @internal param $className |
|
83 | + * @internal param string $class_name - simple class name ie: session |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function espresso_autoloader($class_name) |
|
87 | + { |
|
88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * register_autoloader |
|
97 | + * |
|
98 | + * @access public |
|
99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | + * @param bool $debug **deprecated** |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | + { |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | + foreach ($class_paths as $class => $path) { |
|
108 | + // skip all files that are not PHP |
|
109 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
110 | + continue; |
|
111 | + } |
|
112 | + // don't give up! you gotta... |
|
113 | + // get some class |
|
114 | + if (empty($class)) { |
|
115 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
116 | + } |
|
117 | + // one day you will find the path young grasshopper |
|
118 | + if (empty($path)) { |
|
119 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
120 | + } |
|
121 | + // is file readable ? |
|
122 | + if ($read_check && ! is_readable($path)) { |
|
123 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
124 | + } |
|
125 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * get_autoloaders |
|
139 | + * |
|
140 | + * @access public |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public static function get_autoloaders() |
|
144 | + { |
|
145 | + return self::$_autoloaders; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * register core, model and class 'autoloaders' |
|
151 | + * |
|
152 | + * @access private |
|
153 | + * @return void |
|
154 | + * @throws EE_Error |
|
155 | + */ |
|
156 | + private function _register_custom_autoloaders() |
|
157 | + { |
|
158 | + EEH_Autoloader::$debug = ''; |
|
159 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
164 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
165 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
167 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
168 | + EEH_Debug_Tools::instance()->show_times(); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * register core, model and class 'autoloaders' |
|
176 | + * |
|
177 | + * @access public |
|
178 | + */ |
|
179 | + public static function register_helpers_autoloaders() |
|
180 | + { |
|
181 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * register core, model and class 'autoloaders' |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public static function register_form_sections_autoloaders() |
|
194 | + { |
|
195 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * register core, model and class 'autoloaders' |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @return void |
|
204 | + * @throws EE_Error |
|
205 | + */ |
|
206 | + public static function register_line_item_display_autoloaders() |
|
207 | + { |
|
208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * register core, model and class 'autoloaders' |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public static function register_line_item_filter_autoloaders() |
|
220 | + { |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * register template part 'autoloaders' |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @return void |
|
230 | + * @throws EE_Error |
|
231 | + */ |
|
232 | + public static function register_template_part_autoloaders() |
|
233 | + { |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return void |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + public static function register_business_classes() |
|
243 | + { |
|
244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
251 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
252 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
253 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
254 | + * time the autoloader is used |
|
255 | + * |
|
256 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
257 | + * @param bool $recursive |
|
258 | + * @param bool $debug **deprecated** |
|
259 | + * @throws \EE_Error |
|
260 | + */ |
|
261 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
262 | + { |
|
263 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
264 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
265 | + } |
|
266 | + // make sure last char is a / |
|
267 | + $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
268 | + $class_to_filepath_map = array(); |
|
269 | + $exclude = array( 'index' ); |
|
270 | + // get all the files in that folder that end in php |
|
271 | + $filepaths = glob($folder.'*'); |
|
272 | + |
|
273 | + if (empty($filepaths)) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + foreach ($filepaths as $filepath) { |
|
278 | + if (substr($filepath, -4, 4) === '.php') { |
|
279 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
280 | + if (! in_array($class_name, $exclude)) { |
|
281 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
282 | + } |
|
283 | + } elseif ($recursive) { |
|
284 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
285 | + } |
|
286 | + } |
|
287 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
288 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
289 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
290 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * add_alias |
|
298 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
299 | + * |
|
300 | + * @access public |
|
301 | + * @param string $class_name - simple class name ie: EE_Session |
|
302 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
303 | + */ |
|
304 | + public static function add_alias($class_name, $alias) |
|
305 | + { |
|
306 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
308 | + } |
|
309 | + } |
|
310 | 310 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | if (self::$_autoloaders === null) { |
54 | 54 | self::$_autoloaders = array(); |
55 | 55 | $this->_register_custom_autoloaders(); |
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public static function instance() |
67 | 67 | { |
68 | 68 | // check if class object is instantiated |
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function espresso_autoloader($class_name) |
87 | 87 | { |
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
89 | + require_once(self::$_autoloaders[$class_name]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
105 | 105 | { |
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
107 | 107 | foreach ($class_paths as $class => $path) { |
108 | 108 | // skip all files that are not PHP |
109 | 109 | if (substr($path, strlen($path) - 3) !== 'php') { |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | if ($read_check && ! is_readable($path)) { |
123 | 123 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
124 | 124 | } |
125 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
126 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path); |
|
127 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
128 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
126 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path); |
|
127 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
128 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | { |
158 | 158 | EEH_Autoloader::$debug = ''; |
159 | 159 | \EEH_Autoloader::register_helpers_autoloaders(); |
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
163 | 163 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
164 | 164 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
165 | 165 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
166 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
166 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
167 | 167 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
168 | 168 | EEH_Debug_Tools::instance()->show_times(); |
169 | 169 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public static function register_line_item_display_autoloaders() |
207 | 207 | { |
208 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
208 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function register_line_item_filter_autoloaders() |
220 | 220 | { |
221 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public static function register_template_part_autoloaders() |
233 | 233 | { |
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public static function register_business_classes() |
243 | 243 | { |
244 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business'); |
|
244 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
265 | 265 | } |
266 | 266 | // make sure last char is a / |
267 | - $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : ''; |
|
267 | + $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : ''; |
|
268 | 268 | $class_to_filepath_map = array(); |
269 | - $exclude = array( 'index' ); |
|
269 | + $exclude = array('index'); |
|
270 | 270 | // get all the files in that folder that end in php |
271 | 271 | $filepaths = glob($folder.'*'); |
272 | 272 | |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | foreach ($filepaths as $filepath) { |
278 | 278 | if (substr($filepath, -4, 4) === '.php') { |
279 | 279 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
280 | - if (! in_array($class_name, $exclude)) { |
|
281 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
280 | + if ( ! in_array($class_name, $exclude)) { |
|
281 | + $class_to_filepath_map [$class_name] = $filepath; |
|
282 | 282 | } |
283 | 283 | } elseif ($recursive) { |
284 | 284 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public static function add_alias($class_name, $alias) |
305 | 305 | { |
306 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
307 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
306 | + if (isset(self::$_autoloaders[$class_name])) { |
|
307 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |