Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/google-site-kit/includes/Core/Admin/Dashboard.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Class Google\Site_Kit\Core\Admin\Dashboard
4
+
*
5
+
* @package Google\Site_Kit
6
+
* @copyright 2021 Google LLC
7
+
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
8
+
* @link https://sitekit.withgoogle.com
9
+
*/
10
+
11
+
namespace Google\Site_Kit\Core\Admin;
12
+
13
+
use Google\Site_Kit\Context;
14
+
use Google\Site_Kit\Core\Assets\Assets;
15
+
use Google\Site_Kit\Core\Authentication\Authentication;
16
+
use Google\Site_Kit\Core\Modules\Modules;
17
+
use Google\Site_Kit\Core\Permissions\Permissions;
18
+
use Google\Site_Kit\Core\Util\Requires_Javascript_Trait;
19
+
20
+
/**
21
+
* Class to handle all wp-admin Dashboard related functionality.
22
+
*
23
+
* @since 1.0.0
24
+
* @access private
25
+
* @ignore
26
+
*/
27
+
final class Dashboard {
28
+
use Requires_Javascript_Trait;
29
+
30
+
/**
31
+
* Plugin context.
32
+
*
33
+
* @since 1.0.0
34
+
* @var Context
35
+
*/
36
+
private $context;
37
+
38
+
/**
39
+
* Assets Instance.
40
+
*
41
+
* @since 1.0.0
42
+
* @var Assets
43
+
*/
44
+
private $assets;
45
+
46
+
/**
47
+
* Modules instance.
48
+
*
49
+
* @since 1.7.0
50
+
* @var Modules
51
+
*/
52
+
private $modules;
53
+
54
+
/**
55
+
* Authentication instance.
56
+
*
57
+
* @since 1.120.0
58
+
* @var Authentication
59
+
*/
60
+
private $authentication;
61
+
62
+
/**
63
+
* Constructor.
64
+
*
65
+
* @since 1.0.0
66
+
*
67
+
* @param Context $context Plugin context.
68
+
* @param Assets $assets Optional. Assets API instance. Default is a new instance.
69
+
* @param Modules $modules Optional. Modules instance. Default is a new instance.
70
+
*/
71
+
public function __construct(
72
+
Context $context,
73
+
?Assets $assets = null,
74
+
?Modules $modules = null
75
+
) {
76
+
$this->context = $context;
77
+
$this->assets = $assets ?: new Assets( $this->context );
78
+
$this->modules = $modules ?: new Modules( $this->context );
79
+
80
+
$this->authentication = new Authentication( $this->context );
81
+
}
82
+
83
+
/**
84
+
* Registers functionality through WordPress hooks.
85
+
*
86
+
* @since 1.0.0
87
+
*/
88
+
public function register() {
89
+
add_action(
90
+
'wp_dashboard_setup',
91
+
function () {
92
+
$this->add_widgets();
93
+
}
94
+
);
95
+
}
96
+
97
+
/**
98
+
* Add a Site Kit by Google widget to the WordPress admin dashboard.
99
+
*
100
+
* @since 1.0.0
101
+
*/
102
+
private function add_widgets() {
103
+
if ( ! current_user_can( Permissions::VIEW_WP_DASHBOARD_WIDGET ) ) {
104
+
return;
105
+
}
106
+
107
+
// Enqueue styles.
108
+
$this->assets->enqueue_asset( 'googlesitekit-wp-dashboard-css' );
109
+
110
+
// Enqueue scripts.
111
+
$this->assets->enqueue_asset( 'googlesitekit-wp-dashboard' );
112
+
$this->modules->enqueue_assets();
113
+
114
+
wp_add_dashboard_widget(
115
+
'google_dashboard_widget',
116
+
__( 'Site Kit Summary', 'google-site-kit' ),
117
+
function () {
118
+
$this->render_googlesitekit_wp_dashboard();
119
+
}
120
+
);
121
+
}
122
+
123
+
/**
124
+
* Render the Site Kit WordPress Dashboard widget.
125
+
*
126
+
* @since 1.0.0
127
+
* @since 1.120.0 Added the `data-view-only` attribute.
128
+
*/
129
+
private function render_googlesitekit_wp_dashboard() {
130
+
$active_modules = $this->modules->get_active_modules();
131
+
$analytics_connected = isset( $active_modules['analytics-4'] ) && $active_modules['analytics-4']->is_connected();
132
+
$search_console_connected = isset( $active_modules['search-console'] ) && $active_modules['search-console']->is_connected();
133
+
$is_view_only = ! $this->authentication->is_authenticated();
134
+
$can_view_shared_analytics = current_user_can( Permissions::READ_SHARED_MODULE_DATA, 'analytics-4' );
135
+
$can_view_shared_search_console = current_user_can( Permissions::READ_SHARED_MODULE_DATA, 'search-console' );
136
+
$display_analytics_data = ( ! $is_view_only && $analytics_connected ) || ( $is_view_only && $can_view_shared_analytics );
137
+
$display_search_console_data = ( ! $is_view_only && $search_console_connected ) || ( $is_view_only && $can_view_shared_search_console );
138
+
139
+
$class_names = array();
140
+
141
+
if ( $analytics_connected && $display_analytics_data ) {
142
+
$class_names[] = 'googlesitekit-wp-dashboard-analytics_active_and_connected';
143
+
}
144
+
145
+
if ( $search_console_connected && $display_search_console_data ) {
146
+
$class_names[] = 'googlesitekit-wp-dashboard-search_console_active_and_connected';
147
+
}
148
+
149
+
if ( ! $analytics_connected && ! $is_view_only ) {
150
+
$class_names[] = 'googlesitekit-wp-dashboard-analytics-activate-cta';
151
+
}
152
+
153
+
$class_names = implode( ' ', $class_names );
154
+
155
+
$this->render_noscript_html();
156
+
?>
157
+
<div id="js-googlesitekit-wp-dashboard" data-view-only="<?php echo esc_attr( $is_view_only ); ?>" class="googlesitekit-plugin <?php echo esc_attr( $class_names ); ?>">
158
+
<div class="googlesitekit-wp-dashboard googlesitekit-wp-dashboard-loading">
159
+
<?php
160
+
161
+
$this->render_loading_container( 'googlesitekit-wp-dashboard__cta' );
162
+
?>
163
+
164
+
<div class="googlesitekit-wp-dashboard-stats">
165
+
<?php
166
+
if ( $display_analytics_data ) {
167
+
$this->render_loading_container( 'googlesitekit-wp-dashboard-loading__can_view_analytics' );
168
+
}
169
+
170
+
if ( $display_search_console_data ) {
171
+
$this->render_loading_container( 'googlesitekit-wp-dashboard-loading__search_console_active_and_connected' );
172
+
}
173
+
174
+
if ( ! $analytics_connected && ! $is_view_only ) {
175
+
$this->render_loading_container( 'googlesitekit-wp-dashboard-stats__cta' );
176
+
}
177
+
178
+
if ( $display_analytics_data ) {
179
+
$this->render_loading_container( 'googlesitekit-unique-visitors-chart-widget' );
180
+
$this->render_loading_container( 'googlesitekit-search-console-widget' );
181
+
}
182
+
?>
183
+
</div>
184
+
</div>
185
+
</div>
186
+
<?php
187
+
}
188
+
189
+
/**
190
+
* Render the loading container when data is not available and being fetched.
191
+
*
192
+
* @since 1.144.0
193
+
* @param string $class_names Class names to add to the container.
194
+
* @return void
195
+
*/
196
+
private function render_loading_container( $class_names ) {
197
+
?>
198
+
<div class="googlesitekit-preview-block <?php echo esc_attr( $class_names ); ?>">
199
+
<div class="googlesitekit-preview-block__wrapper"></div>
200
+
</div>
201
+
<?php
202
+
}
203
+
}
204
+