PluginProbe
ElasticPress / 4.5.1
ElasticPress v4.5.1
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / Screen.php

Screen.php in ElasticPress 4.5.1, at includes/classes/Screen.php

194 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Determine which ElasticPress screen we are viewing
4 *
5 * @since 3.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress;
10
11 use ElasticPress\Utils;
12 use ElasticPress\Installer;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Screen class
20 */
21 class Screen {
22 /**
23 * Current screen
24 *
25 * @var string
26 * @since 3.0
27 */
28 protected $screen = null;
29
30 /**
31 * Sync screen instance
32 *
33 * @var Screen\Sync
34 * @since 3.6.0
35 */
36 public $sync_screen;
37
38 /**
39 * Info screen instance
40 *
41 * @var Screen\HealthInfo
42 * @since 4.3.0
43 */
44 public $health_info_screen;
45
46 /**
47 * Status report instance
48 *
49 * @var Screen\StatusReport
50 * @since 4.5.0
51 */
52 public $status_report;
53
54 /**
55 * Initialize class
56 *
57 * @since 3.0
58 */
59 public function setup() {
60 add_action( 'admin_init', [ $this, 'determine_screen' ] );
61
62 $this->sync_screen = new Screen\Sync();
63 $this->health_info_screen = new Screen\HealthInfo();
64 $this->status_report = new Screen\StatusReport();
65
66 $this->sync_screen->setup();
67 $this->health_info_screen->setup();
68 $this->status_report->setup();
69 }
70
71 /**
72 * Determine current ElasticPress screen. null means not EP screen.
73 *
74 * @since 3.0
75 */
76 public function determine_screen() {
77 // If in network mode, don't output notice in admin and vice-versa.
78 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
79 if ( ! is_network_admin() ) {
80 return false;
81 }
82 } else {
83 if ( is_network_admin() ) {
84 return false;
85 }
86 }
87
88 // phpcs:disable WordPress.Security.NonceVerification
89 if ( ! empty( $_GET['page'] ) && false !== strpos( $_GET['page'], 'elasticpress' ) ) {
90 $install_status = Installer::factory()->get_install_status();
91
92 $this->screen = 'install';
93
94 if ( 'elasticpress' === $_GET['page'] ) {
95 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
96 $this->screen = 'dashboard';
97 }
98 } elseif ( 'elasticpress-settings' === $_GET['page'] ) {
99 if ( true === $install_status || 2 === $install_status || isset( $_GET['do_sync'] ) ) {
100 $this->screen = 'settings';
101 }
102 } elseif ( 'elasticpress-health' === $_GET['page'] ) {
103 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
104 $this->screen = 'health';
105 }
106 } elseif ( 'elasticpress-weighting' === $_GET['page'] ) {
107 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
108 $this->screen = 'weighting';
109 }
110 } elseif ( 'elasticpress-synonyms' === $_GET['page'] ) {
111 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
112 $this->screen = 'synonyms';
113 }
114 } elseif ( 'elasticpress-sync' === $_GET['page'] ) {
115 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
116 $this->screen = 'sync';
117 }
118 } elseif ( 'elasticpress-status-report' === $_GET['page'] ) {
119 if ( ! isset( $_GET['install_complete'] ) && ( true === $install_status || isset( $_GET['do_sync'] ) ) ) {
120 $this->screen = 'status-report';
121 }
122 }
123 }
124 // phpcs:enable WordPress.Security.NonceVerification
125 }
126
127 /**
128 * Output template for current screen
129 *
130 * @since 3.0
131 */
132 public function output() {
133 $install_status = Installer::factory()->get_install_status();
134
135 switch ( $this->screen ) {
136 case 'dashboard':
137 require_once __DIR__ . '/../partials/dashboard-page.php';
138 break;
139 case 'settings':
140 require_once __DIR__ . '/../partials/settings-page.php';
141 break;
142 case 'install':
143 require_once __DIR__ . '/../partials/install-page.php';
144 break;
145 case 'health':
146 require_once __DIR__ . '/../partials/stats-page.php';
147 break;
148 case 'sync':
149 require_once __DIR__ . '/../partials/sync-page.php';
150 break;
151 case 'status-report':
152 require_once __DIR__ . '/../partials/status-report-page.php';
153 break;
154 }
155 }
156
157 /**
158 * Get current screen
159 *
160 * @since 3.0
161 * @return string
162 */
163 public function get_current_screen() {
164 return $this->screen;
165 }
166
167 /**
168 * Set current screen
169 *
170 * @since 3.0
171 * @param string $screen Screen to set
172 */
173 public function set_current_screen( $screen ) {
174 $this->screen = $screen;
175 }
176
177 /**
178 * Return singleton instance of class
179 *
180 * @return self
181 * @since 3.0
182 */
183 public static function factory() {
184 static $instance = false;
185
186 if ( ! $instance ) {
187 $instance = new self();
188 $instance->setup();
189 }
190
191 return $instance;
192 }
193 }
194