Completed
Branch BUG-10381-asset-loading (0f96c1)
by
unknown
60:43 queued 48:13
created
shortcodes/espresso_txn_page/EES_Espresso_Txn_Page.shortcode.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,31 +10,31 @@  discard block
 block discarded – undo
10 10
 class EES_Espresso_Txn_Page  extends EES_Shortcode {
11 11
 
12 12
 	/**
13
-     * The transaction specified by the reg_url_link passed from the Request, or from the Session
14
-     *
15
-     * @deprecated 4.9.26
16
-     * @var EE_Transaction $_current_txn
13
+	 * The transaction specified by the reg_url_link passed from the Request, or from the Session
14
+	 *
15
+	 * @deprecated 4.9.26
16
+	 * @var EE_Transaction $_current_txn
17 17
 	 */
18 18
 	protected $_current_txn;
19 19
 
20 20
 	/**
21
-     * The current payment method for the IPN
22
-     *
23
-     * @deprecated 4.9.26
24
-     * @var EE_Payment_Method $_current_pm
21
+	 * The current payment method for the IPN
22
+	 *
23
+	 * @deprecated 4.9.26
24
+	 * @var EE_Payment_Method $_current_pm
25 25
 	 */
26 26
 	protected $_current_pm;
27 27
 
28 28
 	/**
29
-     * @deprecated 4.9.26
30
-     * @return 	void
29
+	 * @deprecated 4.9.26
30
+	 * @return 	void
31 31
 	 */
32 32
 	public static function set_hooks() {
33 33
 	}
34 34
 
35 35
 	/**
36
-     * @deprecated 4.9.26
37
-     * @return 	void
36
+	 * @deprecated 4.9.26
37
+	 * @return 	void
38 38
 	 */
39 39
 	public static function set_hooks_admin() {
40 40
 	}
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
 
44 44
 	/**
45
-     * @deprecated 4.9.26
46
-     * @return 	void
45
+	 * @deprecated 4.9.26
46
+	 * @return 	void
47 47
 	 */
48 48
 	public static function set_definitions() {
49 49
 	}
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 
52 52
 
53 53
 	/**
54
-     * @deprecated 4.9.26
55
-     * @param  WP $WP
54
+	 * @deprecated 4.9.26
55
+	 * @param  WP $WP
56 56
 	 * @return void
57 57
 	 * @throws \Exception
58 58
 	 * @throws \EE_Error
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 
65 65
 
66 66
 	/**
67
-     * @deprecated 4.9.26
68
-     * @param array $attributes
67
+	 * @deprecated 4.9.26
68
+	 * @param array $attributes
69 69
 	 * @return string
70 70
 	 */
71 71
 	public function process_shortcode( $attributes = array() ) {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2 2
 /**
3 3
  * EES_Espresso_Txn_Page
4 4
  *
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @throws \Exception
58 58
 	 * @throws \EE_Error
59 59
 	 */
60
-	public function run( WP $WP ) {
60
+	public function run(WP $WP) {
61 61
 	}
62 62
 
63 63
 
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
      * @param array $attributes
69 69
 	 * @return string
70 70
 	 */
71
-	public function process_shortcode( $attributes = array() ) {
72
-		return __( 'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso' );
71
+	public function process_shortcode($attributes = array()) {
72
+		return __('This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso');
73 73
 	}
74 74
 
75 75
 
Please login to merge, or discard this patch.
espresso_ticket_selector/EES_Espresso_Ticket_Selector.shortcode.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 class EES_Espresso_Ticket_Selector  extends EES_Shortcode {
11 11
 
12 12
 	/**
13
-     * @deprecated 4.9.26
14
-     * @return 	void
13
+	 * @deprecated 4.9.26
14
+	 * @return 	void
15 15
 	 */
16 16
 	public static function set_hooks() {
17 17
 	}
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 	/**
22
-     * @deprecated 4.9.26
23
-     * @return 	void
22
+	 * @deprecated 4.9.26
23
+	 * @return 	void
24 24
 	 */
25 25
 	public static function set_hooks_admin() {
26 26
 	}
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
 
29 29
 
30 30
 	/**
31
-     * @deprecated 4.9.26
32
-     * @param \WP $WP
31
+	 * @deprecated 4.9.26
32
+	 * @param \WP $WP
33 33
 	 */
34 34
 	public function run( WP $WP ) {
35 35
 	}
36 36
 
37 37
 
38 38
 	/**
39
-     * @deprecated 4.9.26
40
-     * @param		array 	$attributes
39
+	 * @deprecated 4.9.26
40
+	 * @param		array 	$attributes
41 41
 	 * @return 	string
42 42
 	 */
43 43
 	public function process_shortcode( $attributes = array() ) {
44
-        \EE_Error::doing_it_wrong(
45
-            __METHOD__,
46
-            __(
47
-                'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector instead.',
48
-                'event_espresso'
49
-            ),
50
-            '4.9.26'
51
-        );
52
-        return '';
53
-    }
44
+		\EE_Error::doing_it_wrong(
45
+			__METHOD__,
46
+			__(
47
+				'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector instead.',
48
+				'event_espresso'
49
+			),
50
+			'4.9.26'
51
+		);
52
+		return '';
53
+	}
54 54
 
55 55
 }
56 56
 // End of file EES_Espresso_Ticket_Selector.shortcode.php
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @return    void
41 41
      * @throws \EE_Error
42 42
      */
43
-	public function run( WP $WP ) {
43
+	public function run(WP $WP) {
44 44
         \EE_Error::doing_it_wrong(
45 45
             __METHOD__,
46 46
             __(
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 *  @param		array 	$attributes
61 61
 	 *  @return 	string
62 62
 	 */
63
-	public function process_shortcode( $attributes = array() ) {
63
+	public function process_shortcode($attributes = array()) {
64 64
         \EE_Error::doing_it_wrong(
65 65
             __METHOD__,
66 66
             __(
Please login to merge, or discard this patch.
core/services/shortcodes/LegacyShortcodesManager.php 2 patches
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -25,416 +25,416 @@
 block discarded – undo
25 25
 class LegacyShortcodesManager
26 26
 {
27 27
 
28
-    /**
29
-     * @var EE_Registry $registry
30
-     */
31
-    private $registry;
32
-
33
-
34
-
35
-
36
-    /**
37
-     * LegacyShortcodesManager constructor.
38
-     *
39
-     * @param \EE_Registry $registry
40
-     */
41
-    public function __construct(EE_Registry $registry)
42
-    {
43
-        $this->registry = $registry;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * registerShortcodes
50
-     *
51
-     * @return void
52
-     */
53
-    public function registerShortcodes()
54
-    {
55
-        $this->registry->shortcodes = $this->getShortcodes();
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * getShortcodes
62
-     *
63
-     * @return array
64
-     */
65
-    public function getShortcodes()
66
-    {
67
-        // previously this method would glob the shortcodes directory
68
-        // then filter that list of shortcodes to register,
69
-        // but now we are going to just supply an empty array.
70
-        // this allows any shortcodes that have not yet been converted to the new system
71
-        // to still get loaded and processed, albeit using the same legacy logic as before
72
-        $shortcodes_to_register = apply_filters(
73
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
74
-            array()
75
-        );
76
-        if ( ! empty($shortcodes_to_register)) {
77
-            // cycle thru shortcode folders
78
-            foreach ($shortcodes_to_register as $shortcode_path) {
79
-                // add to list of installed shortcode modules
80
-                LegacyShortcodesManager::registerShortcode($shortcode_path);
81
-            }
82
-        }
83
-        // filter list of installed modules
84
-        return apply_filters(
85
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
86
-            $this->registry->shortcodes
87
-        );
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     *    register_shortcode - makes core aware of this shortcode
94
-     *
95
-     * @access    public
96
-     * @param    string $shortcode_path - full path up to and including shortcode folder
97
-     * @return    bool
98
-     */
99
-    public function registerShortcode($shortcode_path = null)
100
-    {
101
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
102
-        $shortcode_ext = '.shortcode.php';
103
-        // make all separators match
104
-        $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
105
-        // does the file path INCLUDE the actual file name as part of the path ?
106
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
107
-            // grab shortcode file name from directory name and break apart at dots
108
-            $shortcode_file = explode('.', basename($shortcode_path));
109
-            // take first segment from file name pieces and remove class prefix if it exists
110
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
111
-                ? substr($shortcode_file[0], 4)
112
-                : $shortcode_file[0];
113
-            // sanitize shortcode directory name
114
-            $shortcode = sanitize_key($shortcode);
115
-            // now we need to rebuild the shortcode path
116
-            $shortcode_path = explode(DS, $shortcode_path);
117
-            // remove last segment
118
-            array_pop($shortcode_path);
119
-            // glue it back together
120
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
121
-        } else {
122
-            // we need to generate the filename based off of the folder name
123
-            // grab and sanitize shortcode directory name
124
-            $shortcode = sanitize_key(basename($shortcode_path));
125
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
126
-        }
127
-        // create classname from shortcode directory or file name
128
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
129
-        // add class prefix
130
-        $shortcode_class = 'EES_' . $shortcode;
131
-        // does the shortcode exist ?
132
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
133
-            $msg = sprintf(
134
-                __(
135
-                    'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
136
-                    'event_espresso'
137
-                ),
138
-                $shortcode_class,
139
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
140
-            );
141
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
142
-            return false;
143
-        }
144
-        // load the shortcode class file
145
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
146
-        // verify that class exists
147
-        if ( ! class_exists($shortcode_class)) {
148
-            $msg = sprintf(
149
-                __('The requested %s shortcode class does not exist.', 'event_espresso'),
150
-                $shortcode_class
151
-            );
152
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
153
-            return false;
154
-        }
155
-        $shortcode = strtoupper($shortcode);
156
-        // add to array of registered shortcodes
157
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
158
-        return true;
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     *    _initialize_shortcodes
165
-     *    allow shortcodes to set hooks for the rest of the system
166
-     *
167
-     * @access private
168
-     * @return void
169
-     */
170
-    public function addShortcodes()
171
-    {
172
-        // cycle thru shortcode folders
173
-        foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
174
-            // add class prefix
175
-            $shortcode_class = 'EES_' . $shortcode;
176
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
177
-            // which set hooks ?
178
-            if (is_admin()) {
179
-                // fire immediately
180
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
181
-            } else {
182
-                // delay until other systems are online
183
-                add_action(
184
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
185
-                    array($shortcode_class, 'set_hooks')
186
-                );
187
-                // convert classname to UPPERCASE and create WP shortcode.
188
-                $shortcode_tag = strtoupper($shortcode);
189
-                // but first check if the shortcode has already
190
-                // been added before assigning 'fallback_shortcode_processor'
191
-                if ( ! shortcode_exists($shortcode_tag)) {
192
-                    // NOTE: this shortcode declaration will get overridden if the shortcode
193
-                    // is successfully detected in the post content in initializeShortcode()
194
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
195
-                }
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='publish' 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 (
251
-            // is current page/post the "blog" page ?
252
-            $current_post === EE_Config::get_page_for_posts()
253
-            // or are we on a category page?
254
-            || (
255
-                is_array(term_exists($current_post, 'category'))
256
-                || array_key_exists('category_name', $wp->query_vars)
257
-            )
258
-        ) {
259
-            // initialize all legacy shortcodes
260
-            $load_assets = $this->parseContentForShortcodes('', true);
261
-        } else {
262
-            global $wpdb;
263
-            $post_content = $wpdb->get_var(
264
-                $wpdb->prepare(
265
-                    "SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s",
266
-                    $current_post
267
-                )
268
-            );
269
-            $load_assets = $this->parseContentForShortcodes($post_content);
270
-        }
271
-        if ($load_assets) {
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
-    /**
281
-     * checks supplied content against list of legacy shortcodes,
282
-     * then initializes any found shortcodes, and returns true.
283
-     * returns false if no shortcodes found.
284
-     *
285
-     * @param string $content
286
-     * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
287
-     * @return bool
288
-     */
289
-    public function parseContentForShortcodes($content = '', $load_all = false)
290
-    {
291
-        $has_shortcode = false;
292
-        foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
293
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
294
-                // load up the shortcode
295
-                $this->initializeShortcode($shortcode_class);
296
-                $has_shortcode = true;
297
-            }
298
-        }
299
-        return $has_shortcode;
300
-    }
301
-
302
-
303
-
304
-    /**
305
-     * given a shortcode name, will instantiate the shortcode and call it's run() method
306
-     *
307
-     * @param string $shortcode_class
308
-     * @param WP     $wp
309
-     */
310
-    public function initializeShortcode($shortcode_class = '', WP $wp = null)
311
-    {
312
-        // don't do anything if shortcode is already initialized
313
-        if (
314
-            empty($this->registry->shortcodes->{$shortcode_class})
315
-            || ! is_string($this->registry->shortcodes->{$shortcode_class})
316
-        ) {
317
-            return;
318
-        }
319
-        // let's pause to reflect on this...
320
-        $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
321
-        // ensure that class is actually a shortcode
322
-        if (
323
-            defined('WP_DEBUG')
324
-            && WP_DEBUG === true
325
-            && ! $sc_reflector->isSubclassOf('EES_Shortcode')
326
-        ) {
327
-            EE_Error::add_error(
328
-                sprintf(
329
-                    __(
330
-                        'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
331
-                        'event_espresso'
332
-                    ),
333
-                    $shortcode_class
334
-                ),
335
-                __FILE__,
336
-                __FUNCTION__,
337
-                __LINE__
338
-            );
339
-            add_filter('FHEE_run_EE_the_content', '__return_true');
340
-            return;
341
-        }
342
-        global $wp;
343
-        // and pass the request object to the run method
344
-        $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
345
-        // fire the shortcode class's run method, so that it can activate resources
346
-        $this->registry->shortcodes->{$shortcode_class}->run($wp);
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * get classname, remove EES_prefix, and convert to UPPERCASE
353
-     *
354
-     * @param string $class_name
355
-     * @return string
356
-     */
357
-    public static function generateShortcodeTagFromClassName($class_name)
358
-    {
359
-        return strtoupper(str_replace('EES_', '', $class_name));
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * add EES_prefix and Capitalize words
366
-     *
367
-     * @param string $tag
368
-     * @return string
369
-     */
370
-    public static function generateShortcodeClassNameFromTag($tag)
371
-    {
372
-        // order of operation runs from inside to out
373
-        // 5) maybe add prefix
374
-        return LegacyShortcodesManager::addShortcodeClassPrefix(
375
-        // 4) find spaces, replace with underscores
376
-            str_replace(
377
-                ' ',
378
-                '_',
379
-                // 3) capitalize first letter of each word
380
-                ucwords(
381
-                // 2) also change to lowercase so ucwords() will work
382
-                    strtolower(
383
-                    // 1) find underscores, replace with spaces so ucwords() will work
384
-                        str_replace(
385
-                            '_',
386
-                            ' ',
387
-                            $tag
388
-                        )
389
-                    )
390
-                )
391
-            )
392
-        );
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * maybe add EES_prefix
399
-     *
400
-     * @param string $class_name
401
-     * @return string
402
-     */
403
-    public static function addShortcodeClassPrefix($class_name)
404
-    {
405
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * @return array
412
-     */
413
-    public function getEspressoShortcodeTags()
414
-    {
415
-        static $shortcode_tags = array();
416
-        if (empty($shortcode_tags)) {
417
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
418
-        }
419
-        return $shortcode_tags;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * @param string $content
426
-     * @return string
427
-     */
428
-    public function doShortcode($content)
429
-    {
430
-        foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
431
-            if (strpos($content, $shortcode_tag) !== false) {
432
-                $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
433
-                $this->initializeShortcode($shortcode_class);
434
-            }
435
-        }
436
-        return do_shortcode($content);
437
-    }
28
+	/**
29
+	 * @var EE_Registry $registry
30
+	 */
31
+	private $registry;
32
+
33
+
34
+
35
+
36
+	/**
37
+	 * LegacyShortcodesManager constructor.
38
+	 *
39
+	 * @param \EE_Registry $registry
40
+	 */
41
+	public function __construct(EE_Registry $registry)
42
+	{
43
+		$this->registry = $registry;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * registerShortcodes
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function registerShortcodes()
54
+	{
55
+		$this->registry->shortcodes = $this->getShortcodes();
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * getShortcodes
62
+	 *
63
+	 * @return array
64
+	 */
65
+	public function getShortcodes()
66
+	{
67
+		// previously this method would glob the shortcodes directory
68
+		// then filter that list of shortcodes to register,
69
+		// but now we are going to just supply an empty array.
70
+		// this allows any shortcodes that have not yet been converted to the new system
71
+		// to still get loaded and processed, albeit using the same legacy logic as before
72
+		$shortcodes_to_register = apply_filters(
73
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
74
+			array()
75
+		);
76
+		if ( ! empty($shortcodes_to_register)) {
77
+			// cycle thru shortcode folders
78
+			foreach ($shortcodes_to_register as $shortcode_path) {
79
+				// add to list of installed shortcode modules
80
+				LegacyShortcodesManager::registerShortcode($shortcode_path);
81
+			}
82
+		}
83
+		// filter list of installed modules
84
+		return apply_filters(
85
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
86
+			$this->registry->shortcodes
87
+		);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 *    register_shortcode - makes core aware of this shortcode
94
+	 *
95
+	 * @access    public
96
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
97
+	 * @return    bool
98
+	 */
99
+	public function registerShortcode($shortcode_path = null)
100
+	{
101
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
102
+		$shortcode_ext = '.shortcode.php';
103
+		// make all separators match
104
+		$shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
105
+		// does the file path INCLUDE the actual file name as part of the path ?
106
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
107
+			// grab shortcode file name from directory name and break apart at dots
108
+			$shortcode_file = explode('.', basename($shortcode_path));
109
+			// take first segment from file name pieces and remove class prefix if it exists
110
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
111
+				? substr($shortcode_file[0], 4)
112
+				: $shortcode_file[0];
113
+			// sanitize shortcode directory name
114
+			$shortcode = sanitize_key($shortcode);
115
+			// now we need to rebuild the shortcode path
116
+			$shortcode_path = explode(DS, $shortcode_path);
117
+			// remove last segment
118
+			array_pop($shortcode_path);
119
+			// glue it back together
120
+			$shortcode_path = implode(DS, $shortcode_path) . DS;
121
+		} else {
122
+			// we need to generate the filename based off of the folder name
123
+			// grab and sanitize shortcode directory name
124
+			$shortcode = sanitize_key(basename($shortcode_path));
125
+			$shortcode_path = rtrim($shortcode_path, DS) . DS;
126
+		}
127
+		// create classname from shortcode directory or file name
128
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
129
+		// add class prefix
130
+		$shortcode_class = 'EES_' . $shortcode;
131
+		// does the shortcode exist ?
132
+		if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
133
+			$msg = sprintf(
134
+				__(
135
+					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
136
+					'event_espresso'
137
+				),
138
+				$shortcode_class,
139
+				$shortcode_path . DS . $shortcode_class . $shortcode_ext
140
+			);
141
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
142
+			return false;
143
+		}
144
+		// load the shortcode class file
145
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
146
+		// verify that class exists
147
+		if ( ! class_exists($shortcode_class)) {
148
+			$msg = sprintf(
149
+				__('The requested %s shortcode class does not exist.', 'event_espresso'),
150
+				$shortcode_class
151
+			);
152
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
153
+			return false;
154
+		}
155
+		$shortcode = strtoupper($shortcode);
156
+		// add to array of registered shortcodes
157
+		$this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
158
+		return true;
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 *    _initialize_shortcodes
165
+	 *    allow shortcodes to set hooks for the rest of the system
166
+	 *
167
+	 * @access private
168
+	 * @return void
169
+	 */
170
+	public function addShortcodes()
171
+	{
172
+		// cycle thru shortcode folders
173
+		foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
174
+			// add class prefix
175
+			$shortcode_class = 'EES_' . $shortcode;
176
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
177
+			// which set hooks ?
178
+			if (is_admin()) {
179
+				// fire immediately
180
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
181
+			} else {
182
+				// delay until other systems are online
183
+				add_action(
184
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
185
+					array($shortcode_class, 'set_hooks')
186
+				);
187
+				// convert classname to UPPERCASE and create WP shortcode.
188
+				$shortcode_tag = strtoupper($shortcode);
189
+				// but first check if the shortcode has already
190
+				// been added before assigning 'fallback_shortcode_processor'
191
+				if ( ! shortcode_exists($shortcode_tag)) {
192
+					// NOTE: this shortcode declaration will get overridden if the shortcode
193
+					// is successfully detected in the post content in initializeShortcode()
194
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
195
+				}
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='publish' 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 (
251
+			// is current page/post the "blog" page ?
252
+			$current_post === EE_Config::get_page_for_posts()
253
+			// or are we on a category page?
254
+			|| (
255
+				is_array(term_exists($current_post, 'category'))
256
+				|| array_key_exists('category_name', $wp->query_vars)
257
+			)
258
+		) {
259
+			// initialize all legacy shortcodes
260
+			$load_assets = $this->parseContentForShortcodes('', true);
261
+		} else {
262
+			global $wpdb;
263
+			$post_content = $wpdb->get_var(
264
+				$wpdb->prepare(
265
+					"SELECT post_content from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s",
266
+					$current_post
267
+				)
268
+			);
269
+			$load_assets = $this->parseContentForShortcodes($post_content);
270
+		}
271
+		if ($load_assets) {
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
+	/**
281
+	 * checks supplied content against list of legacy shortcodes,
282
+	 * then initializes any found shortcodes, and returns true.
283
+	 * returns false if no shortcodes found.
284
+	 *
285
+	 * @param string $content
286
+	 * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
287
+	 * @return bool
288
+	 */
289
+	public function parseContentForShortcodes($content = '', $load_all = false)
290
+	{
291
+		$has_shortcode = false;
292
+		foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
293
+			if ($load_all || has_shortcode($content, $shortcode_class) ) {
294
+				// load up the shortcode
295
+				$this->initializeShortcode($shortcode_class);
296
+				$has_shortcode = true;
297
+			}
298
+		}
299
+		return $has_shortcode;
300
+	}
301
+
302
+
303
+
304
+	/**
305
+	 * given a shortcode name, will instantiate the shortcode and call it's run() method
306
+	 *
307
+	 * @param string $shortcode_class
308
+	 * @param WP     $wp
309
+	 */
310
+	public function initializeShortcode($shortcode_class = '', WP $wp = null)
311
+	{
312
+		// don't do anything if shortcode is already initialized
313
+		if (
314
+			empty($this->registry->shortcodes->{$shortcode_class})
315
+			|| ! is_string($this->registry->shortcodes->{$shortcode_class})
316
+		) {
317
+			return;
318
+		}
319
+		// let's pause to reflect on this...
320
+		$sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
321
+		// ensure that class is actually a shortcode
322
+		if (
323
+			defined('WP_DEBUG')
324
+			&& WP_DEBUG === true
325
+			&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
326
+		) {
327
+			EE_Error::add_error(
328
+				sprintf(
329
+					__(
330
+						'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
331
+						'event_espresso'
332
+					),
333
+					$shortcode_class
334
+				),
335
+				__FILE__,
336
+				__FUNCTION__,
337
+				__LINE__
338
+			);
339
+			add_filter('FHEE_run_EE_the_content', '__return_true');
340
+			return;
341
+		}
342
+		global $wp;
343
+		// and pass the request object to the run method
344
+		$this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
345
+		// fire the shortcode class's run method, so that it can activate resources
346
+		$this->registry->shortcodes->{$shortcode_class}->run($wp);
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * get classname, remove EES_prefix, and convert to UPPERCASE
353
+	 *
354
+	 * @param string $class_name
355
+	 * @return string
356
+	 */
357
+	public static function generateShortcodeTagFromClassName($class_name)
358
+	{
359
+		return strtoupper(str_replace('EES_', '', $class_name));
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * add EES_prefix and Capitalize words
366
+	 *
367
+	 * @param string $tag
368
+	 * @return string
369
+	 */
370
+	public static function generateShortcodeClassNameFromTag($tag)
371
+	{
372
+		// order of operation runs from inside to out
373
+		// 5) maybe add prefix
374
+		return LegacyShortcodesManager::addShortcodeClassPrefix(
375
+		// 4) find spaces, replace with underscores
376
+			str_replace(
377
+				' ',
378
+				'_',
379
+				// 3) capitalize first letter of each word
380
+				ucwords(
381
+				// 2) also change to lowercase so ucwords() will work
382
+					strtolower(
383
+					// 1) find underscores, replace with spaces so ucwords() will work
384
+						str_replace(
385
+							'_',
386
+							' ',
387
+							$tag
388
+						)
389
+					)
390
+				)
391
+			)
392
+		);
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * maybe add EES_prefix
399
+	 *
400
+	 * @param string $class_name
401
+	 * @return string
402
+	 */
403
+	public static function addShortcodeClassPrefix($class_name)
404
+	{
405
+		return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * @return array
412
+	 */
413
+	public function getEspressoShortcodeTags()
414
+	{
415
+		static $shortcode_tags = array();
416
+		if (empty($shortcode_tags)) {
417
+			$shortcode_tags = array_keys((array)$this->registry->shortcodes);
418
+		}
419
+		return $shortcode_tags;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * @param string $content
426
+	 * @return string
427
+	 */
428
+	public function doShortcode($content)
429
+	{
430
+		foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
431
+			if (strpos($content, $shortcode_tag) !== false) {
432
+				$shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
433
+				$this->initializeShortcode($shortcode_class);
434
+			}
435
+		}
436
+		return do_shortcode($content);
437
+	}
438 438
 
439 439
 
440 440
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
             // remove last segment
118 118
             array_pop($shortcode_path);
119 119
             // glue it back together
120
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
120
+            $shortcode_path = implode(DS, $shortcode_path).DS;
121 121
         } else {
122 122
             // we need to generate the filename based off of the folder name
123 123
             // grab and sanitize shortcode directory name
124 124
             $shortcode = sanitize_key(basename($shortcode_path));
125
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
125
+            $shortcode_path = rtrim($shortcode_path, DS).DS;
126 126
         }
127 127
         // create classname from shortcode directory or file name
128 128
         $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
129 129
         // add class prefix
130
-        $shortcode_class = 'EES_' . $shortcode;
130
+        $shortcode_class = 'EES_'.$shortcode;
131 131
         // does the shortcode exist ?
132
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
132
+        if ( ! is_readable($shortcode_path.DS.$shortcode_class.$shortcode_ext)) {
133 133
             $msg = sprintf(
134 134
                 __(
135 135
                     'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
136 136
                     'event_espresso'
137 137
                 ),
138 138
                 $shortcode_class,
139
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
139
+                $shortcode_path.DS.$shortcode_class.$shortcode_ext
140 140
             );
141
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
141
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
142 142
             return false;
143 143
         }
144 144
         // load the shortcode class file
145
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
145
+        require_once($shortcode_path.$shortcode_class.$shortcode_ext);
146 146
         // verify that class exists
147 147
         if ( ! class_exists($shortcode_class)) {
148 148
             $msg = sprintf(
149 149
                 __('The requested %s shortcode class does not exist.', 'event_espresso'),
150 150
                 $shortcode_class
151 151
             );
152
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
152
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
153 153
             return false;
154 154
         }
155 155
         $shortcode = strtoupper($shortcode);
156 156
         // add to array of registered shortcodes
157
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
157
+        $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext;
158 158
         return true;
159 159
     }
160 160
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         // cycle thru shortcode folders
173 173
         foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
174 174
             // add class prefix
175
-            $shortcode_class = 'EES_' . $shortcode;
175
+            $shortcode_class = 'EES_'.$shortcode;
176 176
             // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
177 177
             // which set hooks ?
178 178
             if (is_admin()) {
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
     {
291 291
         $has_shortcode = false;
292 292
         foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
293
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
293
+            if ($load_all || has_shortcode($content, $shortcode_class)) {
294 294
                 // load up the shortcode
295 295
                 $this->initializeShortcode($shortcode_class);
296 296
                 $has_shortcode = true;
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      */
403 403
     public static function addShortcodeClassPrefix($class_name)
404 404
     {
405
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
405
+        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name;
406 406
     }
407 407
 
408 408
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
     {
415 415
         static $shortcode_tags = array();
416 416
         if (empty($shortcode_tags)) {
417
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
417
+            $shortcode_tags = array_keys((array) $this->registry->shortcodes);
418 418
         }
419 419
         return $shortcode_tags;
420 420
     }
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodesManager.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -30,184 +30,184 @@
 block discarded – undo
30 30
 class ShortcodesManager
31 31
 {
32 32
 
33
-    /**
34
-     * @var LegacyShortcodesManager $LegacyShortcodesManager
35
-     */
36
-    private $LegacyShortcodesManager;
37
-
38
-    /**
39
-     * @var ShortcodeInterface[] $shortcodes
40
-     */
41
-    private $shortcodes;
42
-
43
-
44
-
45
-    /**
46
-     * ShortcodesManager constructor
47
-     *
48
-     * @param LegacyShortcodesManager $LegacyShortcodesManager
49
-     */
50
-    public function __construct(LegacyShortcodesManager $LegacyShortcodesManager) {
51
-        $this->LegacyShortcodesManager = $LegacyShortcodesManager;
52
-        // assemble a list of installed and active shortcodes
53
-        add_action(
54
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
55
-            array($this, 'registerShortcodes'),
56
-            999
57
-        );
58
-        //  call add_shortcode() for all installed shortcodes
59
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
60
-        // check content for shortcodes, the old way, and the more efficient new way
61
-        add_action('parse_query', array($this->LegacyShortcodesManager, 'initializeShortcodes'), 5);
62
-        add_action('get_header', array($this, 'getHeader'));
63
-    }
64
-
65
-
66
-
67
-    /**
68
-     * @return CollectionInterface|ShortcodeInterface[]
69
-     * @throws InvalidIdentifierException
70
-     * @throws InvalidInterfaceException
71
-     * @throws InvalidFilePathException
72
-     * @throws InvalidEntityException
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidClassException
75
-     */
76
-    public function getShortcodes()
77
-    {
78
-        if ( ! $this->shortcodes instanceof CollectionInterface) {
79
-            $this->shortcodes = $this->loadShortcodesCollection();
80
-        }
81
-        return $this->shortcodes;
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * @return CollectionInterface|ShortcodeInterface[]
88
-     * @throws InvalidIdentifierException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidFilePathException
91
-     * @throws InvalidEntityException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidClassException
94
-     */
95
-    protected function loadShortcodesCollection()
96
-    {
97
-        $loader = new CollectionLoader(
98
-            new CollectionDetails(
99
-            // collection name
100
-                'shortcodes',
101
-                // collection interface
102
-                '\EventEspresso\core\services\shortcodes\ShortcodeInterface',
103
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
104
-                array('EventEspresso\core\domain\entities\shortcodes'),
105
-                // filepaths to classes to add
106
-                array(),
107
-                // filemask to use if parsing folder for files to add
108
-                '',
109
-                // what to use as identifier for collection entities
110
-                // using CLASS NAME prevents duplicates (works like a singleton)
111
-                CollectionDetails::ID_CLASS_NAME
112
-            )
113
-        );
114
-        return $loader->getCollection();
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * @return void
121
-     * @throws InvalidInterfaceException
122
-     * @throws InvalidIdentifierException
123
-     * @throws InvalidFilePathException
124
-     * @throws InvalidEntityException
125
-     * @throws InvalidDataTypeException
126
-     * @throws InvalidClassException
127
-     */
128
-    public function registerShortcodes()
129
-    {
130
-        $this->shortcodes = apply_filters(
131
-            'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
132
-            $this->getShortcodes()
133
-        );
134
-        $this->LegacyShortcodesManager->registerShortcodes();
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * @return void
141
-     */
142
-    public function addShortcodes()
143
-    {
144
-        // cycle thru shortcode folders
145
-        foreach ($this->shortcodes as $shortcode) {
146
-            /** @var ShortcodeInterface $shortcode */
147
-            if ( $shortcode instanceof EnqueueAssetsInterface) {
148
-                add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
149
-                add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
150
-            }
151
-            // add_shortcode() if it has not already been added
152
-            if ( ! shortcode_exists($shortcode->getTag())) {
153
-                add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
154
-            }
155
-        }
156
-        $this->LegacyShortcodesManager->addShortcodes();
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * callback for the WP "get_header" hook point
163
-     * checks posts for EE shortcodes, and initializes them,
164
-     * then toggles filter switch that loads core default assets
165
-     *
166
-     * @return void
167
-     */
168
-    public function getHeader()
169
-    {
170
-        global $wp_query;
171
-        if (empty($wp_query->posts)) {
172
-            return;
173
-        }
174
-        $load_assets = false;
175
-        // array of posts displayed in current request
176
-        $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
177
-        foreach ($posts as $post) {
178
-            // now check post content and excerpt for EE shortcodes
179
-            $load_assets = $this->parseContentForShortcodes($post->post_content)
180
-                ? true
181
-                : $load_assets;
182
-        }
183
-        if ($load_assets) {
184
-            add_filter('FHEE_load_css', '__return_true');
185
-            add_filter('FHEE_load_js', '__return_true');
186
-        }
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * checks supplied content against list of shortcodes,
193
-     * then initializes any found shortcodes, and returns true.
194
-     * returns false if no shortcodes found.
195
-     *
196
-     * @param string $content
197
-     * @return bool
198
-     */
199
-    public function parseContentForShortcodes($content)
200
-    {
201
-        $has_shortcode = false;
202
-        foreach ($this->shortcodes as $shortcode) {
203
-            /** @var ShortcodeInterface $shortcode */
204
-            if (has_shortcode($content, $shortcode->getTag())) {
205
-                $shortcode->initializeShortcode();
206
-                $has_shortcode = true;
207
-            }
208
-        }
209
-        return $has_shortcode;
210
-    }
33
+	/**
34
+	 * @var LegacyShortcodesManager $LegacyShortcodesManager
35
+	 */
36
+	private $LegacyShortcodesManager;
37
+
38
+	/**
39
+	 * @var ShortcodeInterface[] $shortcodes
40
+	 */
41
+	private $shortcodes;
42
+
43
+
44
+
45
+	/**
46
+	 * ShortcodesManager constructor
47
+	 *
48
+	 * @param LegacyShortcodesManager $LegacyShortcodesManager
49
+	 */
50
+	public function __construct(LegacyShortcodesManager $LegacyShortcodesManager) {
51
+		$this->LegacyShortcodesManager = $LegacyShortcodesManager;
52
+		// assemble a list of installed and active shortcodes
53
+		add_action(
54
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
55
+			array($this, 'registerShortcodes'),
56
+			999
57
+		);
58
+		//  call add_shortcode() for all installed shortcodes
59
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
60
+		// check content for shortcodes, the old way, and the more efficient new way
61
+		add_action('parse_query', array($this->LegacyShortcodesManager, 'initializeShortcodes'), 5);
62
+		add_action('get_header', array($this, 'getHeader'));
63
+	}
64
+
65
+
66
+
67
+	/**
68
+	 * @return CollectionInterface|ShortcodeInterface[]
69
+	 * @throws InvalidIdentifierException
70
+	 * @throws InvalidInterfaceException
71
+	 * @throws InvalidFilePathException
72
+	 * @throws InvalidEntityException
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidClassException
75
+	 */
76
+	public function getShortcodes()
77
+	{
78
+		if ( ! $this->shortcodes instanceof CollectionInterface) {
79
+			$this->shortcodes = $this->loadShortcodesCollection();
80
+		}
81
+		return $this->shortcodes;
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * @return CollectionInterface|ShortcodeInterface[]
88
+	 * @throws InvalidIdentifierException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidFilePathException
91
+	 * @throws InvalidEntityException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidClassException
94
+	 */
95
+	protected function loadShortcodesCollection()
96
+	{
97
+		$loader = new CollectionLoader(
98
+			new CollectionDetails(
99
+			// collection name
100
+				'shortcodes',
101
+				// collection interface
102
+				'\EventEspresso\core\services\shortcodes\ShortcodeInterface',
103
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
104
+				array('EventEspresso\core\domain\entities\shortcodes'),
105
+				// filepaths to classes to add
106
+				array(),
107
+				// filemask to use if parsing folder for files to add
108
+				'',
109
+				// what to use as identifier for collection entities
110
+				// using CLASS NAME prevents duplicates (works like a singleton)
111
+				CollectionDetails::ID_CLASS_NAME
112
+			)
113
+		);
114
+		return $loader->getCollection();
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * @return void
121
+	 * @throws InvalidInterfaceException
122
+	 * @throws InvalidIdentifierException
123
+	 * @throws InvalidFilePathException
124
+	 * @throws InvalidEntityException
125
+	 * @throws InvalidDataTypeException
126
+	 * @throws InvalidClassException
127
+	 */
128
+	public function registerShortcodes()
129
+	{
130
+		$this->shortcodes = apply_filters(
131
+			'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
132
+			$this->getShortcodes()
133
+		);
134
+		$this->LegacyShortcodesManager->registerShortcodes();
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * @return void
141
+	 */
142
+	public function addShortcodes()
143
+	{
144
+		// cycle thru shortcode folders
145
+		foreach ($this->shortcodes as $shortcode) {
146
+			/** @var ShortcodeInterface $shortcode */
147
+			if ( $shortcode instanceof EnqueueAssetsInterface) {
148
+				add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
149
+				add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
150
+			}
151
+			// add_shortcode() if it has not already been added
152
+			if ( ! shortcode_exists($shortcode->getTag())) {
153
+				add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
154
+			}
155
+		}
156
+		$this->LegacyShortcodesManager->addShortcodes();
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * callback for the WP "get_header" hook point
163
+	 * checks posts for EE shortcodes, and initializes them,
164
+	 * then toggles filter switch that loads core default assets
165
+	 *
166
+	 * @return void
167
+	 */
168
+	public function getHeader()
169
+	{
170
+		global $wp_query;
171
+		if (empty($wp_query->posts)) {
172
+			return;
173
+		}
174
+		$load_assets = false;
175
+		// array of posts displayed in current request
176
+		$posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
177
+		foreach ($posts as $post) {
178
+			// now check post content and excerpt for EE shortcodes
179
+			$load_assets = $this->parseContentForShortcodes($post->post_content)
180
+				? true
181
+				: $load_assets;
182
+		}
183
+		if ($load_assets) {
184
+			add_filter('FHEE_load_css', '__return_true');
185
+			add_filter('FHEE_load_js', '__return_true');
186
+		}
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * checks supplied content against list of shortcodes,
193
+	 * then initializes any found shortcodes, and returns true.
194
+	 * returns false if no shortcodes found.
195
+	 *
196
+	 * @param string $content
197
+	 * @return bool
198
+	 */
199
+	public function parseContentForShortcodes($content)
200
+	{
201
+		$has_shortcode = false;
202
+		foreach ($this->shortcodes as $shortcode) {
203
+			/** @var ShortcodeInterface $shortcode */
204
+			if (has_shortcode($content, $shortcode->getTag())) {
205
+				$shortcode->initializeShortcode();
206
+				$has_shortcode = true;
207
+			}
208
+		}
209
+		return $has_shortcode;
210
+	}
211 211
 
212 212
 }
213 213
 // End of file ShortcodesManager.php
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoThankYou.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -20,44 +20,44 @@
 block discarded – undo
20 20
 
21 21
 
22 22
 
23
-    /**
24
-     * the actual shortcode tag that gets registered with WordPress
25
-     *
26
-     * @return string
27
-     */
28
-    public function getTag()
29
-    {
30
-        return 'ESPRESSO_THANK_YOU';
31
-    }
32
-
33
-
34
-
35
-    /**
36
-     * a place for adding any initialization code that needs to run prior to wp_header().
37
-     * this may be required for shortcodes that utilize a corresponding module,
38
-     * and need to enqueue assets for that module
39
-     *
40
-     * @return void
41
-     */
42
-    public function initializeShortcode()
43
-    {
44
-        // TODO: Implement initializeShortcode() method.
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * callback that runs when the shortcode is encountered in post content.
51
-     * IMPORTANT !!!
52
-     * remember that shortcode content should be RETURNED and NOT echoed out
53
-     *
54
-     * @param array $attributes
55
-     * @return string
56
-     */
57
-    public function processShortcode($attributes = array())
58
-    {
59
-        // TODO: Implement processShortcode() method.
60
-    }
23
+	/**
24
+	 * the actual shortcode tag that gets registered with WordPress
25
+	 *
26
+	 * @return string
27
+	 */
28
+	public function getTag()
29
+	{
30
+		return 'ESPRESSO_THANK_YOU';
31
+	}
32
+
33
+
34
+
35
+	/**
36
+	 * a place for adding any initialization code that needs to run prior to wp_header().
37
+	 * this may be required for shortcodes that utilize a corresponding module,
38
+	 * and need to enqueue assets for that module
39
+	 *
40
+	 * @return void
41
+	 */
42
+	public function initializeShortcode()
43
+	{
44
+		// TODO: Implement initializeShortcode() method.
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * callback that runs when the shortcode is encountered in post content.
51
+	 * IMPORTANT !!!
52
+	 * remember that shortcode content should be RETURNED and NOT echoed out
53
+	 *
54
+	 * @param array $attributes
55
+	 * @return string
56
+	 */
57
+	public function processShortcode($attributes = array())
58
+	{
59
+		// TODO: Implement processShortcode() method.
60
+	}
61 61
 }
62 62
 // End of file EspressoThankYou.php
63 63
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoThankYou.php
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTxnPage.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -27,79 +27,79 @@
 block discarded – undo
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * the actual shortcode tag that gets registered with WordPress
32
-     *
33
-     * @return string
34
-     */
35
-    public function getTag()
36
-    {
37
-        return 'ESPRESSO_TXN_PAGE';
38
-    }
30
+	/**
31
+	 * the actual shortcode tag that gets registered with WordPress
32
+	 *
33
+	 * @return string
34
+	 */
35
+	public function getTag()
36
+	{
37
+		return 'ESPRESSO_TXN_PAGE';
38
+	}
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * a place for adding any initialization code that needs to run prior to wp_header().
44
-     * this may be required for shortcodes that utilize a corresponding module,
45
-     * and need to enqueue assets for that module
46
-     *
47
-     * @return void
48
-     * @throws \Exception
49
-     * @throws \EE_Error
50
-     */
51
-    public function initializeShortcode()
52
-    {
53
-        $transaction = null;
54
-        if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
55
-            /** @var EEM_Transaction $EEM_Transaction */
56
-            $EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
57
-            $transaction = $EEM_Transaction->get_transaction_from_reg_url_link();
58
-        }
59
-        if ($transaction instanceof EE_Transaction) {
60
-            $payment_method = null;
61
-            $payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', null);
62
-            if ($payment_method_slug) {
63
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug);
64
-            }
65
-            if ($payment_method instanceof EE_Payment_Method && $payment_method->is_off_site()) {
66
-                $gateway = $payment_method->type_obj()->get_gateway();
67
-                if (
68
-                    $gateway instanceof EE_Offsite_Gateway
69
-                    && $gateway->handle_IPN_in_this_request(
70
-                        \EE_Registry::instance()->REQ->params(),
71
-                        true
72
-                    )
73
-                ) {
74
-                    /** @type EE_Payment_Processor $payment_processor */
75
-                    $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
76
-                    $payment_processor->process_ipn($_REQUEST, $transaction, $payment_method);
77
-                }
78
-            }
79
-            //allow gateways to add a filter to stop rendering the page
80
-            if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', false)) {
81
-                exit;
82
-            }
83
-        }
84
-    }
42
+	/**
43
+	 * a place for adding any initialization code that needs to run prior to wp_header().
44
+	 * this may be required for shortcodes that utilize a corresponding module,
45
+	 * and need to enqueue assets for that module
46
+	 *
47
+	 * @return void
48
+	 * @throws \Exception
49
+	 * @throws \EE_Error
50
+	 */
51
+	public function initializeShortcode()
52
+	{
53
+		$transaction = null;
54
+		if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
55
+			/** @var EEM_Transaction $EEM_Transaction */
56
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
57
+			$transaction = $EEM_Transaction->get_transaction_from_reg_url_link();
58
+		}
59
+		if ($transaction instanceof EE_Transaction) {
60
+			$payment_method = null;
61
+			$payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', null);
62
+			if ($payment_method_slug) {
63
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug);
64
+			}
65
+			if ($payment_method instanceof EE_Payment_Method && $payment_method->is_off_site()) {
66
+				$gateway = $payment_method->type_obj()->get_gateway();
67
+				if (
68
+					$gateway instanceof EE_Offsite_Gateway
69
+					&& $gateway->handle_IPN_in_this_request(
70
+						\EE_Registry::instance()->REQ->params(),
71
+						true
72
+					)
73
+				) {
74
+					/** @type EE_Payment_Processor $payment_processor */
75
+					$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
76
+					$payment_processor->process_ipn($_REQUEST, $transaction, $payment_method);
77
+				}
78
+			}
79
+			//allow gateways to add a filter to stop rendering the page
80
+			if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', false)) {
81
+				exit;
82
+			}
83
+		}
84
+	}
85 85
 
86 86
 
87 87
 
88
-    /**
89
-     * callback that runs when the shortcode is encountered in post content.
90
-     * IMPORTANT !!!
91
-     * remember that shortcode content should be RETURNED and NOT echoed out
92
-     *
93
-     * @param array $attributes
94
-     * @return string
95
-     */
96
-    public function processShortcode($attributes = array())
97
-    {
98
-        return __(
99
-            'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.',
100
-            'event_espresso'
101
-        );
102
-    }
88
+	/**
89
+	 * callback that runs when the shortcode is encountered in post content.
90
+	 * IMPORTANT !!!
91
+	 * remember that shortcode content should be RETURNED and NOT echoed out
92
+	 *
93
+	 * @param array $attributes
94
+	 * @return string
95
+	 */
96
+	public function processShortcode($attributes = array())
97
+	{
98
+		return __(
99
+			'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.',
100
+			'event_espresso'
101
+		);
102
+	}
103 103
 }
104 104
 // End of file EspressoTxnPage.php
105 105
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTxnPage.php
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -21,50 +21,50 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * the actual shortcode tag that gets registered with WordPress
26
-     *
27
-     * @return string
28
-     */
29
-    public function getTag()
30
-    {
31
-        return 'ESPRESSO_TICKET_SELECTOR';
32
-    }
24
+	/**
25
+	 * the actual shortcode tag that gets registered with WordPress
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function getTag()
30
+	{
31
+		return 'ESPRESSO_TICKET_SELECTOR';
32
+	}
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * a place for adding any initialization code that needs to run prior to wp_header().
38
-     * this may be required for shortcodes that utilize a corresponding module,
39
-     * and need to enqueue assets for that module
40
-     *
41
-     * @return void
42
-     */
43
-    public function initializeShortcode()
44
-    {
45
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
46
-    }
36
+	/**
37
+	 * a place for adding any initialization code that needs to run prior to wp_header().
38
+	 * this may be required for shortcodes that utilize a corresponding module,
39
+	 * and need to enqueue assets for that module
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function initializeShortcode()
44
+	{
45
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
46
+	}
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     * callback that runs when the shortcode is encountered in post content.
52
-     * IMPORTANT !!!
53
-     * remember that shortcode content should be RETURNED and NOT echoed out
54
-     *
55
-     * @param array $attributes
56
-     * @return string
57
-     */
58
-    public function processShortcode($attributes = array())
59
-    {
60
-        extract($attributes, EXTR_OVERWRITE);
61
-        $event_id = isset($event_id) ? $event_id : 0;
62
-        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
63
-        ob_start();
64
-        do_action('AHEE_event_details_before_post', $event_id);
65
-        espresso_ticket_selector($event);
66
-        do_action('AHEE_event_details_after_post');
67
-        return ob_get_clean();    }
50
+	/**
51
+	 * callback that runs when the shortcode is encountered in post content.
52
+	 * IMPORTANT !!!
53
+	 * remember that shortcode content should be RETURNED and NOT echoed out
54
+	 *
55
+	 * @param array $attributes
56
+	 * @return string
57
+	 */
58
+	public function processShortcode($attributes = array())
59
+	{
60
+		extract($attributes, EXTR_OVERWRITE);
61
+		$event_id = isset($event_id) ? $event_id : 0;
62
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
63
+		ob_start();
64
+		do_action('AHEE_event_details_before_post', $event_id);
65
+		espresso_ticket_selector($event);
66
+		do_action('AHEE_event_details_after_post');
67
+		return ob_get_clean();    }
68 68
 }
69 69
 // End of file EspressoTicketSelector.php
70 70
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
         do_action('AHEE_event_details_before_post', $event_id);
65 65
         espresso_ticket_selector($event);
66 66
         do_action('AHEE_event_details_after_post');
67
-        return ob_get_clean();    }
67
+        return ob_get_clean(); }
68 68
 }
69 69
 // End of file EspressoTicketSelector.php
70 70
 // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php
71 71
\ No newline at end of file
Please login to merge, or discard this patch.