Completed
Branch EDTR/plugins-page-asset-manage... (cb3385)
by
unknown
27:13 queued 18:46
created
core/domain/services/assets/WordpressPluginsPageAssetManager.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -22,91 +22,91 @@
 block discarded – undo
22 22
 class WordpressPluginsPageAssetManager extends ReactAssetManager
23 23
 {
24 24
 
25
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page';
25
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page';
26 26
 
27
-    const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page';
27
+	const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page';
28 28
 
29
-    /**
30
-     * @var ExitModal $exit_modal
31
-     */
32
-    private $exit_modal;
29
+	/**
30
+	 * @var ExitModal $exit_modal
31
+	 */
32
+	private $exit_modal;
33 33
 
34 34
 
35
-    /**
36
-     * WordpressPluginsPageAssetManager constructor.
37
-     *
38
-     * @param AssetCollection $assets
39
-     * @param DomainInterface $domain
40
-     * @param Registry        $registry
41
-     * @param ExitModal       $exit_modal
42
-     */
43
-    public function __construct(
44
-        AssetCollection $assets,
45
-        DomainInterface $domain,
46
-        Registry $registry,
47
-        ExitModal $exit_modal
48
-    ) {
49
-        $this->exit_modal = $exit_modal;
50
-        parent::__construct($domain, $assets, $registry);
51
-    }
35
+	/**
36
+	 * WordpressPluginsPageAssetManager constructor.
37
+	 *
38
+	 * @param AssetCollection $assets
39
+	 * @param DomainInterface $domain
40
+	 * @param Registry        $registry
41
+	 * @param ExitModal       $exit_modal
42
+	 */
43
+	public function __construct(
44
+		AssetCollection $assets,
45
+		DomainInterface $domain,
46
+		Registry $registry,
47
+		ExitModal $exit_modal
48
+	) {
49
+		$this->exit_modal = $exit_modal;
50
+		parent::__construct($domain, $assets, $registry);
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @inheritDoc
56
-     */
57
-    public function addAssets()
58
-    {
59
-        parent::addAssets();
60
-        $this->registerJavascript();
61
-        $this->registerStyleSheets();
62
-    }
54
+	/**
55
+	 * @inheritDoc
56
+	 */
57
+	public function addAssets()
58
+	{
59
+		parent::addAssets();
60
+		$this->registerJavascript();
61
+		$this->registerStyleSheets();
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * Register javascript assets
67
-     *
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidEntityException
70
-     * @throws DuplicateCollectionIdentifierException
71
-     * @throws DomainException
72
-     */
73
-    private function registerJavascript()
74
-    {
75
-        $this->addJs(
76
-            WordpressPluginsPageAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
77
-            [
78
-                ReactAssetManager::JS_HANDLE_REACT,
79
-                ReactAssetManager::JS_HANDLE_REACT_DOM,
80
-                CoreAssetManager::JS_HANDLE_JS_CORE,
81
-                'wp-components',
82
-                'wp-i18n',
83
-                'wp-url'
84
-            ]
85
-        )
86
-        ->setRequiresTranslation()
87
-        ->enqueueAsset();
65
+	/**
66
+	 * Register javascript assets
67
+	 *
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidEntityException
70
+	 * @throws DuplicateCollectionIdentifierException
71
+	 * @throws DomainException
72
+	 */
73
+	private function registerJavascript()
74
+	{
75
+		$this->addJs(
76
+			WordpressPluginsPageAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
77
+			[
78
+				ReactAssetManager::JS_HANDLE_REACT,
79
+				ReactAssetManager::JS_HANDLE_REACT_DOM,
80
+				CoreAssetManager::JS_HANDLE_JS_CORE,
81
+				'wp-components',
82
+				'wp-i18n',
83
+				'wp-url'
84
+			]
85
+		)
86
+		->setRequiresTranslation()
87
+		->enqueueAsset();
88 88
 
89
-        $this->registry->addData(
90
-            'exitModalInfo',
91
-            $this->exit_modal->getExitSurveyInfo()
92
-        );
93
-    }
89
+		$this->registry->addData(
90
+			'exitModalInfo',
91
+			$this->exit_modal->getExitSurveyInfo()
92
+		);
93
+	}
94 94
 
95 95
 
96
-    /**
97
-     * Register CSS assets.
98
-     *
99
-     * @throws DuplicateCollectionIdentifierException
100
-     * @throws InvalidDataTypeException
101
-     * @throws InvalidEntityException
102
-     * @throws DomainException
103
-     */
104
-    private function registerStyleSheets()
105
-    {
106
-        $this->addCss(
107
-            WordpressPluginsPageAssetManager::CSS_HANDLE_WP_PLUGINS_PAGE,
108
-            ['wp-components']
109
-        )
110
-        ->enqueueAsset();
111
-    }
96
+	/**
97
+	 * Register CSS assets.
98
+	 *
99
+	 * @throws DuplicateCollectionIdentifierException
100
+	 * @throws InvalidDataTypeException
101
+	 * @throws InvalidEntityException
102
+	 * @throws DomainException
103
+	 */
104
+	private function registerStyleSheets()
105
+	{
106
+		$this->addCss(
107
+			WordpressPluginsPageAssetManager::CSS_HANDLE_WP_PLUGINS_PAGE,
108
+			['wp-components']
109
+		)
110
+		->enqueueAsset();
111
+	}
112 112
 }
Please login to merge, or discard this patch.
core/domain/services/assets/EspressoAdminAssetManager.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -15,104 +15,104 @@
 block discarded – undo
15 15
 class EspressoAdminAssetManager extends AssetManager
16 16
 {
17 17
 
18
-    const JS_HANDLE_INJECT_WP = 'ee-inject-wp';
18
+	const JS_HANDLE_INJECT_WP = 'ee-inject-wp';
19 19
 
20
-    const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie';
20
+	const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie';
21 21
 
22
-    const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr';
22
+	const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr';
23 23
 
24
-    const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride';
24
+	const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride';
25 25
 
26
-    const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css';
26
+	const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css';
27 27
 
28
-    const CSS_HANDLE_JOYRIDE = 'joyride-css';
28
+	const CSS_HANDLE_JOYRIDE = 'joyride-css';
29 29
 
30 30
 
31
-    /**
32
-     * @inheritDoc
33
-     */
34
-    public function addAssets()
35
-    {
36
-        $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN);
37
-        $this->registerJavascript($joyride);
38
-        $this->registerStyleSheets($joyride);
39
-    }
31
+	/**
32
+	 * @inheritDoc
33
+	 */
34
+	public function addAssets()
35
+	{
36
+		$joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN);
37
+		$this->registerJavascript($joyride);
38
+		$this->registerStyleSheets($joyride);
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Register javascript assets
44
-     *
45
-     * @param bool $joyride
46
-     */
47
-    private function registerJavascript($joyride = false)
48
-    {
49
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
50
-        // Note: the intention of this script is to only do TARGETED injections.
51
-        //ie: only injecting on certain script calls.
52
-        $this->addJavascript(
53
-            EspressoAdminAssetManager::JS_HANDLE_INJECT_WP,
54
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
55
-            ['jquery'],
56
-            true,
57
-            EVENT_ESPRESSO_VERSION
58
-        );
59
-        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook,
60
-        // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' );
61
-        if (! $joyride) {
62
-            return;
63
-        }
64
-        // register cookie script for future dependencies
65
-        $this->addJavascript(
66
-            EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
67
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
68
-            ['jquery'],
69
-            true,
70
-            '2.1'
71
-        );
72
-        $this->addJavascript(
73
-            EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR,
74
-            EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
75
-            [],
76
-            true,
77
-            '2.1'
78
-        );
79
-        // wanna go for a joyride?
80
-        $this->addJavascript(
81
-            EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE,
82
-            EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
83
-            [
84
-                EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
85
-                EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR
86
-            ],
87
-            '2.1',
88
-            true
89
-        )->enqueueAsset();
90
-    }
42
+	/**
43
+	 * Register javascript assets
44
+	 *
45
+	 * @param bool $joyride
46
+	 */
47
+	private function registerJavascript($joyride = false)
48
+	{
49
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
50
+		// Note: the intention of this script is to only do TARGETED injections.
51
+		//ie: only injecting on certain script calls.
52
+		$this->addJavascript(
53
+			EspressoAdminAssetManager::JS_HANDLE_INJECT_WP,
54
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
55
+			['jquery'],
56
+			true,
57
+			EVENT_ESPRESSO_VERSION
58
+		);
59
+		// joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook,
60
+		// can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' );
61
+		if (! $joyride) {
62
+			return;
63
+		}
64
+		// register cookie script for future dependencies
65
+		$this->addJavascript(
66
+			EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
67
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
68
+			['jquery'],
69
+			true,
70
+			'2.1'
71
+		);
72
+		$this->addJavascript(
73
+			EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR,
74
+			EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
75
+			[],
76
+			true,
77
+			'2.1'
78
+		);
79
+		// wanna go for a joyride?
80
+		$this->addJavascript(
81
+			EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE,
82
+			EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
83
+			[
84
+				EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
85
+				EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR
86
+			],
87
+			'2.1',
88
+			true
89
+		)->enqueueAsset();
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * Register CSS assets.
95
-     *
96
-     * @param bool $joyride
97
-     */
98
-    private function registerStyleSheets($joyride = false)
99
-    {
100
-        if (! $joyride) {
101
-            return;
102
-        }       // joyride style
103
-        $this->addStylesheet(
104
-            EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE,
105
-            EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css',
106
-            [],
107
-            'all',
108
-            '2.1'
109
-        );
110
-        $this->addStylesheet(
111
-            EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE,
112
-            EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
113
-            ['joyride-css'],
114
-            'all',
115
-            EVENT_ESPRESSO_VERSION
116
-        )->enqueueAsset();
117
-    }
93
+	/**
94
+	 * Register CSS assets.
95
+	 *
96
+	 * @param bool $joyride
97
+	 */
98
+	private function registerStyleSheets($joyride = false)
99
+	{
100
+		if (! $joyride) {
101
+			return;
102
+		}       // joyride style
103
+		$this->addStylesheet(
104
+			EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE,
105
+			EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css',
106
+			[],
107
+			'all',
108
+			'2.1'
109
+		);
110
+		$this->addStylesheet(
111
+			EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE,
112
+			EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
113
+			['joyride-css'],
114
+			'all',
115
+			EVENT_ESPRESSO_VERSION
116
+		)->enqueueAsset();
117
+	}
118 118
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,27 +51,27 @@  discard block
 block discarded – undo
51 51
         //ie: only injecting on certain script calls.
52 52
         $this->addJavascript(
53 53
             EspressoAdminAssetManager::JS_HANDLE_INJECT_WP,
54
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
54
+            EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js',
55 55
             ['jquery'],
56 56
             true,
57 57
             EVENT_ESPRESSO_VERSION
58 58
         );
59 59
         // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook,
60 60
         // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' );
61
-        if (! $joyride) {
61
+        if ( ! $joyride) {
62 62
             return;
63 63
         }
64 64
         // register cookie script for future dependencies
65 65
         $this->addJavascript(
66 66
             EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
67
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
67
+            EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js',
68 68
             ['jquery'],
69 69
             true,
70 70
             '2.1'
71 71
         );
72 72
         $this->addJavascript(
73 73
             EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR,
74
-            EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
74
+            EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js',
75 75
             [],
76 76
             true,
77 77
             '2.1'
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         // wanna go for a joyride?
80 80
         $this->addJavascript(
81 81
             EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE,
82
-            EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
82
+            EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js',
83 83
             [
84 84
                 EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
85 85
                 EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR
@@ -97,19 +97,19 @@  discard block
 block discarded – undo
97 97
      */
98 98
     private function registerStyleSheets($joyride = false)
99 99
     {
100
-        if (! $joyride) {
100
+        if ( ! $joyride) {
101 101
             return;
102 102
         }       // joyride style
103 103
         $this->addStylesheet(
104 104
             EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE,
105
-            EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css',
105
+            EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css',
106 106
             [],
107 107
             'all',
108 108
             '2.1'
109 109
         );
110 110
         $this->addStylesheet(
111 111
             EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE,
112
-            EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
112
+            EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css',
113 113
             ['joyride-css'],
114 114
             'all',
115 115
             EVENT_ESPRESSO_VERSION
Please login to merge, or discard this patch.
core/domain/services/admin/ExitModal.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
 class ExitModal
17 17
 {
18 18
 
19
-    /**
20
-     * ExitModal constructor.
21
-     */
22
-    public function __construct()
23
-    {
24
-    }
19
+	/**
20
+	 * ExitModal constructor.
21
+	 */
22
+	public function __construct()
23
+	{
24
+	}
25 25
 
26 26
 
27
-    /**
28
-     * @return array
29
-     * @since $VID:$
30
-     */
31
-    public function getExitSurveyInfo()
32
-    {
33
-        $current_user = new WP_User(get_current_user_id());
34
-        return [
35
-            'firstName'     => htmlspecialchars($current_user->user_firstname),
36
-            'emailAddress'  => htmlspecialchars($current_user->user_email),
37
-            'website'       => htmlspecialchars(site_url()),
38
-            'isModalActive' => $this->isModalActive()
39
-        ];
40
-    }
27
+	/**
28
+	 * @return array
29
+	 * @since $VID:$
30
+	 */
31
+	public function getExitSurveyInfo()
32
+	{
33
+		$current_user = new WP_User(get_current_user_id());
34
+		return [
35
+			'firstName'     => htmlspecialchars($current_user->user_firstname),
36
+			'emailAddress'  => htmlspecialchars($current_user->user_email),
37
+			'website'       => htmlspecialchars(site_url()),
38
+			'isModalActive' => $this->isModalActive()
39
+		];
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Exposes a filter switch for turning off the enqueueing of the modal script.
45
-     * @return bool
46
-     */
47
-    private function isModalActive()
48
-    {
49
-        return filter_var(
50
-            apply_filters(
51
-                'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
52
-                true
53
-            ),
54
-            FILTER_VALIDATE_BOOLEAN
55
-        );
56
-    }
43
+	/**
44
+	 * Exposes a filter switch for turning off the enqueueing of the modal script.
45
+	 * @return bool
46
+	 */
47
+	private function isModalActive()
48
+	{
49
+		return filter_var(
50
+			apply_filters(
51
+				'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
52
+				true
53
+			),
54
+			FILTER_VALIDATE_BOOLEAN
55
+		);
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * @deprecated $VID:$
61
-     */
62
-    public function modalContainer()
63
-    {
64
-    }
59
+	/**
60
+	 * @deprecated $VID:$
61
+	 */
62
+	public function modalContainer()
63
+	{
64
+	}
65 65
 
66
-    /**
67
-     * @deprecated $VID:$
68
-     */
69
-    public function enqueues()
70
-    {
71
-    }
66
+	/**
67
+	 * @deprecated $VID:$
68
+	 */
69
+	public function enqueues()
70
+	{
71
+	}
72 72
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 2 patches
Indentation   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -16,726 +16,726 @@
 block discarded – undo
16 16
 class EE_Admin_Page_Loader
17 17
 {
18 18
 
19
-    /**
20
-     * @var LoaderInterface $loader
21
-     */
22
-    protected $loader;
23
-
24
-    /**
25
-     * _installed_pages
26
-     * objects for page_init objects detected and loaded
27
-     *
28
-     * @access private
29
-     * @var EE_Admin_Page_Init[]
30
-     */
31
-    private $_installed_pages = array();
32
-
33
-
34
-    /**
35
-     * this is used to hold the registry of menu slugs for all the installed admin pages
36
-     *
37
-     * @var array
38
-     */
39
-    private $_menu_slugs = array();
40
-
41
-
42
-    /**
43
-     * _caffeinated_extends
44
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
45
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
46
-     *
47
-     * @var array
48
-     */
49
-    private $_caffeinated_extends = array();
50
-
51
-
52
-    /**
53
-     * _current_caf_extend_slug
54
-     * This property is used for holding the page slug that is required for referencing the correct
55
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
56
-     *
57
-     * @var array
58
-     */
59
-    private $_current_caf_extend_slug;
60
-
61
-    /**
62
-     * _prepped_menu_maps
63
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
64
-     *
65
-     * @since  4.4.0
66
-     * @var EE_Admin_Page_Menu_Map[]
67
-     */
68
-    private $_prepped_menu_maps = array();
69
-
70
-
71
-    /**
72
-     * _admin_menu_groups
73
-     * array that holds the group headings and details for
74
-     *
75
-     * @access private
76
-     * @var array
77
-     */
78
-    private $_admin_menu_groups = array();
79
-
80
-
81
-    /**
82
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
83
-     * pages.
84
-     *
85
-     * @var string
86
-     */
87
-    public $hook_file;
88
-
89
-
90
-    /**
91
-     * @throws InvalidArgumentException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidInterfaceException
94
-     */
95
-    public function __construct()
96
-    {
97
-        $this->loader = LoaderFactory::getLoader();
98
-    }
99
-
100
-
101
-    /**
102
-     * @throws EE_Error
103
-     * @throws ReflectionException
104
-     * @since $VID:$
105
-     */
106
-    public function init()
107
-    {
108
-        // load menu_map classes
109
-        if (! class_exists('EE_Admin_Page_Menu_Map', false)) {
110
-            $map = require EE_ADMIN . 'EE_Admin_Page_Menu_Map.core.php';
111
-            if ($map) {
112
-                // define the default "groups" for the admin_pages
113
-                $this->_set_menu_groups();
114
-                // let's do a scan and see what installed pages we have
115
-                $this->_get_installed_pages();
116
-                // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
117
-                add_action('admin_menu', [$this, 'set_menus']);
118
-                add_action('network_admin_menu', [$this, 'set_network_menus']);
119
-            }
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
126
-     * files in the caffeinated folder.
127
-     *
128
-     * @access private
129
-     * @return void
130
-     */
131
-    private function _define_caffeinated_constants()
132
-    {
133
-        if (! defined('EE_CORE_CAF_ADMIN')) {
134
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
135
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
136
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
137
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
138
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
139
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
140
-        }
141
-    }
142
-
143
-
144
-    /**
145
-     * _set_menu_groups
146
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
147
-     *
148
-     * @access private
149
-     * @return void
150
-     * @throws EE_Error
151
-     */
152
-    private function _set_menu_groups()
153
-    {
154
-        // set array of EE_Admin_Page_Menu_Group objects
155
-        $groups = array(
156
-            'main'       => new EE_Admin_Page_Menu_Group(
157
-                array(
158
-                    'menu_label'   => __('Main', 'event_espresso'),
159
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
160
-                    'menu_slug'    => 'main',
161
-                    'capability'   => 'ee_read_ee',
162
-                    'menu_order'   => 0,
163
-                    'parent_slug'  => 'espresso_events',
164
-                )
165
-            ),
166
-            'management' => new EE_Admin_Page_Menu_Group(
167
-                array(
168
-                    'menu_label'   => __('Management', 'event_espresso'),
169
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
-                    'menu_slug'    => 'management',
171
-                    'capability'   => 'ee_read_ee',
172
-                    'menu_order'   => 10,
173
-                    'parent_slug'  => 'espresso_events',
174
-                )
175
-            ),
176
-            'settings'   => new EE_Admin_Page_Menu_Group(
177
-                array(
178
-                    'menu_label'   => __('Settings', 'event_espresso'),
179
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
-                    'menu_slug'    => 'settings',
181
-                    'capability'   => 'ee_read_ee',
182
-                    'menu_order'   => 30,
183
-                    'parent_slug'  => 'espresso_events',
184
-                )
185
-            ),
186
-            'templates'  => new EE_Admin_Page_Menu_Group(
187
-                array(
188
-                    'menu_label'   => __('Templates', 'event_espresso'),
189
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
190
-                    'menu_slug'    => 'templates',
191
-                    'capability'   => 'ee_read_ee',
192
-                    'menu_order'   => 40,
193
-                    'parent_slug'  => 'espresso_events',
194
-                )
195
-            ),
196
-            'extras'     => new EE_Admin_Page_Menu_Group(
197
-                array(
198
-                    'menu_label'              => __('Extras', 'event_espresso'),
199
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
200
-                    'menu_slug'               => 'extras',
201
-                    'capability'              => 'ee_read_ee',
202
-                    'menu_order'              => 50,
203
-                    'parent_slug'             => 'espresso_events',
204
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
205
-                )
206
-            ),
207
-            'tools'      => new EE_Admin_Page_Menu_Group(
208
-                array(
209
-                    'menu_label'   => __('Tools', 'event_espresso'),
210
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
211
-                    'menu_slug'    => 'tools',
212
-                    'capability'   => 'ee_read_ee',
213
-                    'menu_order'   => 60,
214
-                    'parent_slug'  => 'espresso_events',
215
-                )
216
-            ),
217
-            'addons'     => new EE_Admin_Page_Menu_Group(
218
-                array(
219
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
220
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
221
-                    'menu_slug'    => 'addons',
222
-                    'capability'   => 'ee_read_ee',
223
-                    'menu_order'   => 20,
224
-                    'parent_slug'  => 'espresso_events',
225
-                )
226
-            ),
227
-        );
228
-        $this->_admin_menu_groups = apply_filters(
229
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
230
-            $groups
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
237
-     * slug.  The other utility with this function is it validates that all the groups are instances of
238
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
239
-     *
240
-     * @return EE_Admin_Page_Menu_Group[]
241
-     * @throws EE_Error
242
-     * @since  4.4.0
243
-     */
244
-    private function _rearrange_menu_groups()
245
-    {
246
-        $groups = array();
247
-        // first let's order the menu groups by their internal menu order
248
-        // (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
249
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
250
-        foreach ($this->_admin_menu_groups as $group) {
251
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
252
-                throw new EE_Error(
253
-                    sprintf(
254
-                        __(
255
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
256
-                            'event_espresso'
257
-                        ),
258
-                        print_r($group, true)
259
-                    )
260
-                );
261
-            }
262
-            $groups[ $group->menu_slug ] = $group;
263
-        }
264
-        return $groups;
265
-    }
266
-
267
-
268
-    /**
269
-     * _get_installed_pages
270
-     * This just gets the list of installed EE_Admin_pages.
271
-     *
272
-     * @access private
273
-     * @return void
274
-     * @throws EE_Error
275
-     * @throws InvalidArgumentException
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     * @throws ReflectionException
279
-     */
280
-    private function _get_installed_pages()
281
-    {
282
-        $installed_refs = array();
283
-        $exclude = array('assets', 'templates');
284
-        // grab everything in the  admin core directory
285
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
286
-        if ($admin_screens) {
287
-            foreach ($admin_screens as $admin_screen) {
288
-                $admin_screen_name = basename($admin_screen);
289
-                // files and anything in the exclude array need not apply
290
-                if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
291
-                    // these folders represent the different EE admin pages
292
-                    $installed_refs[ $admin_screen_name ] = $admin_screen;
293
-                }
294
-            }
295
-        }
296
-        if (empty($installed_refs)) {
297
-            $error_msg[] = __(
298
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
299
-                'event_espresso'
300
-            );
301
-            $error_msg[] = $error_msg[0] . "\r\n"
302
-                           . sprintf(
303
-                               __(
304
-                                   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
305
-                                   'event_espresso'
306
-                               ),
307
-                               EE_ADMIN_PAGES
308
-                           );
309
-            throw new EE_Error(implode('||', $error_msg));
310
-        }
311
-        // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
312
-        $installed_refs = $this->_set_caffeinated($installed_refs);
313
-        // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
314
-        $installed_refs = apply_filters(
315
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
316
-            $installed_refs
317
-        );
318
-        $this->_caffeinated_extends = apply_filters(
319
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
320
-            $this->_caffeinated_extends
321
-        );
322
-        // loop through admin pages and setup the $_installed_pages array.
323
-        $hooks_ref = [];
324
-        foreach ($installed_refs as $page => $path) {
325
-            // don't load the page init class IF IT's ALREADY LOADED !!!
326
-            if (isset($this->_installed_pages[ $page ])
327
-                && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init
328
-            ) {
329
-                continue;
330
-            }
331
-            // set autoloaders for our admin page classes based on included path information
332
-            EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
333
-            // build list of installed pages
334
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
335
-            // verify returned object
336
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
337
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338
-                    continue;
339
-                }
340
-                // skip if in full maintenance mode and maintenance_mode_parent is set
341
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
342
-                if (empty($maintenance_mode_parent)
343
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
344
-                ) {
345
-                    unset($installed_refs[ $page ]);
346
-                    continue;
347
-                }
348
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
349
-                $this->_menu_slugs[ $menu_slug ] = $page;
350
-                // flag for register hooks on extended pages b/c extended pages use the default INIT.
351
-                $extend = false;
352
-                // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
353
-                if (isset($this->_caffeinated_extends[ $page ])) {
354
-                    $this->_current_caf_extend_slug = $page;
355
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
356
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
357
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
358
-                    add_filter(
359
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
360
-                        static function ($path_to_file) use ($caf_path) {
361
-                            return $caf_path;
362
-                        }
363
-                    );
364
-                    add_filter(
365
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
366
-                        static function ($admin_page) use ($caf_admin_page) {
367
-                            return $caf_admin_page;
368
-                        }
369
-                    );
370
-                    $extend = true;
371
-                }
372
-                // let's do the registered hooks
373
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
374
-                foreach ($extended_hooks as $key => $value) {
375
-                    $hooks_ref[] = $value;
376
-                }
377
-            }
378
-        }
379
-        // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
380
-        // first make sure we've got unique values
381
-        $hooks_ref = array_unique($hooks_ref);
382
-        // now let's loop and require!
383
-        foreach ($hooks_ref as $path) {
384
-            require_once($path);
385
-        }
386
-        // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
387
-        global $ee_menu_slugs;
388
-        $ee_menu_slugs = $this->_menu_slugs;
389
-        // we need to loop again to run any early code
390
-        foreach ($installed_refs as $page => $path) {
391
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
392
-                $this->_installed_pages[ $page ]->do_initial_loads();
393
-            }
394
-        }
395
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
396
-    }
397
-
398
-
399
-    /**
400
-     * get_admin_page_object
401
-     *
402
-     * @param string $page_slug
403
-     * @return EE_Admin_Page
404
-     */
405
-    public function get_admin_page_object($page_slug = '')
406
-    {
407
-        if (isset($this->_installed_pages[ $page_slug ])) {
408
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
409
-        }
410
-        return null;
411
-    }
412
-
413
-
414
-    /**
415
-     * _get_classname_for_admin_page
416
-     * generates an "Admin Page" class based on the directory  name
417
-     *
418
-     * @param $dir_name
419
-     * @return string
420
-     */
421
-    private function _get_classname_for_admin_page($dir_name = '')
422
-    {
423
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
424
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
425
-    }
426
-
427
-
428
-    /**
429
-     * _get_classname_for_admin_init_page
430
-     * generates an "Admin Page Init" class based on the directory  name
431
-     *
432
-     * @param $dir_name
433
-     * @return string
434
-     */
435
-    private function _get_classname_for_admin_init_page($dir_name = '')
436
-    {
437
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
438
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
439
-    }
440
-
441
-
442
-    /**
443
-     * _load_admin_page
444
-     * Loads and instantiates page_init object for a single EE_admin page.
445
-     *
446
-     * @param string $page page_reference
447
-     * @param string $path
448
-     * @return object|bool  return page object if valid, bool false if not.
449
-     * @throws EE_Error
450
-     * @throws InvalidArgumentException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     */
454
-    private function _load_admin_page($page = '', $path = '')
455
-    {
456
-        $class_name = $this->_get_classname_for_admin_init_page($page);
457
-        $admin_page = $this->loader->getShared($class_name);
458
-        if (! $admin_page || ! class_exists($class_name, false)) {
459
-            $inner_error_msg = '<br />'
460
-                               . sprintf(
461
-                                   esc_html__(
462
-                                       'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463
-                                       'event_espresso'
464
-                                   ),
465
-                                   '<strong>' . $class_name . '</strong>'
466
-                               );
467
-            $error_msg[] = sprintf(
468
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
469
-                $page
470
-            );
471
-            $error_msg[] = $error_msg[0]
472
-                           . "\r\n"
473
-                           . sprintf(
474
-                               esc_html__(
475
-                                   'There is no Init class in place for the %s admin page.',
476
-                                   'event_espresso'
477
-                               ),
478
-                               $page
479
-                           )
480
-                           . $inner_error_msg;
481
-            throw new EE_Error(implode('||', $error_msg));
482
-        }
483
-        return $admin_page;
484
-    }
485
-
486
-
487
-    /**
488
-     * set_menus
489
-     * This method sets up the menus for EE Admin Pages
490
-     *
491
-     * @access private
492
-     * @return void
493
-     * @throws EE_Error
494
-     * @throws InvalidDataTypeException
495
-     * @throws ReflectionException
496
-     */
497
-    public function set_menus()
498
-    {
499
-        // prep the menu pages (sort, group.)
500
-        $this->_prep_pages();
501
-        foreach ($this->_prepped_menu_maps as $menu_map) {
502
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
503
-                $menu_map->add_menu_page();
504
-            }
505
-        }
506
-    }
507
-
508
-
509
-    /**
510
-     * set_network_menus
511
-     * This method sets up the menus for network EE Admin Pages.
512
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
513
-     * are only added to the menu map if they are intended for the admin menu
514
-     *
515
-     * @return void
516
-     * @throws EE_Error
517
-     * @throws InvalidDataTypeException
518
-     * @throws ReflectionException
519
-     */
520
-    public function set_network_menus()
521
-    {
522
-        $this->_prep_pages();
523
-        foreach ($this->_prepped_menu_maps as $menu_map) {
524
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
525
-                $menu_map->add_menu_page(true);
526
-            }
527
-        }
528
-    }
529
-
530
-
531
-    /**
532
-     * _prep_pages
533
-     * sets the _prepped_menu_maps property
534
-     *
535
-     * @access private
536
-     * @return void
537
-     * @throws EE_Error
538
-     * @throws InvalidDataTypeException
539
-     */
540
-    private function _prep_pages()
541
-    {
542
-        $pages_array = array();
543
-        // rearrange _admin_menu_groups to be indexed by group slug.
544
-        $menu_groups = $this->_rearrange_menu_groups();
545
-        foreach ($this->_installed_pages as $page) {
546
-            if ($page instanceof EE_Admin_page_Init) {
547
-                $page_map = $page->get_menu_map();
548
-                // if we've got an array then the menu map is in the old format
549
-                // so let's throw a persistent notice that the admin system isn't setup correctly for this item.
550
-                if ($page_map === null || is_array($page_map)) {
551
-                    new PersistentAdminNotice(
552
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
553
-                        sprintf(
554
-                            __(
555
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
556
-                                'event_espresso'
557
-                            ),
558
-                            $page->label
559
-                        )
560
-                    );
561
-                    continue;
562
-                }
563
-                // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
564
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
565
-                    throw new EE_Error(
566
-                        sprintf(
567
-                            __(
568
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
569
-                                'event_espresso'
570
-                            ),
571
-                            $page->label,
572
-                            $page_map
573
-                        )
574
-                    );
575
-                }
576
-                // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
577
-                if (empty($page_map->maintenance_mode_parent)
578
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
579
-                ) {
580
-                    continue;
581
-                }
582
-                // assign to group (remember $page_map has the admin page stored in it).
583
-                $pages_array[ $page_map->menu_group ][] = $page_map;
584
-            }
585
-        }
586
-        if (empty($pages_array)) {
587
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
588
-        }
589
-        // let's sort the groups, make sure it's a valid group, add header (if to show).
590
-        foreach ($pages_array as $group => $menu_maps) {
591
-            // valid_group?
592
-            if (! array_key_exists($group, $menu_groups)) {
593
-                continue;
594
-            }
595
-            // sort pages.
596
-            usort($menu_maps, array($this, '_sort_menu_maps'));
597
-            // prepend header
598
-            array_unshift($menu_maps, $menu_groups[ $group ]);
599
-            // reset $pages_array with prepped data
600
-            $pages_array[ $group ] = $menu_maps;
601
-        }
602
-
603
-        // now let's setup the _prepped_menu_maps property
604
-        foreach ($menu_groups as $group => $group_objs) {
605
-            if (isset($pages_array[ $group ])) {
606
-                foreach ($pages_array[ $group ] as $key => $value) {
607
-                    $this->_prepped_menu_maps[] = $value;
608
-                }
609
-            }
610
-        }
611
-    }
612
-
613
-
614
-    /**
615
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
616
-     * In this method there are three checks being done:
617
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
618
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
619
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
620
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
621
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
622
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
623
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
624
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
625
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
626
-     * admin_pages)
627
-     *
628
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
629
-     *                              loaded.
630
-     * @return array
631
-     * @throws EE_Error
632
-     */
633
-    private function _set_caffeinated($installed_refs)
634
-    {
635
-        // first let's check if there IS a caffeinated folder. If there is not then lets get out.
636
-        if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) {
637
-            return $installed_refs;
638
-        }
639
-        $this->_define_caffeinated_constants();
640
-        $exclude = array('tickets');
641
-        // okay let's setup an "New" pages first (we'll return installed refs later)
642
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
643
-        if ($new_admin_screens) {
644
-            foreach ($new_admin_screens as $admin_screen) {
645
-                $admin_screen_name = basename($admin_screen);
646
-                // files and anything in the exclude array need not apply
647
-                if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
648
-                    // these folders represent the different NEW EE admin pages
649
-                    $installed_refs[ $admin_screen_name ] = $admin_screen;
650
-                    // set autoloaders for our admin page classes based on included path information
651
-                    EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen);
652
-                }
653
-            }
654
-        }
655
-        // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
656
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
657
-        if ($extends) {
658
-            foreach ($extends as $extend) {
659
-                if (is_dir($extend)) {
660
-                    $extend_ref = basename($extend);
661
-                    // now let's make sure there is a file that matches the expected format
662
-                    $filename = str_replace(
663
-                        ' ',
664
-                        '_',
665
-                        ucwords(
666
-                            str_replace(
667
-                                '_',
668
-                                ' ',
669
-                                $extend_ref
670
-                            )
671
-                        )
672
-                    );
673
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
674
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
675
-                        array('\\', '/'),
676
-                        '/',
677
-                        EE_CORE_CAF_ADMIN
678
-                        . 'extend/'
679
-                        . $extend_ref
680
-                        . '/'
681
-                        . $filename
682
-                        . '.core.php'
683
-                    );
684
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
685
-                    // set autoloaders for our admin page classes based on included path information
686
-                    EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend);
687
-                }
688
-            }
689
-        }
690
-        // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
691
-        $ee_admin_hooks = array();
692
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
693
-        if ($hooks) {
694
-            foreach ($hooks as $hook) {
695
-                if (is_readable($hook)) {
696
-                    require_once $hook;
697
-                    $classname = str_replace(
698
-                        [EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'],
699
-                        '',
700
-                        $hook
701
-                    );
702
-                    if (class_exists($classname)) {
703
-                        $admin_page = $this->loader->getShared($classname);
704
-                        $ee_admin_hooks[] = $admin_page;
705
-                    }
706
-                }
707
-            }
708
-        }
709
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
710
-        return $installed_refs;
711
-    }
712
-
713
-
714
-    /**
715
-     * Utility method for sorting the _menu_maps (callback for usort php function)
716
-     *
717
-     * @since  4.4.0
718
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
719
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
720
-     * @return int    sort order
721
-     */
722
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
723
-    {
724
-        if ($a->menu_order === $b->menu_order) {
725
-            return 0;
726
-        }
727
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
728
-    }
729
-
730
-
731
-    /**
732
-     * _default_header_link
733
-     * This is just a dummy method to use with header submenu items
734
-     *
735
-     * @return bool false
736
-     */
737
-    public function _default_header_link()
738
-    {
739
-        return false;
740
-    }
19
+	/**
20
+	 * @var LoaderInterface $loader
21
+	 */
22
+	protected $loader;
23
+
24
+	/**
25
+	 * _installed_pages
26
+	 * objects for page_init objects detected and loaded
27
+	 *
28
+	 * @access private
29
+	 * @var EE_Admin_Page_Init[]
30
+	 */
31
+	private $_installed_pages = array();
32
+
33
+
34
+	/**
35
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
36
+	 *
37
+	 * @var array
38
+	 */
39
+	private $_menu_slugs = array();
40
+
41
+
42
+	/**
43
+	 * _caffeinated_extends
44
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
45
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	private $_caffeinated_extends = array();
50
+
51
+
52
+	/**
53
+	 * _current_caf_extend_slug
54
+	 * This property is used for holding the page slug that is required for referencing the correct
55
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
56
+	 *
57
+	 * @var array
58
+	 */
59
+	private $_current_caf_extend_slug;
60
+
61
+	/**
62
+	 * _prepped_menu_maps
63
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
64
+	 *
65
+	 * @since  4.4.0
66
+	 * @var EE_Admin_Page_Menu_Map[]
67
+	 */
68
+	private $_prepped_menu_maps = array();
69
+
70
+
71
+	/**
72
+	 * _admin_menu_groups
73
+	 * array that holds the group headings and details for
74
+	 *
75
+	 * @access private
76
+	 * @var array
77
+	 */
78
+	private $_admin_menu_groups = array();
79
+
80
+
81
+	/**
82
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
83
+	 * pages.
84
+	 *
85
+	 * @var string
86
+	 */
87
+	public $hook_file;
88
+
89
+
90
+	/**
91
+	 * @throws InvalidArgumentException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidInterfaceException
94
+	 */
95
+	public function __construct()
96
+	{
97
+		$this->loader = LoaderFactory::getLoader();
98
+	}
99
+
100
+
101
+	/**
102
+	 * @throws EE_Error
103
+	 * @throws ReflectionException
104
+	 * @since $VID:$
105
+	 */
106
+	public function init()
107
+	{
108
+		// load menu_map classes
109
+		if (! class_exists('EE_Admin_Page_Menu_Map', false)) {
110
+			$map = require EE_ADMIN . 'EE_Admin_Page_Menu_Map.core.php';
111
+			if ($map) {
112
+				// define the default "groups" for the admin_pages
113
+				$this->_set_menu_groups();
114
+				// let's do a scan and see what installed pages we have
115
+				$this->_get_installed_pages();
116
+				// set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
117
+				add_action('admin_menu', [$this, 'set_menus']);
118
+				add_action('network_admin_menu', [$this, 'set_network_menus']);
119
+			}
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
126
+	 * files in the caffeinated folder.
127
+	 *
128
+	 * @access private
129
+	 * @return void
130
+	 */
131
+	private function _define_caffeinated_constants()
132
+	{
133
+		if (! defined('EE_CORE_CAF_ADMIN')) {
134
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
135
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
136
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
137
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
138
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
139
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
140
+		}
141
+	}
142
+
143
+
144
+	/**
145
+	 * _set_menu_groups
146
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
147
+	 *
148
+	 * @access private
149
+	 * @return void
150
+	 * @throws EE_Error
151
+	 */
152
+	private function _set_menu_groups()
153
+	{
154
+		// set array of EE_Admin_Page_Menu_Group objects
155
+		$groups = array(
156
+			'main'       => new EE_Admin_Page_Menu_Group(
157
+				array(
158
+					'menu_label'   => __('Main', 'event_espresso'),
159
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
160
+					'menu_slug'    => 'main',
161
+					'capability'   => 'ee_read_ee',
162
+					'menu_order'   => 0,
163
+					'parent_slug'  => 'espresso_events',
164
+				)
165
+			),
166
+			'management' => new EE_Admin_Page_Menu_Group(
167
+				array(
168
+					'menu_label'   => __('Management', 'event_espresso'),
169
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
+					'menu_slug'    => 'management',
171
+					'capability'   => 'ee_read_ee',
172
+					'menu_order'   => 10,
173
+					'parent_slug'  => 'espresso_events',
174
+				)
175
+			),
176
+			'settings'   => new EE_Admin_Page_Menu_Group(
177
+				array(
178
+					'menu_label'   => __('Settings', 'event_espresso'),
179
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
+					'menu_slug'    => 'settings',
181
+					'capability'   => 'ee_read_ee',
182
+					'menu_order'   => 30,
183
+					'parent_slug'  => 'espresso_events',
184
+				)
185
+			),
186
+			'templates'  => new EE_Admin_Page_Menu_Group(
187
+				array(
188
+					'menu_label'   => __('Templates', 'event_espresso'),
189
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
190
+					'menu_slug'    => 'templates',
191
+					'capability'   => 'ee_read_ee',
192
+					'menu_order'   => 40,
193
+					'parent_slug'  => 'espresso_events',
194
+				)
195
+			),
196
+			'extras'     => new EE_Admin_Page_Menu_Group(
197
+				array(
198
+					'menu_label'              => __('Extras', 'event_espresso'),
199
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
200
+					'menu_slug'               => 'extras',
201
+					'capability'              => 'ee_read_ee',
202
+					'menu_order'              => 50,
203
+					'parent_slug'             => 'espresso_events',
204
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
205
+				)
206
+			),
207
+			'tools'      => new EE_Admin_Page_Menu_Group(
208
+				array(
209
+					'menu_label'   => __('Tools', 'event_espresso'),
210
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
211
+					'menu_slug'    => 'tools',
212
+					'capability'   => 'ee_read_ee',
213
+					'menu_order'   => 60,
214
+					'parent_slug'  => 'espresso_events',
215
+				)
216
+			),
217
+			'addons'     => new EE_Admin_Page_Menu_Group(
218
+				array(
219
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
220
+					'menu_label'   => __('Add-ons', 'event_espresso'),
221
+					'menu_slug'    => 'addons',
222
+					'capability'   => 'ee_read_ee',
223
+					'menu_order'   => 20,
224
+					'parent_slug'  => 'espresso_events',
225
+				)
226
+			),
227
+		);
228
+		$this->_admin_menu_groups = apply_filters(
229
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
230
+			$groups
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
237
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
238
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
239
+	 *
240
+	 * @return EE_Admin_Page_Menu_Group[]
241
+	 * @throws EE_Error
242
+	 * @since  4.4.0
243
+	 */
244
+	private function _rearrange_menu_groups()
245
+	{
246
+		$groups = array();
247
+		// first let's order the menu groups by their internal menu order
248
+		// (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
249
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
250
+		foreach ($this->_admin_menu_groups as $group) {
251
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
252
+				throw new EE_Error(
253
+					sprintf(
254
+						__(
255
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
256
+							'event_espresso'
257
+						),
258
+						print_r($group, true)
259
+					)
260
+				);
261
+			}
262
+			$groups[ $group->menu_slug ] = $group;
263
+		}
264
+		return $groups;
265
+	}
266
+
267
+
268
+	/**
269
+	 * _get_installed_pages
270
+	 * This just gets the list of installed EE_Admin_pages.
271
+	 *
272
+	 * @access private
273
+	 * @return void
274
+	 * @throws EE_Error
275
+	 * @throws InvalidArgumentException
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 * @throws ReflectionException
279
+	 */
280
+	private function _get_installed_pages()
281
+	{
282
+		$installed_refs = array();
283
+		$exclude = array('assets', 'templates');
284
+		// grab everything in the  admin core directory
285
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
286
+		if ($admin_screens) {
287
+			foreach ($admin_screens as $admin_screen) {
288
+				$admin_screen_name = basename($admin_screen);
289
+				// files and anything in the exclude array need not apply
290
+				if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
291
+					// these folders represent the different EE admin pages
292
+					$installed_refs[ $admin_screen_name ] = $admin_screen;
293
+				}
294
+			}
295
+		}
296
+		if (empty($installed_refs)) {
297
+			$error_msg[] = __(
298
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
299
+				'event_espresso'
300
+			);
301
+			$error_msg[] = $error_msg[0] . "\r\n"
302
+						   . sprintf(
303
+							   __(
304
+								   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
305
+								   'event_espresso'
306
+							   ),
307
+							   EE_ADMIN_PAGES
308
+						   );
309
+			throw new EE_Error(implode('||', $error_msg));
310
+		}
311
+		// this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
312
+		$installed_refs = $this->_set_caffeinated($installed_refs);
313
+		// allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
314
+		$installed_refs = apply_filters(
315
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
316
+			$installed_refs
317
+		);
318
+		$this->_caffeinated_extends = apply_filters(
319
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
320
+			$this->_caffeinated_extends
321
+		);
322
+		// loop through admin pages and setup the $_installed_pages array.
323
+		$hooks_ref = [];
324
+		foreach ($installed_refs as $page => $path) {
325
+			// don't load the page init class IF IT's ALREADY LOADED !!!
326
+			if (isset($this->_installed_pages[ $page ])
327
+				&& $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init
328
+			) {
329
+				continue;
330
+			}
331
+			// set autoloaders for our admin page classes based on included path information
332
+			EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
333
+			// build list of installed pages
334
+			$this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
335
+			// verify returned object
336
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
337
+				if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338
+					continue;
339
+				}
340
+				// skip if in full maintenance mode and maintenance_mode_parent is set
341
+				$maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
342
+				if (empty($maintenance_mode_parent)
343
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
344
+				) {
345
+					unset($installed_refs[ $page ]);
346
+					continue;
347
+				}
348
+				$menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
349
+				$this->_menu_slugs[ $menu_slug ] = $page;
350
+				// flag for register hooks on extended pages b/c extended pages use the default INIT.
351
+				$extend = false;
352
+				// now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
353
+				if (isset($this->_caffeinated_extends[ $page ])) {
354
+					$this->_current_caf_extend_slug = $page;
355
+					$admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
356
+					$caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
357
+					$caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
358
+					add_filter(
359
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
360
+						static function ($path_to_file) use ($caf_path) {
361
+							return $caf_path;
362
+						}
363
+					);
364
+					add_filter(
365
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
366
+						static function ($admin_page) use ($caf_admin_page) {
367
+							return $caf_admin_page;
368
+						}
369
+					);
370
+					$extend = true;
371
+				}
372
+				// let's do the registered hooks
373
+				$extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
374
+				foreach ($extended_hooks as $key => $value) {
375
+					$hooks_ref[] = $value;
376
+				}
377
+			}
378
+		}
379
+		// the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
380
+		// first make sure we've got unique values
381
+		$hooks_ref = array_unique($hooks_ref);
382
+		// now let's loop and require!
383
+		foreach ($hooks_ref as $path) {
384
+			require_once($path);
385
+		}
386
+		// make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
387
+		global $ee_menu_slugs;
388
+		$ee_menu_slugs = $this->_menu_slugs;
389
+		// we need to loop again to run any early code
390
+		foreach ($installed_refs as $page => $path) {
391
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
392
+				$this->_installed_pages[ $page ]->do_initial_loads();
393
+			}
394
+		}
395
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
396
+	}
397
+
398
+
399
+	/**
400
+	 * get_admin_page_object
401
+	 *
402
+	 * @param string $page_slug
403
+	 * @return EE_Admin_Page
404
+	 */
405
+	public function get_admin_page_object($page_slug = '')
406
+	{
407
+		if (isset($this->_installed_pages[ $page_slug ])) {
408
+			return $this->_installed_pages[ $page_slug ]->loaded_page_object();
409
+		}
410
+		return null;
411
+	}
412
+
413
+
414
+	/**
415
+	 * _get_classname_for_admin_page
416
+	 * generates an "Admin Page" class based on the directory  name
417
+	 *
418
+	 * @param $dir_name
419
+	 * @return string
420
+	 */
421
+	private function _get_classname_for_admin_page($dir_name = '')
422
+	{
423
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
424
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
425
+	}
426
+
427
+
428
+	/**
429
+	 * _get_classname_for_admin_init_page
430
+	 * generates an "Admin Page Init" class based on the directory  name
431
+	 *
432
+	 * @param $dir_name
433
+	 * @return string
434
+	 */
435
+	private function _get_classname_for_admin_init_page($dir_name = '')
436
+	{
437
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
438
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
439
+	}
440
+
441
+
442
+	/**
443
+	 * _load_admin_page
444
+	 * Loads and instantiates page_init object for a single EE_admin page.
445
+	 *
446
+	 * @param string $page page_reference
447
+	 * @param string $path
448
+	 * @return object|bool  return page object if valid, bool false if not.
449
+	 * @throws EE_Error
450
+	 * @throws InvalidArgumentException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 */
454
+	private function _load_admin_page($page = '', $path = '')
455
+	{
456
+		$class_name = $this->_get_classname_for_admin_init_page($page);
457
+		$admin_page = $this->loader->getShared($class_name);
458
+		if (! $admin_page || ! class_exists($class_name, false)) {
459
+			$inner_error_msg = '<br />'
460
+							   . sprintf(
461
+								   esc_html__(
462
+									   'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463
+									   'event_espresso'
464
+								   ),
465
+								   '<strong>' . $class_name . '</strong>'
466
+							   );
467
+			$error_msg[] = sprintf(
468
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
469
+				$page
470
+			);
471
+			$error_msg[] = $error_msg[0]
472
+						   . "\r\n"
473
+						   . sprintf(
474
+							   esc_html__(
475
+								   'There is no Init class in place for the %s admin page.',
476
+								   'event_espresso'
477
+							   ),
478
+							   $page
479
+						   )
480
+						   . $inner_error_msg;
481
+			throw new EE_Error(implode('||', $error_msg));
482
+		}
483
+		return $admin_page;
484
+	}
485
+
486
+
487
+	/**
488
+	 * set_menus
489
+	 * This method sets up the menus for EE Admin Pages
490
+	 *
491
+	 * @access private
492
+	 * @return void
493
+	 * @throws EE_Error
494
+	 * @throws InvalidDataTypeException
495
+	 * @throws ReflectionException
496
+	 */
497
+	public function set_menus()
498
+	{
499
+		// prep the menu pages (sort, group.)
500
+		$this->_prep_pages();
501
+		foreach ($this->_prepped_menu_maps as $menu_map) {
502
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
503
+				$menu_map->add_menu_page();
504
+			}
505
+		}
506
+	}
507
+
508
+
509
+	/**
510
+	 * set_network_menus
511
+	 * This method sets up the menus for network EE Admin Pages.
512
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
513
+	 * are only added to the menu map if they are intended for the admin menu
514
+	 *
515
+	 * @return void
516
+	 * @throws EE_Error
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws ReflectionException
519
+	 */
520
+	public function set_network_menus()
521
+	{
522
+		$this->_prep_pages();
523
+		foreach ($this->_prepped_menu_maps as $menu_map) {
524
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
525
+				$menu_map->add_menu_page(true);
526
+			}
527
+		}
528
+	}
529
+
530
+
531
+	/**
532
+	 * _prep_pages
533
+	 * sets the _prepped_menu_maps property
534
+	 *
535
+	 * @access private
536
+	 * @return void
537
+	 * @throws EE_Error
538
+	 * @throws InvalidDataTypeException
539
+	 */
540
+	private function _prep_pages()
541
+	{
542
+		$pages_array = array();
543
+		// rearrange _admin_menu_groups to be indexed by group slug.
544
+		$menu_groups = $this->_rearrange_menu_groups();
545
+		foreach ($this->_installed_pages as $page) {
546
+			if ($page instanceof EE_Admin_page_Init) {
547
+				$page_map = $page->get_menu_map();
548
+				// if we've got an array then the menu map is in the old format
549
+				// so let's throw a persistent notice that the admin system isn't setup correctly for this item.
550
+				if ($page_map === null || is_array($page_map)) {
551
+					new PersistentAdminNotice(
552
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
553
+						sprintf(
554
+							__(
555
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
556
+								'event_espresso'
557
+							),
558
+							$page->label
559
+						)
560
+					);
561
+					continue;
562
+				}
563
+				// if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
564
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
565
+					throw new EE_Error(
566
+						sprintf(
567
+							__(
568
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
569
+								'event_espresso'
570
+							),
571
+							$page->label,
572
+							$page_map
573
+						)
574
+					);
575
+				}
576
+				// use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
577
+				if (empty($page_map->maintenance_mode_parent)
578
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
579
+				) {
580
+					continue;
581
+				}
582
+				// assign to group (remember $page_map has the admin page stored in it).
583
+				$pages_array[ $page_map->menu_group ][] = $page_map;
584
+			}
585
+		}
586
+		if (empty($pages_array)) {
587
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
588
+		}
589
+		// let's sort the groups, make sure it's a valid group, add header (if to show).
590
+		foreach ($pages_array as $group => $menu_maps) {
591
+			// valid_group?
592
+			if (! array_key_exists($group, $menu_groups)) {
593
+				continue;
594
+			}
595
+			// sort pages.
596
+			usort($menu_maps, array($this, '_sort_menu_maps'));
597
+			// prepend header
598
+			array_unshift($menu_maps, $menu_groups[ $group ]);
599
+			// reset $pages_array with prepped data
600
+			$pages_array[ $group ] = $menu_maps;
601
+		}
602
+
603
+		// now let's setup the _prepped_menu_maps property
604
+		foreach ($menu_groups as $group => $group_objs) {
605
+			if (isset($pages_array[ $group ])) {
606
+				foreach ($pages_array[ $group ] as $key => $value) {
607
+					$this->_prepped_menu_maps[] = $value;
608
+				}
609
+			}
610
+		}
611
+	}
612
+
613
+
614
+	/**
615
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
616
+	 * In this method there are three checks being done:
617
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
618
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
619
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
620
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
621
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
622
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
623
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
624
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
625
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
626
+	 * admin_pages)
627
+	 *
628
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
629
+	 *                              loaded.
630
+	 * @return array
631
+	 * @throws EE_Error
632
+	 */
633
+	private function _set_caffeinated($installed_refs)
634
+	{
635
+		// first let's check if there IS a caffeinated folder. If there is not then lets get out.
636
+		if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) {
637
+			return $installed_refs;
638
+		}
639
+		$this->_define_caffeinated_constants();
640
+		$exclude = array('tickets');
641
+		// okay let's setup an "New" pages first (we'll return installed refs later)
642
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
643
+		if ($new_admin_screens) {
644
+			foreach ($new_admin_screens as $admin_screen) {
645
+				$admin_screen_name = basename($admin_screen);
646
+				// files and anything in the exclude array need not apply
647
+				if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
648
+					// these folders represent the different NEW EE admin pages
649
+					$installed_refs[ $admin_screen_name ] = $admin_screen;
650
+					// set autoloaders for our admin page classes based on included path information
651
+					EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen);
652
+				}
653
+			}
654
+		}
655
+		// let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
656
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
657
+		if ($extends) {
658
+			foreach ($extends as $extend) {
659
+				if (is_dir($extend)) {
660
+					$extend_ref = basename($extend);
661
+					// now let's make sure there is a file that matches the expected format
662
+					$filename = str_replace(
663
+						' ',
664
+						'_',
665
+						ucwords(
666
+							str_replace(
667
+								'_',
668
+								' ',
669
+								$extend_ref
670
+							)
671
+						)
672
+					);
673
+					$filename = 'Extend_' . $filename . '_Admin_Page';
674
+					$this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
675
+						array('\\', '/'),
676
+						'/',
677
+						EE_CORE_CAF_ADMIN
678
+						. 'extend/'
679
+						. $extend_ref
680
+						. '/'
681
+						. $filename
682
+						. '.core.php'
683
+					);
684
+					$this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
685
+					// set autoloaders for our admin page classes based on included path information
686
+					EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend);
687
+				}
688
+			}
689
+		}
690
+		// let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
691
+		$ee_admin_hooks = array();
692
+		$hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
693
+		if ($hooks) {
694
+			foreach ($hooks as $hook) {
695
+				if (is_readable($hook)) {
696
+					require_once $hook;
697
+					$classname = str_replace(
698
+						[EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'],
699
+						'',
700
+						$hook
701
+					);
702
+					if (class_exists($classname)) {
703
+						$admin_page = $this->loader->getShared($classname);
704
+						$ee_admin_hooks[] = $admin_page;
705
+					}
706
+				}
707
+			}
708
+		}
709
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
710
+		return $installed_refs;
711
+	}
712
+
713
+
714
+	/**
715
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
716
+	 *
717
+	 * @since  4.4.0
718
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
719
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
720
+	 * @return int    sort order
721
+	 */
722
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
723
+	{
724
+		if ($a->menu_order === $b->menu_order) {
725
+			return 0;
726
+		}
727
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
728
+	}
729
+
730
+
731
+	/**
732
+	 * _default_header_link
733
+	 * This is just a dummy method to use with header submenu items
734
+	 *
735
+	 * @return bool false
736
+	 */
737
+	public function _default_header_link()
738
+	{
739
+		return false;
740
+	}
741 741
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
     public function init()
107 107
     {
108 108
         // load menu_map classes
109
-        if (! class_exists('EE_Admin_Page_Menu_Map', false)) {
110
-            $map = require EE_ADMIN . 'EE_Admin_Page_Menu_Map.core.php';
109
+        if ( ! class_exists('EE_Admin_Page_Menu_Map', false)) {
110
+            $map = require EE_ADMIN.'EE_Admin_Page_Menu_Map.core.php';
111 111
             if ($map) {
112 112
                 // define the default "groups" for the admin_pages
113 113
                 $this->_set_menu_groups();
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
      */
131 131
     private function _define_caffeinated_constants()
132 132
     {
133
-        if (! defined('EE_CORE_CAF_ADMIN')) {
134
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
135
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
136
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
137
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
138
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
139
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
133
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
134
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
135
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
136
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
137
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
138
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
139
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
140 140
         }
141 141
     }
142 142
 
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         // (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
249 249
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
250 250
         foreach ($this->_admin_menu_groups as $group) {
251
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
251
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
252 252
                 throw new EE_Error(
253 253
                     sprintf(
254 254
                         __(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                     )
260 260
                 );
261 261
             }
262
-            $groups[ $group->menu_slug ] = $group;
262
+            $groups[$group->menu_slug] = $group;
263 263
         }
264 264
         return $groups;
265 265
     }
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
         $installed_refs = array();
283 283
         $exclude = array('assets', 'templates');
284 284
         // grab everything in the  admin core directory
285
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
285
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
286 286
         if ($admin_screens) {
287 287
             foreach ($admin_screens as $admin_screen) {
288 288
                 $admin_screen_name = basename($admin_screen);
289 289
                 // files and anything in the exclude array need not apply
290 290
                 if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
291 291
                     // these folders represent the different EE admin pages
292
-                    $installed_refs[ $admin_screen_name ] = $admin_screen;
292
+                    $installed_refs[$admin_screen_name] = $admin_screen;
293 293
                 }
294 294
             }
295 295
         }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
299 299
                 'event_espresso'
300 300
             );
301
-            $error_msg[] = $error_msg[0] . "\r\n"
301
+            $error_msg[] = $error_msg[0]."\r\n"
302 302
                            . sprintf(
303 303
                                __(
304 304
                                    'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
@@ -323,54 +323,54 @@  discard block
 block discarded – undo
323 323
         $hooks_ref = [];
324 324
         foreach ($installed_refs as $page => $path) {
325 325
             // don't load the page init class IF IT's ALREADY LOADED !!!
326
-            if (isset($this->_installed_pages[ $page ])
327
-                && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init
326
+            if (isset($this->_installed_pages[$page])
327
+                && $this->_installed_pages[$page] instanceof EE_Admin_Page_Init
328 328
             ) {
329 329
                 continue;
330 330
             }
331 331
             // set autoloaders for our admin page classes based on included path information
332 332
             EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
333 333
             // build list of installed pages
334
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
334
+            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
335 335
             // verify returned object
336
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
337
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
336
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
337
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338 338
                     continue;
339 339
                 }
340 340
                 // skip if in full maintenance mode and maintenance_mode_parent is set
341
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
341
+                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
342 342
                 if (empty($maintenance_mode_parent)
343 343
                     && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
344 344
                 ) {
345
-                    unset($installed_refs[ $page ]);
345
+                    unset($installed_refs[$page]);
346 346
                     continue;
347 347
                 }
348
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
349
-                $this->_menu_slugs[ $menu_slug ] = $page;
348
+                $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
349
+                $this->_menu_slugs[$menu_slug] = $page;
350 350
                 // flag for register hooks on extended pages b/c extended pages use the default INIT.
351 351
                 $extend = false;
352 352
                 // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
353
-                if (isset($this->_caffeinated_extends[ $page ])) {
353
+                if (isset($this->_caffeinated_extends[$page])) {
354 354
                     $this->_current_caf_extend_slug = $page;
355
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
356
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
357
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
355
+                    $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
356
+                    $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
357
+                    $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
358 358
                     add_filter(
359 359
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
360
-                        static function ($path_to_file) use ($caf_path) {
360
+                        static function($path_to_file) use ($caf_path) {
361 361
                             return $caf_path;
362 362
                         }
363 363
                     );
364 364
                     add_filter(
365 365
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
366
-                        static function ($admin_page) use ($caf_admin_page) {
366
+                        static function($admin_page) use ($caf_admin_page) {
367 367
                             return $caf_admin_page;
368 368
                         }
369 369
                     );
370 370
                     $extend = true;
371 371
                 }
372 372
                 // let's do the registered hooks
373
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
373
+                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
374 374
                 foreach ($extended_hooks as $key => $value) {
375 375
                     $hooks_ref[] = $value;
376 376
                 }
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
         $ee_menu_slugs = $this->_menu_slugs;
389 389
         // we need to loop again to run any early code
390 390
         foreach ($installed_refs as $page => $path) {
391
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
392
-                $this->_installed_pages[ $page ]->do_initial_loads();
391
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
392
+                $this->_installed_pages[$page]->do_initial_loads();
393 393
             }
394 394
         }
395 395
         do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
      */
405 405
     public function get_admin_page_object($page_slug = '')
406 406
     {
407
-        if (isset($this->_installed_pages[ $page_slug ])) {
408
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
407
+        if (isset($this->_installed_pages[$page_slug])) {
408
+            return $this->_installed_pages[$page_slug]->loaded_page_object();
409 409
         }
410 410
         return null;
411 411
     }
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     private function _get_classname_for_admin_page($dir_name = '')
422 422
     {
423 423
         $class_name = str_replace('_', ' ', strtolower($dir_name));
424
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
424
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
425 425
     }
426 426
 
427 427
 
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
     private function _get_classname_for_admin_init_page($dir_name = '')
436 436
     {
437 437
         $class_name = str_replace('_', ' ', strtolower($dir_name));
438
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
438
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
439 439
     }
440 440
 
441 441
 
@@ -455,14 +455,14 @@  discard block
 block discarded – undo
455 455
     {
456 456
         $class_name = $this->_get_classname_for_admin_init_page($page);
457 457
         $admin_page = $this->loader->getShared($class_name);
458
-        if (! $admin_page || ! class_exists($class_name, false)) {
458
+        if ( ! $admin_page || ! class_exists($class_name, false)) {
459 459
             $inner_error_msg = '<br />'
460 460
                                . sprintf(
461 461
                                    esc_html__(
462 462
                                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463 463
                                        'event_espresso'
464 464
                                    ),
465
-                                   '<strong>' . $class_name . '</strong>'
465
+                                   '<strong>'.$class_name.'</strong>'
466 466
                                );
467 467
             $error_msg[] = sprintf(
468 468
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
                 // so let's throw a persistent notice that the admin system isn't setup correctly for this item.
550 550
                 if ($page_map === null || is_array($page_map)) {
551 551
                     new PersistentAdminNotice(
552
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
552
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
553 553
                         sprintf(
554 554
                             __(
555 555
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
                     continue;
562 562
                 }
563 563
                 // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
564
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
564
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
565 565
                     throw new EE_Error(
566 566
                         sprintf(
567 567
                             __(
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                     continue;
581 581
                 }
582 582
                 // assign to group (remember $page_map has the admin page stored in it).
583
-                $pages_array[ $page_map->menu_group ][] = $page_map;
583
+                $pages_array[$page_map->menu_group][] = $page_map;
584 584
             }
585 585
         }
586 586
         if (empty($pages_array)) {
@@ -589,21 +589,21 @@  discard block
 block discarded – undo
589 589
         // let's sort the groups, make sure it's a valid group, add header (if to show).
590 590
         foreach ($pages_array as $group => $menu_maps) {
591 591
             // valid_group?
592
-            if (! array_key_exists($group, $menu_groups)) {
592
+            if ( ! array_key_exists($group, $menu_groups)) {
593 593
                 continue;
594 594
             }
595 595
             // sort pages.
596 596
             usort($menu_maps, array($this, '_sort_menu_maps'));
597 597
             // prepend header
598
-            array_unshift($menu_maps, $menu_groups[ $group ]);
598
+            array_unshift($menu_maps, $menu_groups[$group]);
599 599
             // reset $pages_array with prepped data
600
-            $pages_array[ $group ] = $menu_maps;
600
+            $pages_array[$group] = $menu_maps;
601 601
         }
602 602
 
603 603
         // now let's setup the _prepped_menu_maps property
604 604
         foreach ($menu_groups as $group => $group_objs) {
605
-            if (isset($pages_array[ $group ])) {
606
-                foreach ($pages_array[ $group ] as $key => $value) {
605
+            if (isset($pages_array[$group])) {
606
+                foreach ($pages_array[$group] as $key => $value) {
607 607
                     $this->_prepped_menu_maps[] = $value;
608 608
                 }
609 609
             }
@@ -633,27 +633,27 @@  discard block
 block discarded – undo
633 633
     private function _set_caffeinated($installed_refs)
634 634
     {
635 635
         // first let's check if there IS a caffeinated folder. If there is not then lets get out.
636
-        if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) {
636
+        if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated/admin')) {
637 637
             return $installed_refs;
638 638
         }
639 639
         $this->_define_caffeinated_constants();
640 640
         $exclude = array('tickets');
641 641
         // okay let's setup an "New" pages first (we'll return installed refs later)
642
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
642
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
643 643
         if ($new_admin_screens) {
644 644
             foreach ($new_admin_screens as $admin_screen) {
645 645
                 $admin_screen_name = basename($admin_screen);
646 646
                 // files and anything in the exclude array need not apply
647 647
                 if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) {
648 648
                     // these folders represent the different NEW EE admin pages
649
-                    $installed_refs[ $admin_screen_name ] = $admin_screen;
649
+                    $installed_refs[$admin_screen_name] = $admin_screen;
650 650
                     // set autoloaders for our admin page classes based on included path information
651 651
                     EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen);
652 652
                 }
653 653
             }
654 654
         }
655 655
         // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
656
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
656
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
657 657
         if ($extends) {
658 658
             foreach ($extends as $extend) {
659 659
                 if (is_dir($extend)) {
@@ -670,8 +670,8 @@  discard block
 block discarded – undo
670 670
                             )
671 671
                         )
672 672
                     );
673
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
674
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
673
+                    $filename = 'Extend_'.$filename.'_Admin_Page';
674
+                    $this->_caffeinated_extends[$extend_ref]['path'] = str_replace(
675 675
                         array('\\', '/'),
676 676
                         '/',
677 677
                         EE_CORE_CAF_ADMIN
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                         . $filename
682 682
                         . '.core.php'
683 683
                     );
684
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
684
+                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
685 685
                     // set autoloaders for our admin page classes based on included path information
686 686
                     EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend);
687 687
                 }
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
         }
690 690
         // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
691 691
         $ee_admin_hooks = array();
692
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
692
+        $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
693 693
         if ($hooks) {
694 694
             foreach ($hooks as $hook) {
695 695
                 if (is_readable($hook)) {
696 696
                     require_once $hook;
697 697
                     $classname = str_replace(
698
-                        [EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'],
698
+                        [EE_CORE_CAF_ADMIN.'hooks/', '.class.php'],
699 699
                         '',
700 700
                         $hook
701 701
                     );
Please login to merge, or discard this patch.
core/services/request/Request.php 1 patch
Indentation   +671 added lines, -671 removed lines patch added patch discarded remove patch
@@ -17,675 +17,675 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_FILES parameters
50
-     *
51
-     * @var array $files
52
-     */
53
-    private $files;
54
-
55
-    /**
56
-     * $_REQUEST parameters
57
-     *
58
-     * @var array $request
59
-     */
60
-    private $request;
61
-
62
-    /**
63
-     * @var RequestTypeContextCheckerInterface
64
-     */
65
-    private $request_type;
66
-
67
-    /**
68
-     * IP address for request
69
-     *
70
-     * @var string $ip_address
71
-     */
72
-    private $ip_address;
73
-
74
-    /**
75
-     * @var string $user_agent
76
-     */
77
-    private $user_agent;
78
-
79
-    /**
80
-     * true if current user appears to be some kind of bot
81
-     *
82
-     * @var bool $is_bot
83
-     */
84
-    private $is_bot;
85
-
86
-
87
-    /**
88
-     * @param array $get
89
-     * @param array $post
90
-     * @param array $cookie
91
-     * @param array $server
92
-     * @param array $files
93
-     */
94
-    public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
-    {
96
-        // grab request vars
97
-        $this->get = $get;
98
-        $this->post = $post;
99
-        $this->cookie = $cookie;
100
-        $this->server = $server;
101
-        $this->files = $files;
102
-        $this->request = array_merge($this->get, $this->post);
103
-        $this->ip_address = $this->visitorIp();
104
-    }
105
-
106
-
107
-    /**
108
-     * @param RequestTypeContextCheckerInterface $type
109
-     */
110
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
-    {
112
-        $this->request_type = $type;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function getParams()
120
-    {
121
-        return $this->get;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function postParams()
129
-    {
130
-        return $this->post;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function cookieParams()
138
-    {
139
-        return $this->cookie;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function serverParams()
147
-    {
148
-        return $this->server;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public function filesParams()
156
-    {
157
-        return $this->files;
158
-    }
159
-
160
-
161
-    /**
162
-     * returns contents of $_REQUEST
163
-     *
164
-     * @return array
165
-     */
166
-    public function requestParams()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param      $key
174
-     * @param      $value
175
-     * @param bool $override_ee
176
-     * @return    void
177
-     */
178
-    public function setRequestParam($key, $value, $override_ee = false)
179
-    {
180
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
181
-        if ($key !== 'ee'
182
-            || ($key === 'ee' && empty($this->request['ee']))
183
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
-        ) {
185
-            $this->request[ $key ] = $value;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     * returns   the value for a request param if the given key exists
192
-     *
193
-     * @param       $key
194
-     * @param null  $default
195
-     * @return mixed
196
-     */
197
-    public function getRequestParam($key, $default = null)
198
-    {
199
-        return $this->requestParameterDrillDown($key, $default, 'get');
200
-    }
201
-
202
-
203
-    /**
204
-     * check if param exists
205
-     *
206
-     * @param       $key
207
-     * @return bool
208
-     */
209
-    public function requestParamIsSet($key)
210
-    {
211
-        return $this->requestParameterDrillDown($key);
212
-    }
213
-
214
-
215
-    /**
216
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
-     * and return the value for the first match found
218
-     * wildcards can be either of the following:
219
-     *      ? to represent a single character of any type
220
-     *      * to represent one or more characters of any type
221
-     *
222
-     * @param string     $pattern
223
-     * @param null|mixed $default
224
-     * @return mixed
225
-     */
226
-    public function getMatch($pattern, $default = null)
227
-    {
228
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
229
-    }
230
-
231
-
232
-    /**
233
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
234
-     * wildcards can be either of the following:
235
-     *      ? to represent a single character of any type
236
-     *      * to represent one or more characters of any type
237
-     * returns true if a match is found or false if not
238
-     *
239
-     * @param string $pattern
240
-     * @return bool
241
-     */
242
-    public function matches($pattern)
243
-    {
244
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
-    }
246
-
247
-
248
-    /**
249
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
-     *                                      and used to search through the current request's parameter keys
252
-     * @param array  $request_params        The array of request parameters to search through
253
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
254
-     *                                      Default is null
255
-     * @param string $return                [optional] Controls what kind of value is returned.
256
-     *                                      Options are:
257
-     *                                      'bool' will return true or false if match is found or not
258
-     *                                      'key' will return the first key found that matches the supplied pattern
259
-     *                                      'value' will return the value for the first request parameter
260
-     *                                      whose key matches the supplied pattern
261
-     *                                      Default is 'value'
262
-     * @return boolean|string
263
-     */
264
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
265
-    {
266
-        $return = in_array($return, array('bool', 'key', 'value'), true)
267
-            ? $return
268
-            : 'is_set';
269
-        // replace wildcard chars with regex chars
270
-        $pattern = str_replace(
271
-            array("\*", "\?"),
272
-            array('.*', '.'),
273
-            preg_quote($pattern, '/')
274
-        );
275
-        foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
277
-                // return value for request param
278
-                if ($return === 'value') {
279
-                    return $request_params[ $key ];
280
-                }
281
-                // or actual key or true just to indicate it was found
282
-                return $return === 'key' ? $key : true;
283
-            }
284
-        }
285
-        // match not found so return default value or false
286
-        return $return === 'value' ? $default : false;
287
-    }
288
-
289
-
290
-    /**
291
-     * the supplied key can be a simple string to represent a "top-level" request parameter
292
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
-     * by using square brackets to surround keys for deeper array elements.
294
-     * For example :
295
-     * if the supplied $key was: "first[second][third]"
296
-     * then this will attempt to drill down into the request parameter array to find a value.
297
-     * Given the following request parameters:
298
-     *  array(
299
-     *      'first' => array(
300
-     *          'second' => array(
301
-     *              'third' => 'has a value'
302
-     *          )
303
-     *      )
304
-     *  )
305
-     * would return true if default parameters were set
306
-     *
307
-     * @param string $callback
308
-     * @param        $key
309
-     * @param null   $default
310
-     * @param array  $request_params
311
-     * @return bool|mixed|null
312
-     */
313
-    private function requestParameterDrillDown(
314
-        $key,
315
-        $default = null,
316
-        $callback = 'is_set',
317
-        array $request_params = array()
318
-    ) {
319
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
-            ? $callback
321
-            : 'is_set';
322
-        $request_params = ! empty($request_params)
323
-            ? $request_params
324
-            : $this->request;
325
-        // does incoming key represent an array like 'first[second][third]'  ?
326
-        if (strpos($key, '[') !== false) {
327
-            // turn it into an actual array
328
-            $key = str_replace(']', '', $key);
329
-            $keys = explode('[', $key);
330
-            $key = array_shift($keys);
331
-            if ($callback === 'match') {
332
-                $real_key = $this->match($key, $request_params, $default, 'key');
333
-                $key = $real_key ? $real_key : $key;
334
-            }
335
-            // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
337
-                // build a new key to pass along like: 'second[third]'
338
-                // or just 'second' depending on depth of keys
339
-                $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
342
-                }
343
-                return $this->requestParameterDrillDown(
344
-                    $key_string,
345
-                    $default,
346
-                    $callback,
347
-                    $request_params[ $key ]
348
-                );
349
-            }
350
-        }
351
-        if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
353
-        }
354
-        if ($callback === 'match') {
355
-            return $this->match($key, $request_params, $default);
356
-        }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
359
-            : $default;
360
-    }
361
-
362
-
363
-    /**
364
-     * remove param
365
-     *
366
-     * @param      $key
367
-     * @param bool $unset_from_global_too
368
-     */
369
-    public function unSetRequestParam($key, $unset_from_global_too = false)
370
-    {
371
-        // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
374
-        if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * remove params
382
-     *
383
-     * @param array $keys
384
-     * @param bool  $unset_from_global_too
385
-     */
386
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
-    {
388
-        foreach ($keys as $key) {
389
-            $this->unSetRequestParam($key, $unset_from_global_too);
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * @return string
396
-     */
397
-    public function ipAddress()
398
-    {
399
-        return $this->ip_address;
400
-    }
401
-
402
-
403
-    /**
404
-     * attempt to get IP address of current visitor from server
405
-     * plz see: http://stackoverflow.com/a/2031935/1475279
406
-     *
407
-     * @access public
408
-     * @return string
409
-     */
410
-    private function visitorIp()
411
-    {
412
-        $visitor_ip = '0.0.0.0';
413
-        $server_keys = array(
414
-            'HTTP_CLIENT_IP',
415
-            'HTTP_X_FORWARDED_FOR',
416
-            'HTTP_X_FORWARDED',
417
-            'HTTP_X_CLUSTER_CLIENT_IP',
418
-            'HTTP_FORWARDED_FOR',
419
-            'HTTP_FORWARDED',
420
-            'REMOTE_ADDR',
421
-        );
422
-        foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
-                        $visitor_ip = $ip;
427
-                    }
428
-                }
429
-            }
430
-        }
431
-        return $visitor_ip;
432
-    }
433
-
434
-
435
-    /**
436
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
-     * @return string
441
-     */
442
-    public function requestUri($relativeToWpRoot = false)
443
-    {
444
-        $request_uri = filter_input(
445
-            INPUT_SERVER,
446
-            'REQUEST_URI',
447
-            FILTER_SANITIZE_URL,
448
-            FILTER_NULL_ON_FAILURE
449
-        );
450
-        if (empty($request_uri)) {
451
-            // fallback sanitization if the above fails
452
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
-        }
454
-        if ($relativeToWpRoot) {
455
-            $home_path = untrailingslashit(
456
-                parse_url(
457
-                    home_url(),
458
-                    PHP_URL_PATH
459
-                )
460
-            );
461
-            $request_uri = str_replace(
462
-                $home_path,
463
-                '',
464
-                $request_uri
465
-            );
466
-        }
467
-        return $request_uri;
468
-    }
469
-
470
-    /**
471
-     * @return string
472
-     */
473
-    public function userAgent()
474
-    {
475
-        return $this->user_agent;
476
-    }
477
-
478
-
479
-    /**
480
-     * @param string $user_agent
481
-     */
482
-    public function setUserAgent($user_agent = '')
483
-    {
484
-        if ($user_agent === '' || ! is_string($user_agent)) {
485
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
-        }
487
-        $this->user_agent = $user_agent;
488
-    }
489
-
490
-
491
-    /**
492
-     * @return bool
493
-     */
494
-    public function isBot()
495
-    {
496
-        return $this->is_bot;
497
-    }
498
-
499
-
500
-    /**
501
-     * @param bool $is_bot
502
-     */
503
-    public function setIsBot($is_bot)
504
-    {
505
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
-    }
507
-
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function isActivation()
513
-    {
514
-        return $this->request_type->isActivation();
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $is_activation
520
-     * @return bool
521
-     */
522
-    public function setIsActivation($is_activation)
523
-    {
524
-        return $this->request_type->setIsActivation($is_activation);
525
-    }
526
-
527
-
528
-    /**
529
-     * @return bool
530
-     */
531
-    public function isAdmin()
532
-    {
533
-        return $this->request_type->isAdmin();
534
-    }
535
-
536
-
537
-    /**
538
-     * @return bool
539
-     */
540
-    public function isAdminAjax()
541
-    {
542
-        return $this->request_type->isAdminAjax();
543
-    }
544
-
545
-
546
-    /**
547
-     * @return bool
548
-     */
549
-    public function isAjax()
550
-    {
551
-        return $this->request_type->isAjax();
552
-    }
553
-
554
-
555
-    /**
556
-     * @return bool
557
-     */
558
-    public function isEeAjax()
559
-    {
560
-        return $this->request_type->isEeAjax();
561
-    }
562
-
563
-
564
-    /**
565
-     * @return bool
566
-     */
567
-    public function isOtherAjax()
568
-    {
569
-        return $this->request_type->isOtherAjax();
570
-    }
571
-
572
-
573
-    /**
574
-     * @return bool
575
-     */
576
-    public function isApi()
577
-    {
578
-        return $this->request_type->isApi();
579
-    }
580
-
581
-
582
-    /**
583
-     * @return bool
584
-     */
585
-    public function isCli()
586
-    {
587
-        return $this->request_type->isCli();
588
-    }
589
-
590
-
591
-    /**
592
-     * @return bool
593
-     */
594
-    public function isCron()
595
-    {
596
-        return $this->request_type->isCron();
597
-    }
598
-
599
-
600
-    /**
601
-     * @return bool
602
-     */
603
-    public function isFeed()
604
-    {
605
-        return $this->request_type->isFeed();
606
-    }
607
-
608
-
609
-    /**
610
-     * @return bool
611
-     */
612
-    public function isFrontend()
613
-    {
614
-        return $this->request_type->isFrontend();
615
-    }
616
-
617
-
618
-    /**
619
-     * @return bool
620
-     */
621
-    public function isFrontAjax()
622
-    {
623
-        return $this->request_type->isFrontAjax();
624
-    }
625
-
626
-
627
-    /**
628
-     * @return bool
629
-     */
630
-    public function isGQL()
631
-    {
632
-        return $this->request_type->isGQL();
633
-    }
634
-
635
-
636
-    /**
637
-     * @return bool
638
-     */
639
-    public function isIframe()
640
-    {
641
-        return $this->request_type->isIframe();
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * @return bool
648
-     */
649
-    public function isUnitTesting()
650
-    {
651
-        return $this->request_type->isUnitTesting();
652
-    }
653
-
654
-
655
-    /**
656
-     * @return bool
657
-     */
658
-    public function isWordPressApi()
659
-    {
660
-        return $this->request_type->isWordPressApi();
661
-    }
662
-
663
-
664
-
665
-    /**
666
-     * @return bool
667
-     */
668
-    public function isWordPressHeartbeat()
669
-    {
670
-        return $this->request_type->isWordPressHeartbeat();
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * @return bool
677
-     */
678
-    public function isWordPressScrape()
679
-    {
680
-        return $this->request_type->isWordPressScrape();
681
-    }
682
-
683
-
684
-    /**
685
-     * @return string
686
-     */
687
-    public function slug()
688
-    {
689
-        return $this->request_type->slug();
690
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_FILES parameters
50
+	 *
51
+	 * @var array $files
52
+	 */
53
+	private $files;
54
+
55
+	/**
56
+	 * $_REQUEST parameters
57
+	 *
58
+	 * @var array $request
59
+	 */
60
+	private $request;
61
+
62
+	/**
63
+	 * @var RequestTypeContextCheckerInterface
64
+	 */
65
+	private $request_type;
66
+
67
+	/**
68
+	 * IP address for request
69
+	 *
70
+	 * @var string $ip_address
71
+	 */
72
+	private $ip_address;
73
+
74
+	/**
75
+	 * @var string $user_agent
76
+	 */
77
+	private $user_agent;
78
+
79
+	/**
80
+	 * true if current user appears to be some kind of bot
81
+	 *
82
+	 * @var bool $is_bot
83
+	 */
84
+	private $is_bot;
85
+
86
+
87
+	/**
88
+	 * @param array $get
89
+	 * @param array $post
90
+	 * @param array $cookie
91
+	 * @param array $server
92
+	 * @param array $files
93
+	 */
94
+	public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
+	{
96
+		// grab request vars
97
+		$this->get = $get;
98
+		$this->post = $post;
99
+		$this->cookie = $cookie;
100
+		$this->server = $server;
101
+		$this->files = $files;
102
+		$this->request = array_merge($this->get, $this->post);
103
+		$this->ip_address = $this->visitorIp();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param RequestTypeContextCheckerInterface $type
109
+	 */
110
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
+	{
112
+		$this->request_type = $type;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function getParams()
120
+	{
121
+		return $this->get;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function postParams()
129
+	{
130
+		return $this->post;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function cookieParams()
138
+	{
139
+		return $this->cookie;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function serverParams()
147
+	{
148
+		return $this->server;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public function filesParams()
156
+	{
157
+		return $this->files;
158
+	}
159
+
160
+
161
+	/**
162
+	 * returns contents of $_REQUEST
163
+	 *
164
+	 * @return array
165
+	 */
166
+	public function requestParams()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param      $key
174
+	 * @param      $value
175
+	 * @param bool $override_ee
176
+	 * @return    void
177
+	 */
178
+	public function setRequestParam($key, $value, $override_ee = false)
179
+	{
180
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
181
+		if ($key !== 'ee'
182
+			|| ($key === 'ee' && empty($this->request['ee']))
183
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
+		) {
185
+			$this->request[ $key ] = $value;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 * returns   the value for a request param if the given key exists
192
+	 *
193
+	 * @param       $key
194
+	 * @param null  $default
195
+	 * @return mixed
196
+	 */
197
+	public function getRequestParam($key, $default = null)
198
+	{
199
+		return $this->requestParameterDrillDown($key, $default, 'get');
200
+	}
201
+
202
+
203
+	/**
204
+	 * check if param exists
205
+	 *
206
+	 * @param       $key
207
+	 * @return bool
208
+	 */
209
+	public function requestParamIsSet($key)
210
+	{
211
+		return $this->requestParameterDrillDown($key);
212
+	}
213
+
214
+
215
+	/**
216
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
+	 * and return the value for the first match found
218
+	 * wildcards can be either of the following:
219
+	 *      ? to represent a single character of any type
220
+	 *      * to represent one or more characters of any type
221
+	 *
222
+	 * @param string     $pattern
223
+	 * @param null|mixed $default
224
+	 * @return mixed
225
+	 */
226
+	public function getMatch($pattern, $default = null)
227
+	{
228
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
229
+	}
230
+
231
+
232
+	/**
233
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
234
+	 * wildcards can be either of the following:
235
+	 *      ? to represent a single character of any type
236
+	 *      * to represent one or more characters of any type
237
+	 * returns true if a match is found or false if not
238
+	 *
239
+	 * @param string $pattern
240
+	 * @return bool
241
+	 */
242
+	public function matches($pattern)
243
+	{
244
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
+	 *                                      and used to search through the current request's parameter keys
252
+	 * @param array  $request_params        The array of request parameters to search through
253
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
254
+	 *                                      Default is null
255
+	 * @param string $return                [optional] Controls what kind of value is returned.
256
+	 *                                      Options are:
257
+	 *                                      'bool' will return true or false if match is found or not
258
+	 *                                      'key' will return the first key found that matches the supplied pattern
259
+	 *                                      'value' will return the value for the first request parameter
260
+	 *                                      whose key matches the supplied pattern
261
+	 *                                      Default is 'value'
262
+	 * @return boolean|string
263
+	 */
264
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
265
+	{
266
+		$return = in_array($return, array('bool', 'key', 'value'), true)
267
+			? $return
268
+			: 'is_set';
269
+		// replace wildcard chars with regex chars
270
+		$pattern = str_replace(
271
+			array("\*", "\?"),
272
+			array('.*', '.'),
273
+			preg_quote($pattern, '/')
274
+		);
275
+		foreach ($request_params as $key => $request_param) {
276
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
277
+				// return value for request param
278
+				if ($return === 'value') {
279
+					return $request_params[ $key ];
280
+				}
281
+				// or actual key or true just to indicate it was found
282
+				return $return === 'key' ? $key : true;
283
+			}
284
+		}
285
+		// match not found so return default value or false
286
+		return $return === 'value' ? $default : false;
287
+	}
288
+
289
+
290
+	/**
291
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
292
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
+	 * by using square brackets to surround keys for deeper array elements.
294
+	 * For example :
295
+	 * if the supplied $key was: "first[second][third]"
296
+	 * then this will attempt to drill down into the request parameter array to find a value.
297
+	 * Given the following request parameters:
298
+	 *  array(
299
+	 *      'first' => array(
300
+	 *          'second' => array(
301
+	 *              'third' => 'has a value'
302
+	 *          )
303
+	 *      )
304
+	 *  )
305
+	 * would return true if default parameters were set
306
+	 *
307
+	 * @param string $callback
308
+	 * @param        $key
309
+	 * @param null   $default
310
+	 * @param array  $request_params
311
+	 * @return bool|mixed|null
312
+	 */
313
+	private function requestParameterDrillDown(
314
+		$key,
315
+		$default = null,
316
+		$callback = 'is_set',
317
+		array $request_params = array()
318
+	) {
319
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
+			? $callback
321
+			: 'is_set';
322
+		$request_params = ! empty($request_params)
323
+			? $request_params
324
+			: $this->request;
325
+		// does incoming key represent an array like 'first[second][third]'  ?
326
+		if (strpos($key, '[') !== false) {
327
+			// turn it into an actual array
328
+			$key = str_replace(']', '', $key);
329
+			$keys = explode('[', $key);
330
+			$key = array_shift($keys);
331
+			if ($callback === 'match') {
332
+				$real_key = $this->match($key, $request_params, $default, 'key');
333
+				$key = $real_key ? $real_key : $key;
334
+			}
335
+			// check if top level key exists
336
+			if (isset($request_params[ $key ])) {
337
+				// build a new key to pass along like: 'second[third]'
338
+				// or just 'second' depending on depth of keys
339
+				$key_string = array_shift($keys);
340
+				if (! empty($keys)) {
341
+					$key_string .= '[' . implode('][', $keys) . ']';
342
+				}
343
+				return $this->requestParameterDrillDown(
344
+					$key_string,
345
+					$default,
346
+					$callback,
347
+					$request_params[ $key ]
348
+				);
349
+			}
350
+		}
351
+		if ($callback === 'is_set') {
352
+			return isset($request_params[ $key ]);
353
+		}
354
+		if ($callback === 'match') {
355
+			return $this->match($key, $request_params, $default);
356
+		}
357
+		return isset($request_params[ $key ])
358
+			? $request_params[ $key ]
359
+			: $default;
360
+	}
361
+
362
+
363
+	/**
364
+	 * remove param
365
+	 *
366
+	 * @param      $key
367
+	 * @param bool $unset_from_global_too
368
+	 */
369
+	public function unSetRequestParam($key, $unset_from_global_too = false)
370
+	{
371
+		// because unset may not actually remove var
372
+		$this->request[ $key ] = null;
373
+		unset($this->request[ $key ]);
374
+		if ($unset_from_global_too) {
375
+			unset($_REQUEST[ $key ]);
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * remove params
382
+	 *
383
+	 * @param array $keys
384
+	 * @param bool  $unset_from_global_too
385
+	 */
386
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
+	{
388
+		foreach ($keys as $key) {
389
+			$this->unSetRequestParam($key, $unset_from_global_too);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * @return string
396
+	 */
397
+	public function ipAddress()
398
+	{
399
+		return $this->ip_address;
400
+	}
401
+
402
+
403
+	/**
404
+	 * attempt to get IP address of current visitor from server
405
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
406
+	 *
407
+	 * @access public
408
+	 * @return string
409
+	 */
410
+	private function visitorIp()
411
+	{
412
+		$visitor_ip = '0.0.0.0';
413
+		$server_keys = array(
414
+			'HTTP_CLIENT_IP',
415
+			'HTTP_X_FORWARDED_FOR',
416
+			'HTTP_X_FORWARDED',
417
+			'HTTP_X_CLUSTER_CLIENT_IP',
418
+			'HTTP_FORWARDED_FOR',
419
+			'HTTP_FORWARDED',
420
+			'REMOTE_ADDR',
421
+		);
422
+		foreach ($server_keys as $key) {
423
+			if (isset($this->server[ $key ])) {
424
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
+						$visitor_ip = $ip;
427
+					}
428
+				}
429
+			}
430
+		}
431
+		return $visitor_ip;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
+	 * @return string
441
+	 */
442
+	public function requestUri($relativeToWpRoot = false)
443
+	{
444
+		$request_uri = filter_input(
445
+			INPUT_SERVER,
446
+			'REQUEST_URI',
447
+			FILTER_SANITIZE_URL,
448
+			FILTER_NULL_ON_FAILURE
449
+		);
450
+		if (empty($request_uri)) {
451
+			// fallback sanitization if the above fails
452
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
+		}
454
+		if ($relativeToWpRoot) {
455
+			$home_path = untrailingslashit(
456
+				parse_url(
457
+					home_url(),
458
+					PHP_URL_PATH
459
+				)
460
+			);
461
+			$request_uri = str_replace(
462
+				$home_path,
463
+				'',
464
+				$request_uri
465
+			);
466
+		}
467
+		return $request_uri;
468
+	}
469
+
470
+	/**
471
+	 * @return string
472
+	 */
473
+	public function userAgent()
474
+	{
475
+		return $this->user_agent;
476
+	}
477
+
478
+
479
+	/**
480
+	 * @param string $user_agent
481
+	 */
482
+	public function setUserAgent($user_agent = '')
483
+	{
484
+		if ($user_agent === '' || ! is_string($user_agent)) {
485
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
+		}
487
+		$this->user_agent = $user_agent;
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return bool
493
+	 */
494
+	public function isBot()
495
+	{
496
+		return $this->is_bot;
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param bool $is_bot
502
+	 */
503
+	public function setIsBot($is_bot)
504
+	{
505
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
+	}
507
+
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function isActivation()
513
+	{
514
+		return $this->request_type->isActivation();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $is_activation
520
+	 * @return bool
521
+	 */
522
+	public function setIsActivation($is_activation)
523
+	{
524
+		return $this->request_type->setIsActivation($is_activation);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @return bool
530
+	 */
531
+	public function isAdmin()
532
+	{
533
+		return $this->request_type->isAdmin();
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return bool
539
+	 */
540
+	public function isAdminAjax()
541
+	{
542
+		return $this->request_type->isAdminAjax();
543
+	}
544
+
545
+
546
+	/**
547
+	 * @return bool
548
+	 */
549
+	public function isAjax()
550
+	{
551
+		return $this->request_type->isAjax();
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return bool
557
+	 */
558
+	public function isEeAjax()
559
+	{
560
+		return $this->request_type->isEeAjax();
561
+	}
562
+
563
+
564
+	/**
565
+	 * @return bool
566
+	 */
567
+	public function isOtherAjax()
568
+	{
569
+		return $this->request_type->isOtherAjax();
570
+	}
571
+
572
+
573
+	/**
574
+	 * @return bool
575
+	 */
576
+	public function isApi()
577
+	{
578
+		return $this->request_type->isApi();
579
+	}
580
+
581
+
582
+	/**
583
+	 * @return bool
584
+	 */
585
+	public function isCli()
586
+	{
587
+		return $this->request_type->isCli();
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return bool
593
+	 */
594
+	public function isCron()
595
+	{
596
+		return $this->request_type->isCron();
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return bool
602
+	 */
603
+	public function isFeed()
604
+	{
605
+		return $this->request_type->isFeed();
606
+	}
607
+
608
+
609
+	/**
610
+	 * @return bool
611
+	 */
612
+	public function isFrontend()
613
+	{
614
+		return $this->request_type->isFrontend();
615
+	}
616
+
617
+
618
+	/**
619
+	 * @return bool
620
+	 */
621
+	public function isFrontAjax()
622
+	{
623
+		return $this->request_type->isFrontAjax();
624
+	}
625
+
626
+
627
+	/**
628
+	 * @return bool
629
+	 */
630
+	public function isGQL()
631
+	{
632
+		return $this->request_type->isGQL();
633
+	}
634
+
635
+
636
+	/**
637
+	 * @return bool
638
+	 */
639
+	public function isIframe()
640
+	{
641
+		return $this->request_type->isIframe();
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * @return bool
648
+	 */
649
+	public function isUnitTesting()
650
+	{
651
+		return $this->request_type->isUnitTesting();
652
+	}
653
+
654
+
655
+	/**
656
+	 * @return bool
657
+	 */
658
+	public function isWordPressApi()
659
+	{
660
+		return $this->request_type->isWordPressApi();
661
+	}
662
+
663
+
664
+
665
+	/**
666
+	 * @return bool
667
+	 */
668
+	public function isWordPressHeartbeat()
669
+	{
670
+		return $this->request_type->isWordPressHeartbeat();
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * @return bool
677
+	 */
678
+	public function isWordPressScrape()
679
+	{
680
+		return $this->request_type->isWordPressScrape();
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return string
686
+	 */
687
+	public function slug()
688
+	{
689
+		return $this->request_type->slug();
690
+	}
691 691
 }
Please login to merge, or discard this patch.
core/services/request/middleware/SetRequestTypeContextChecker.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,42 +18,42 @@
 block discarded – undo
18 18
 class SetRequestTypeContextChecker extends Middleware
19 19
 {
20 20
 
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     * @throws InvalidArgumentException
28
-     */
29
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
-    {
31
-        $this->request  = $request;
32
-        $this->response = $response;
33
-        /** @var RequestTypeContextDetector $request_type_context_detector */
34
-        $request_type_context_detector = $this->loader->getShared(
35
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
36
-            array(
37
-                $this->request,
38
-                $this->loader->getShared(
39
-                    'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
-                    array($this->loader)
41
-                ),
42
-                array(
43
-                    'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
44
-                    'WP_CLI'     => defined('WP_CLI') && WP_CLI,
45
-                    'is_admin'   => is_admin(),
46
-                )
47
-            )
48
-        );
49
-        $request_type_context = $request_type_context_detector->detectRequestTypeContext();
50
-        $request_type_context->setIsUnitTesting(defined('EE_TESTS_DIR'));
51
-        $request_type_context_checker = $this->loader->getShared(
52
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
53
-            array($request_type_context)
54
-        );
55
-        $this->request->setRequestTypeContextChecker($request_type_context_checker);
56
-        $this->response = $this->processRequestStack($this->request, $this->response);
57
-        return $this->response;
58
-    }
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 * @throws InvalidArgumentException
28
+	 */
29
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
+	{
31
+		$this->request  = $request;
32
+		$this->response = $response;
33
+		/** @var RequestTypeContextDetector $request_type_context_detector */
34
+		$request_type_context_detector = $this->loader->getShared(
35
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
36
+			array(
37
+				$this->request,
38
+				$this->loader->getShared(
39
+					'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
+					array($this->loader)
41
+				),
42
+				array(
43
+					'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
44
+					'WP_CLI'     => defined('WP_CLI') && WP_CLI,
45
+					'is_admin'   => is_admin(),
46
+				)
47
+			)
48
+		);
49
+		$request_type_context = $request_type_context_detector->detectRequestTypeContext();
50
+		$request_type_context->setIsUnitTesting(defined('EE_TESTS_DIR'));
51
+		$request_type_context_checker = $this->loader->getShared(
52
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
53
+			array($request_type_context)
54
+		);
55
+		$this->request->setRequestTypeContextChecker($request_type_context_checker);
56
+		$this->response = $this->processRequestStack($this->request, $this->response);
57
+		return $this->response;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Post_Content_Field.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -7,127 +7,127 @@
 block discarded – undo
7 7
 class EE_Post_Content_Field extends EE_Text_Field_Base
8 8
 {
9 9
 
10
-    /**
11
-     * @param string $table_column
12
-     * @param string $nicename
13
-     * @param bool   $nullable
14
-     * @param null   $default_value
15
-     */
16
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
-    {
18
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
19
-        $this->setSchemaType('object');
20
-    }
10
+	/**
11
+	 * @param string $table_column
12
+	 * @param string $nicename
13
+	 * @param bool   $nullable
14
+	 * @param null   $default_value
15
+	 */
16
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
+	{
18
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
19
+		$this->setSchemaType('object');
20
+	}
21 21
 
22 22
 
23
-    /**
24
-     * removes all tags which a WP Post wouldn't allow in its content normally
25
-     *
26
-     * @param string $value
27
-     * @return string
28
-     */
29
-    public function prepare_for_set($value)
30
-    {
31
-        if (! current_user_can('unfiltered_html')) {
32
-            $value = wp_kses("$value", wp_kses_allowed_html('post'));
33
-        }
34
-        return parent::prepare_for_set($value);
35
-    }
23
+	/**
24
+	 * removes all tags which a WP Post wouldn't allow in its content normally
25
+	 *
26
+	 * @param string $value
27
+	 * @return string
28
+	 */
29
+	public function prepare_for_set($value)
30
+	{
31
+		if (! current_user_can('unfiltered_html')) {
32
+			$value = wp_kses("$value", wp_kses_allowed_html('post'));
33
+		}
34
+		return parent::prepare_for_set($value);
35
+	}
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * Runs the content through `the_content`, or if prepares the content for placing in a form input
41
-     * @param string $value_on_field_to_be_outputted
42
-     * @param string   $schema possible values: 'form_input' or null (if null, will run through 'the_content')
43
-     * @return string
44
-     * @throws EE_Error when WP_DEBUG is on and recursive calling is detected
45
-     */
46
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
47
-    {
48
-        switch ($schema) {
49
-            case 'form_input':
50
-                return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
51
-            case 'the_content':
52
-                if (doing_filter('the_content')) {
53
-                    if (defined('WP_DEBUG') && WP_DEBUG) {
54
-                        throw new EE_Error(
55
-                            sprintf(
56
-                                esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'),
57
-                                'EE_Post_Content_Field::prepare_for_pretty_echoing',
58
-                                '$schema',
59
-                                'the_content',
60
-                                'the_content_wp_core_only'
61
-                            )
62
-                        );
63
-                    } else {
64
-                        return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only');
65
-                    }
66
-                }
67
-                return apply_filters(
68
-                    'the_content',
69
-                    parent::prepare_for_pretty_echoing(
70
-                        $value_on_field_to_be_outputted,
71
-                        $schema
72
-                    )
73
-                );
74
-            case 'the_content_wp_core_only':
75
-            default:
76
-                self::_setup_the_content_wp_core_only_filters();
77
-                $return_value = apply_filters(
78
-                    'the_content_wp_core_only',
79
-                    parent::prepare_for_pretty_echoing(
80
-                        $value_on_field_to_be_outputted,
81
-                        $schema
82
-                    )
83
-                );
84
-                // ya know what? adding these filters is super fast. Let's just
85
-                // avoid needing to maintain global state and set this up as-needed
86
-                remove_all_filters('the_content_wp_core_only');
87
-                do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
88
-                return $return_value;
89
-        }
90
-    }
39
+	/**
40
+	 * Runs the content through `the_content`, or if prepares the content for placing in a form input
41
+	 * @param string $value_on_field_to_be_outputted
42
+	 * @param string   $schema possible values: 'form_input' or null (if null, will run through 'the_content')
43
+	 * @return string
44
+	 * @throws EE_Error when WP_DEBUG is on and recursive calling is detected
45
+	 */
46
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
47
+	{
48
+		switch ($schema) {
49
+			case 'form_input':
50
+				return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
51
+			case 'the_content':
52
+				if (doing_filter('the_content')) {
53
+					if (defined('WP_DEBUG') && WP_DEBUG) {
54
+						throw new EE_Error(
55
+							sprintf(
56
+								esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'),
57
+								'EE_Post_Content_Field::prepare_for_pretty_echoing',
58
+								'$schema',
59
+								'the_content',
60
+								'the_content_wp_core_only'
61
+							)
62
+						);
63
+					} else {
64
+						return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only');
65
+					}
66
+				}
67
+				return apply_filters(
68
+					'the_content',
69
+					parent::prepare_for_pretty_echoing(
70
+						$value_on_field_to_be_outputted,
71
+						$schema
72
+					)
73
+				);
74
+			case 'the_content_wp_core_only':
75
+			default:
76
+				self::_setup_the_content_wp_core_only_filters();
77
+				$return_value = apply_filters(
78
+					'the_content_wp_core_only',
79
+					parent::prepare_for_pretty_echoing(
80
+						$value_on_field_to_be_outputted,
81
+						$schema
82
+					)
83
+				);
84
+				// ya know what? adding these filters is super fast. Let's just
85
+				// avoid needing to maintain global state and set this up as-needed
86
+				remove_all_filters('the_content_wp_core_only');
87
+				do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done');
88
+				return $return_value;
89
+		}
90
+	}
91 91
 
92 92
 
93 93
 
94
-    /**
95
-     * Verifies we've setup the standard WP core filters on  'the_content_wp_core_only' filter
96
-     */
97
-    protected static function _setup_the_content_wp_core_only_filters()
98
-    {
99
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8);
100
-        add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8);
101
-        add_filter('the_content_wp_core_only', 'wptexturize', 10);
102
-        add_filter('the_content_wp_core_only', 'wpautop', 10);
103
-        add_filter('the_content_wp_core_only', 'shortcode_unautop', 10);
104
-        add_filter('the_content_wp_core_only', 'prepend_attachment', 10);
105
-        if (function_exists('wp_filter_content_tags')) {
106
-            add_filter('the_content_wp_core_only', 'wp_filter_content_tags', 10);
107
-        }
108
-        add_filter('the_content_wp_core_only', 'do_shortcode', 11);
109
-        add_filter('the_content_wp_core_only', 'convert_smilies', 20);
110
-    }
94
+	/**
95
+	 * Verifies we've setup the standard WP core filters on  'the_content_wp_core_only' filter
96
+	 */
97
+	protected static function _setup_the_content_wp_core_only_filters()
98
+	{
99
+		add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8);
100
+		add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8);
101
+		add_filter('the_content_wp_core_only', 'wptexturize', 10);
102
+		add_filter('the_content_wp_core_only', 'wpautop', 10);
103
+		add_filter('the_content_wp_core_only', 'shortcode_unautop', 10);
104
+		add_filter('the_content_wp_core_only', 'prepend_attachment', 10);
105
+		if (function_exists('wp_filter_content_tags')) {
106
+			add_filter('the_content_wp_core_only', 'wp_filter_content_tags', 10);
107
+		}
108
+		add_filter('the_content_wp_core_only', 'do_shortcode', 11);
109
+		add_filter('the_content_wp_core_only', 'convert_smilies', 20);
110
+	}
111 111
 
112 112
 
113 113
 
114
-    public function getSchemaProperties()
115
-    {
116
-        return array(
117
-            'raw' => array(
118
-                'description' =>  sprintf(
119
-                    __('%s - the content as it exists in the database.', 'event_espresso'),
120
-                    $this->get_nicename()
121
-                ),
122
-                'type' => 'string'
123
-            ),
124
-            'rendered' => array(
125
-                'description' =>  sprintf(
126
-                    __('%s - the content rendered for display.', 'event_espresso'),
127
-                    $this->get_nicename()
128
-                ),
129
-                'type' => 'string'
130
-            )
131
-        );
132
-    }
114
+	public function getSchemaProperties()
115
+	{
116
+		return array(
117
+			'raw' => array(
118
+				'description' =>  sprintf(
119
+					__('%s - the content as it exists in the database.', 'event_espresso'),
120
+					$this->get_nicename()
121
+				),
122
+				'type' => 'string'
123
+			),
124
+			'rendered' => array(
125
+				'description' =>  sprintf(
126
+					__('%s - the content rendered for display.', 'event_espresso'),
127
+					$this->get_nicename()
128
+				),
129
+				'type' => 'string'
130
+			)
131
+		);
132
+	}
133 133
 }
Please login to merge, or discard this patch.
core/domain/entities/contexts/RequestTypeContext.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -16,185 +16,185 @@
 block discarded – undo
16 16
 class RequestTypeContext extends Context
17 17
 {
18 18
 
19
-    /**
20
-     * indicates that the current request involves some form of activation
21
-     */
22
-    const ACTIVATION = 'activation-request';
23
-
24
-    /**
25
-     * indicates that the current request is for the admin but is not being made via AJAX
26
-     */
27
-    const ADMIN = 'non-ajax-admin-request';
28
-
29
-    /**
30
-     * indicates that the current request is for the admin AND is being made via AJAX
31
-     */
32
-    const AJAX_ADMIN = 'admin-ajax-request';
33
-
34
-    /**
35
-     * indicates that the current request is for the frontend AND is being made via AJAX
36
-     */
37
-    const AJAX_FRONT = 'frontend-ajax-request';
38
-
39
-    /**
40
-     * indicates that the current request is for the WP Heartbeat
41
-     */
42
-    const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
-
44
-    /**
45
-     * indicates that the current request is being made via AJAX, but is NOT for EE
46
-     */
47
-    const AJAX_OTHER = 'other-ajax-request';
48
-
49
-    /**
50
-     * indicates that the current request is for the EE REST API
51
-     */
52
-    const API = 'rest-api';
53
-
54
-    /**
55
-     * indicates that the current request is from the command line
56
-     */
57
-    const CLI = 'command-line';
58
-
59
-    /**
60
-     * indicates that the current request is for a WP_Cron
61
-     */
62
-    const CRON = 'wp-cron';
63
-
64
-    /**
65
-     * indicates that the current request is for a feed (ie: RSS)
66
-     */
67
-    const FEED = 'feed-request';
68
-
69
-    /**
70
-     * indicates that the current request is for the frontend but is not being made via AJAX
71
-     */
72
-    const FRONTEND = 'non-ajax-frontend-request';
73
-
74
-    /**
75
-     * indicates that the current request is for content that is to be displayed within an iframe
76
-     */
77
-    const IFRAME = 'iframe-request';
78
-
79
-    /**
80
-     * indicates that the current request is for the EE GraphQL manager
81
-     */
82
-    const GQL = 'graphql';
83
-
84
-    /**
85
-     * indicates that the current request is for the WP REST API
86
-     */
87
-    const WP_API = 'wp-rest-api';
88
-
89
-    /**
90
-     * indicates that the current request is a loopback sent from WP core to test for errors
91
-     */
92
-    const WP_SCRAPE = 'wordpress-scrape';
93
-
94
-    /**
95
-     * @var boolean $is_activation
96
-     */
97
-    private $is_activation = false;
98
-
99
-    /**
100
-     * @var boolean $is_unit_testing
101
-     */
102
-    private $is_unit_testing = false;
103
-
104
-    /**
105
-     * @var array $valid_request_types
106
-     */
107
-    private $valid_request_types = array();
108
-
109
-
110
-    /**
111
-     * RequestTypeContext constructor.
112
-     *
113
-     * @param string $slug
114
-     * @param string $description
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function __construct($slug, $description)
118
-    {
119
-        parent::__construct($slug, $description);
120
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
-            throw new InvalidArgumentException(
122
-                sprintf(
123
-                    esc_html__(
124
-                        'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
-                        'event_espresso'
126
-                    ),
127
-                    '<br />',
128
-                    var_export($this->validRequestTypes(), true)
129
-                )
130
-            );
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function validRequestTypes()
139
-    {
140
-        if (empty($this->valid_request_types)) {
141
-            $this->valid_request_types = apply_filters(
142
-                'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
-                array(
144
-                    RequestTypeContext::ACTIVATION,
145
-                    RequestTypeContext::ADMIN,
146
-                    RequestTypeContext::AJAX_ADMIN,
147
-                    RequestTypeContext::AJAX_FRONT,
148
-                    RequestTypeContext::AJAX_HEARTBEAT,
149
-                    RequestTypeContext::AJAX_OTHER,
150
-                    RequestTypeContext::API,
151
-                    RequestTypeContext::CLI,
152
-                    RequestTypeContext::CRON,
153
-                    RequestTypeContext::FEED,
154
-                    RequestTypeContext::FRONTEND,
155
-                    RequestTypeContext::GQL,
156
-                    RequestTypeContext::IFRAME,
157
-                    RequestTypeContext::WP_API,
158
-                    RequestTypeContext::WP_SCRAPE,
159
-                )
160
-            );
161
-        }
162
-        return $this->valid_request_types;
163
-    }
164
-
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    public function isActivation()
170
-    {
171
-        return $this->is_activation;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param bool $is_activation
177
-     */
178
-    public function setIsActivation($is_activation)
179
-    {
180
-        $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-    /**
185
-     * @return bool
186
-     */
187
-    public function isUnitTesting()
188
-    {
189
-        return $this->is_unit_testing;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param bool $is_unit_testing
195
-     */
196
-    public function setIsUnitTesting($is_unit_testing)
197
-    {
198
-        $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
-    }
19
+	/**
20
+	 * indicates that the current request involves some form of activation
21
+	 */
22
+	const ACTIVATION = 'activation-request';
23
+
24
+	/**
25
+	 * indicates that the current request is for the admin but is not being made via AJAX
26
+	 */
27
+	const ADMIN = 'non-ajax-admin-request';
28
+
29
+	/**
30
+	 * indicates that the current request is for the admin AND is being made via AJAX
31
+	 */
32
+	const AJAX_ADMIN = 'admin-ajax-request';
33
+
34
+	/**
35
+	 * indicates that the current request is for the frontend AND is being made via AJAX
36
+	 */
37
+	const AJAX_FRONT = 'frontend-ajax-request';
38
+
39
+	/**
40
+	 * indicates that the current request is for the WP Heartbeat
41
+	 */
42
+	const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
+
44
+	/**
45
+	 * indicates that the current request is being made via AJAX, but is NOT for EE
46
+	 */
47
+	const AJAX_OTHER = 'other-ajax-request';
48
+
49
+	/**
50
+	 * indicates that the current request is for the EE REST API
51
+	 */
52
+	const API = 'rest-api';
53
+
54
+	/**
55
+	 * indicates that the current request is from the command line
56
+	 */
57
+	const CLI = 'command-line';
58
+
59
+	/**
60
+	 * indicates that the current request is for a WP_Cron
61
+	 */
62
+	const CRON = 'wp-cron';
63
+
64
+	/**
65
+	 * indicates that the current request is for a feed (ie: RSS)
66
+	 */
67
+	const FEED = 'feed-request';
68
+
69
+	/**
70
+	 * indicates that the current request is for the frontend but is not being made via AJAX
71
+	 */
72
+	const FRONTEND = 'non-ajax-frontend-request';
73
+
74
+	/**
75
+	 * indicates that the current request is for content that is to be displayed within an iframe
76
+	 */
77
+	const IFRAME = 'iframe-request';
78
+
79
+	/**
80
+	 * indicates that the current request is for the EE GraphQL manager
81
+	 */
82
+	const GQL = 'graphql';
83
+
84
+	/**
85
+	 * indicates that the current request is for the WP REST API
86
+	 */
87
+	const WP_API = 'wp-rest-api';
88
+
89
+	/**
90
+	 * indicates that the current request is a loopback sent from WP core to test for errors
91
+	 */
92
+	const WP_SCRAPE = 'wordpress-scrape';
93
+
94
+	/**
95
+	 * @var boolean $is_activation
96
+	 */
97
+	private $is_activation = false;
98
+
99
+	/**
100
+	 * @var boolean $is_unit_testing
101
+	 */
102
+	private $is_unit_testing = false;
103
+
104
+	/**
105
+	 * @var array $valid_request_types
106
+	 */
107
+	private $valid_request_types = array();
108
+
109
+
110
+	/**
111
+	 * RequestTypeContext constructor.
112
+	 *
113
+	 * @param string $slug
114
+	 * @param string $description
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function __construct($slug, $description)
118
+	{
119
+		parent::__construct($slug, $description);
120
+		if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
+			throw new InvalidArgumentException(
122
+				sprintf(
123
+					esc_html__(
124
+						'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
+						'event_espresso'
126
+					),
127
+					'<br />',
128
+					var_export($this->validRequestTypes(), true)
129
+				)
130
+			);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function validRequestTypes()
139
+	{
140
+		if (empty($this->valid_request_types)) {
141
+			$this->valid_request_types = apply_filters(
142
+				'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
+				array(
144
+					RequestTypeContext::ACTIVATION,
145
+					RequestTypeContext::ADMIN,
146
+					RequestTypeContext::AJAX_ADMIN,
147
+					RequestTypeContext::AJAX_FRONT,
148
+					RequestTypeContext::AJAX_HEARTBEAT,
149
+					RequestTypeContext::AJAX_OTHER,
150
+					RequestTypeContext::API,
151
+					RequestTypeContext::CLI,
152
+					RequestTypeContext::CRON,
153
+					RequestTypeContext::FEED,
154
+					RequestTypeContext::FRONTEND,
155
+					RequestTypeContext::GQL,
156
+					RequestTypeContext::IFRAME,
157
+					RequestTypeContext::WP_API,
158
+					RequestTypeContext::WP_SCRAPE,
159
+				)
160
+			);
161
+		}
162
+		return $this->valid_request_types;
163
+	}
164
+
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	public function isActivation()
170
+	{
171
+		return $this->is_activation;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param bool $is_activation
177
+	 */
178
+	public function setIsActivation($is_activation)
179
+	{
180
+		$this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return bool
186
+	 */
187
+	public function isUnitTesting()
188
+	{
189
+		return $this->is_unit_testing;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param bool $is_unit_testing
195
+	 */
196
+	public function setIsUnitTesting($is_unit_testing)
197
+	{
198
+		$this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/domain/services/contexts/RequestTypeContextChecker.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -16,238 +16,238 @@
 block discarded – undo
16 16
 class RequestTypeContextChecker extends ContextChecker implements RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var RequestTypeContext $request_type
21
-     */
22
-    private $request_type;
23
-
24
-
25
-    /**
26
-     * RequestTypeContextChecker constructor.
27
-     *
28
-     * @param RequestTypeContext $request_type
29
-     */
30
-    public function __construct(RequestTypeContext $request_type)
31
-    {
32
-        $this->request_type = $request_type;
33
-        parent::__construct(
34
-            'RequestTypeContextChecker',
35
-            $this->request_type->validRequestTypes()
36
-        );
37
-    }
38
-
39
-
40
-    /**
41
-     * true if the current request involves some form of activation
42
-     *
43
-     * @return bool
44
-     */
45
-    public function isActivation()
46
-    {
47
-        return $this->request_type->isActivation();
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $is_activation
53
-     */
54
-    public function setIsActivation($is_activation)
55
-    {
56
-        $this->request_type->setIsActivation($is_activation);
57
-    }
58
-
59
-
60
-    /**
61
-     * true if the current request is for the admin and is not being made via AJAX
62
-     *
63
-     * @return bool
64
-     */
65
-    public function isAdmin()
66
-    {
67
-        return $this->request_type->slug() === RequestTypeContext::ADMIN;
68
-    }
69
-
70
-
71
-    /**
72
-     * true if the current request is for the admin AND is being made via AJAX
73
-     *
74
-     * @return bool
75
-     */
76
-    public function isAdminAjax()
77
-    {
78
-        return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN;
79
-    }
80
-
81
-
82
-    /**
83
-     * true if the current request is being made via AJAX... any AJAX
84
-     *
85
-     * @return bool
86
-     */
87
-    public function isAjax()
88
-    {
89
-        return $this->isEeAjax() || $this->isOtherAjax();
90
-    }
91
-
92
-
93
-    /**
94
-     * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX
95
-     *
96
-     * @return bool
97
-     */
98
-    public function isEeAjax()
99
-    {
100
-        return $this->isAdminAjax() || $this->isFrontAjax();
101
-    }
102
-
103
-
104
-    /**
105
-     * true if the current request is being made via AJAX but is NOT for EE related logic
106
-     *
107
-     * @return bool
108
-     */
109
-    public function isOtherAjax()
110
-    {
111
-        return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER;
112
-    }
113
-
114
-    /**
115
-     * true if the current request is for the EE REST API
116
-     *
117
-     * @return bool
118
-     */
119
-    public function isApi()
120
-    {
121
-        return $this->request_type->slug() === RequestTypeContext::API;
122
-    }
123
-
124
-
125
-    /**
126
-     * true if the current request is from the command line
127
-     *
128
-     * @return bool
129
-     */
130
-    public function isCli()
131
-    {
132
-        return $this->request_type->slug() === RequestTypeContext::CLI;
133
-    }
134
-
135
-
136
-    /**
137
-     * true if the current request is for a WP_Cron
138
-     *
139
-     * @return bool
140
-     */
141
-    public function isCron()
142
-    {
143
-        return $this->request_type->slug() === RequestTypeContext::CRON;
144
-    }
145
-
146
-
147
-    /**
148
-     * true if the current request is for a feed (ie: RSS)
149
-     *
150
-     * @return bool
151
-     */
152
-    public function isFeed()
153
-    {
154
-        return $this->request_type->slug() === RequestTypeContext::FEED;
155
-    }
156
-
157
-
158
-    /**
159
-     * true if the current request is for the frontend and is not being made via AJAX
160
-     *
161
-     * @return bool
162
-     */
163
-    public function isFrontend()
164
-    {
165
-        return $this->request_type->slug() === RequestTypeContext::FRONTEND;
166
-    }
167
-
168
-
169
-    /**
170
-     * true if the current request is for the frontend AND is being made via AJAX
171
-     *
172
-     * @return bool
173
-     */
174
-    public function isFrontAjax()
175
-    {
176
-        return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT;
177
-    }
178
-
179
-
180
-    /**
181
-     * true if the current request is for the EE GraphQL manager
182
-     *
183
-     * @return bool
184
-     */
185
-    public function isGQL()
186
-    {
187
-        return $this->request_type->slug() === RequestTypeContext::GQL;
188
-    }
189
-
190
-
191
-    /**
192
-     * true if the current request is for content that is to be displayed within an iframe
193
-     *
194
-     * @return bool
195
-     */
196
-    public function isIframe()
197
-    {
198
-        return $this->request_type->slug() === RequestTypeContext::IFRAME;
199
-    }
200
-
201
-
202
-    /**
203
-     * true if the current request is occurring while unit testing
204
-     *
205
-     * @return bool
206
-     */
207
-    public function isUnitTesting()
208
-    {
209
-        return $this->request_type->isUnitTesting();
210
-    }
211
-
212
-
213
-    /**
214
-     * true if the current request is for the WP REST API
215
-     *
216
-     * @return bool
217
-     */
218
-    public function isWordPressApi()
219
-    {
220
-        return $this->request_type->slug() === RequestTypeContext::WP_API;
221
-    }
222
-
223
-
224
-    /**
225
-     * true if the current request is being made via AJAX for the WP Heartbeat
226
-     *
227
-     * @return bool
228
-     */
229
-    public function isWordPressHeartbeat()
230
-    {
231
-        return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT;
232
-    }
233
-
234
-
235
-    /**
236
-     * true if the current request is a loopback sent from WP core to test for errors
237
-     *
238
-     * @return bool
239
-     */
240
-    public function isWordPressScrape()
241
-    {
242
-        return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE;
243
-    }
244
-
245
-
246
-    /**
247
-     * @return string
248
-     */
249
-    public function slug()
250
-    {
251
-        return $this->request_type->slug();
252
-    }
19
+	/**
20
+	 * @var RequestTypeContext $request_type
21
+	 */
22
+	private $request_type;
23
+
24
+
25
+	/**
26
+	 * RequestTypeContextChecker constructor.
27
+	 *
28
+	 * @param RequestTypeContext $request_type
29
+	 */
30
+	public function __construct(RequestTypeContext $request_type)
31
+	{
32
+		$this->request_type = $request_type;
33
+		parent::__construct(
34
+			'RequestTypeContextChecker',
35
+			$this->request_type->validRequestTypes()
36
+		);
37
+	}
38
+
39
+
40
+	/**
41
+	 * true if the current request involves some form of activation
42
+	 *
43
+	 * @return bool
44
+	 */
45
+	public function isActivation()
46
+	{
47
+		return $this->request_type->isActivation();
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $is_activation
53
+	 */
54
+	public function setIsActivation($is_activation)
55
+	{
56
+		$this->request_type->setIsActivation($is_activation);
57
+	}
58
+
59
+
60
+	/**
61
+	 * true if the current request is for the admin and is not being made via AJAX
62
+	 *
63
+	 * @return bool
64
+	 */
65
+	public function isAdmin()
66
+	{
67
+		return $this->request_type->slug() === RequestTypeContext::ADMIN;
68
+	}
69
+
70
+
71
+	/**
72
+	 * true if the current request is for the admin AND is being made via AJAX
73
+	 *
74
+	 * @return bool
75
+	 */
76
+	public function isAdminAjax()
77
+	{
78
+		return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN;
79
+	}
80
+
81
+
82
+	/**
83
+	 * true if the current request is being made via AJAX... any AJAX
84
+	 *
85
+	 * @return bool
86
+	 */
87
+	public function isAjax()
88
+	{
89
+		return $this->isEeAjax() || $this->isOtherAjax();
90
+	}
91
+
92
+
93
+	/**
94
+	 * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX
95
+	 *
96
+	 * @return bool
97
+	 */
98
+	public function isEeAjax()
99
+	{
100
+		return $this->isAdminAjax() || $this->isFrontAjax();
101
+	}
102
+
103
+
104
+	/**
105
+	 * true if the current request is being made via AJAX but is NOT for EE related logic
106
+	 *
107
+	 * @return bool
108
+	 */
109
+	public function isOtherAjax()
110
+	{
111
+		return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER;
112
+	}
113
+
114
+	/**
115
+	 * true if the current request is for the EE REST API
116
+	 *
117
+	 * @return bool
118
+	 */
119
+	public function isApi()
120
+	{
121
+		return $this->request_type->slug() === RequestTypeContext::API;
122
+	}
123
+
124
+
125
+	/**
126
+	 * true if the current request is from the command line
127
+	 *
128
+	 * @return bool
129
+	 */
130
+	public function isCli()
131
+	{
132
+		return $this->request_type->slug() === RequestTypeContext::CLI;
133
+	}
134
+
135
+
136
+	/**
137
+	 * true if the current request is for a WP_Cron
138
+	 *
139
+	 * @return bool
140
+	 */
141
+	public function isCron()
142
+	{
143
+		return $this->request_type->slug() === RequestTypeContext::CRON;
144
+	}
145
+
146
+
147
+	/**
148
+	 * true if the current request is for a feed (ie: RSS)
149
+	 *
150
+	 * @return bool
151
+	 */
152
+	public function isFeed()
153
+	{
154
+		return $this->request_type->slug() === RequestTypeContext::FEED;
155
+	}
156
+
157
+
158
+	/**
159
+	 * true if the current request is for the frontend and is not being made via AJAX
160
+	 *
161
+	 * @return bool
162
+	 */
163
+	public function isFrontend()
164
+	{
165
+		return $this->request_type->slug() === RequestTypeContext::FRONTEND;
166
+	}
167
+
168
+
169
+	/**
170
+	 * true if the current request is for the frontend AND is being made via AJAX
171
+	 *
172
+	 * @return bool
173
+	 */
174
+	public function isFrontAjax()
175
+	{
176
+		return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT;
177
+	}
178
+
179
+
180
+	/**
181
+	 * true if the current request is for the EE GraphQL manager
182
+	 *
183
+	 * @return bool
184
+	 */
185
+	public function isGQL()
186
+	{
187
+		return $this->request_type->slug() === RequestTypeContext::GQL;
188
+	}
189
+
190
+
191
+	/**
192
+	 * true if the current request is for content that is to be displayed within an iframe
193
+	 *
194
+	 * @return bool
195
+	 */
196
+	public function isIframe()
197
+	{
198
+		return $this->request_type->slug() === RequestTypeContext::IFRAME;
199
+	}
200
+
201
+
202
+	/**
203
+	 * true if the current request is occurring while unit testing
204
+	 *
205
+	 * @return bool
206
+	 */
207
+	public function isUnitTesting()
208
+	{
209
+		return $this->request_type->isUnitTesting();
210
+	}
211
+
212
+
213
+	/**
214
+	 * true if the current request is for the WP REST API
215
+	 *
216
+	 * @return bool
217
+	 */
218
+	public function isWordPressApi()
219
+	{
220
+		return $this->request_type->slug() === RequestTypeContext::WP_API;
221
+	}
222
+
223
+
224
+	/**
225
+	 * true if the current request is being made via AJAX for the WP Heartbeat
226
+	 *
227
+	 * @return bool
228
+	 */
229
+	public function isWordPressHeartbeat()
230
+	{
231
+		return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT;
232
+	}
233
+
234
+
235
+	/**
236
+	 * true if the current request is a loopback sent from WP core to test for errors
237
+	 *
238
+	 * @return bool
239
+	 */
240
+	public function isWordPressScrape()
241
+	{
242
+		return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE;
243
+	}
244
+
245
+
246
+	/**
247
+	 * @return string
248
+	 */
249
+	public function slug()
250
+	{
251
+		return $this->request_type->slug();
252
+	}
253 253
 }
Please login to merge, or discard this patch.