forked from wp-plugins/wp-statistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.php
334 lines (237 loc) · 17.1 KB
/
dashboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
add_action( 'wp_dashboard_setup', 'wp_statistics_dashboard_widget_load' );
function wp_statistics_dashboard_widget_load() {
GLOBAL $WP_Statistics;
$WP_Statistics->load_user_options();
// We need to fudge the display settings for first time users so not all of the widgets are displayed, we only want to do this on
// the first time they visit the dashboard though so check to see if we've been here before.
if( !$WP_Statistics->get_user_option('dashboard_set') ) {
$WP_Statistics->update_user_option('dashboard_set', WP_STATISTICS_VERSION);
$hidden_widgets = get_user_meta($WP_Statistics->user_id, 'metaboxhidden_dashboard', true);
if( !is_array( $hidden_widgets ) ) { $hidden_widgets = array(); }
$default_hidden = array('wp-statistics-browsers-widget','wp-statistics-countries-widget','wp-statistics-hitsmap-widget',
'wp-statistics-hits-widget','wp-statistics-pages-widget','wp-statistics-recent-widget','wp-statistics-referring-widget',
'wp-statistics-search-widget','wp-statistics-summary-widget','wp-statistics-words-widget', 'wp-statistics-top-visitors-widget' );
foreach( $default_hidden as $widget ) {
if( !in_array( $widget, $hidden_widgets ) ) {
$hidden_widgets[] = $widget;
}
}
update_user_meta( $WP_Statistics->user_id, 'metaboxhidden_dashboard', $hidden_widgets );
}
else if( $WP_Statistics->get_user_option('dashboard_set') != WP_STATISTICS_VERSION ) {
// We also have to fudge things when we add new widgets to the code base.
if( version_compare( $WP_Statistics->get_user_option('dashboard_set'), '8.7', '<' ) ) {
$WP_Statistics->update_user_option('dashboard_set', WP_STATISTICS_VERSION);
$hidden_widgets = get_user_meta($WP_Statistics->user_id, 'metaboxhidden_dashboard', true);
if( !is_array( $hidden_widgets ) ) { $hidden_widgets = array(); }
$default_hidden = array('wp-statistics-top-visitors-widget' );
foreach( $default_hidden as $widget ) {
if( !in_array( $widget, $hidden_widgets ) ) {
$hidden_widgets[] = $widget;
}
}
update_user_meta( $WP_Statistics->user_id, 'metaboxhidden_dashboard', $hidden_widgets );
}
}
// If the user does not have at least read access to the status plugin, just return without adding the widgets.
if (!current_user_can(wp_statistics_validate_capability($WP_Statistics->get_option('read_capability', 'manage_option')))) { return; }
// If the admin has disabled the widgets, don't display them.
if (!$WP_Statistics->get_option('disable_dashboard')) {
wp_add_dashboard_widget( 'wp-statistics-quickstats-widget', __('Quick Stats', 'wp_statistics'), 'wp_statistics_quickstats_widget', $control_callback = null );
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-browsers-widget', __('Top 10 Browsers', 'wp_statistics'), 'wp_statistics_browsers_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-countries-widget', __('Top 10 Countries', 'wp_statistics'), 'wp_statistics_countries_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-hitsmap-widget', __('Today\'s Visitor Map', 'wp_statistics'), 'wp_statistics_hitsmap_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visits') ) { wp_add_dashboard_widget( 'wp-statistics-hits-widget', __('Hit Statistics', 'wp_statistics'), 'wp_statistics_hits_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('pages') ) { wp_add_dashboard_widget( 'wp-statistics-pages-widget', __('Top 10 Pages', 'wp_statistics'), 'wp_statistics_pages_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-recent-widget', __('Recent Visitors', 'wp_statistics'), 'wp_statistics_recent_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-referring-widget', __('Top Referring Sites', 'wp_statistics'), 'wp_statistics_referring_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-search-widget', __('Search Engine Referrals', 'wp_statistics'), 'wp_statistics_search_widget', $control_callback = null ); }
wp_add_dashboard_widget( 'wp-statistics-summary-widget', __('Summary', 'wp_statistics'), 'wp_statistics_summary_widget', $control_callback = null );
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-words-widget', __('Latest Search Words', 'wp_statistics'), 'wp_statistics_words_widget', $control_callback = null ); }
if( $WP_Statistics->get_option('visitors') ) { wp_add_dashboard_widget( 'wp-statistics-top-visitors-widget', __('Top 10 Visitors Today', 'wp_statistics'), 'wp_statistics_top_visitors_widget', $control_callback = null ); }
}
}
function wp_statistics_load_widget_css_and_scripts() {
// Load the css we use for the statistics pages.
wp_enqueue_style('log-css', plugin_dir_url(__FILE__) . 'assets/css/log.css', true, '1.1');
wp_enqueue_style('jqplot-css', plugin_dir_url(__FILE__) . 'assets/css/jquery.jqplot.min.css', true, '1.0.8');
// Don't forget the right to left support.
if( is_rtl() )
wp_enqueue_style('rtl-css', plugin_dir_url(__FILE__) . 'assets/css/rtl.css', true, '1.1');
// Load the charts code.
wp_enqueue_script('jqplot', plugin_dir_url(__FILE__) . 'assets/js/jquery.jqplot.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-daterenderer', plugin_dir_url(__FILE__) . 'assets/js/jqplot.dateAxisRenderer.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-tickrenderer', plugin_dir_url(__FILE__) . 'assets/js/jqplot.canvasAxisTickRenderer.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-axisrenderer', plugin_dir_url(__FILE__) . 'assets/js/jqplot.canvasAxisLabelRenderer.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-textrenderer', plugin_dir_url(__FILE__) . 'assets/js/jqplot.canvasTextRenderer.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-tooltip', plugin_dir_url(__FILE__) . 'assets/js/jqplot.highlighter.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-pierenderer', plugin_dir_url(__FILE__) . 'assets/js/jqplot.pieRenderer.min.js', true, '0.8.3');
wp_enqueue_script('jqplot-enhancedlengend', plugin_dir_url(__FILE__) . 'assets/js/jqplot.enhancedLegendRenderer.min.js', true, '0.8.3');
}
function wp_statistics_is_wp_widget_visible( $widget, $type = 'dashboard' ) {
GLOBAL $WP_Statistics;
$hidden_widgets = get_user_meta($WP_Statistics->user_id,'metaboxhidden_' . $type, true);
if( !is_array( $hidden_widgets ) ) { $hidden_widgets = array(); }
if( in_array( $widget, $hidden_widgets ) ) {
return __('Please reload the dashboard to display the content of this widget.', 'wp_statistics');
}
return true;
}
function wp_statistics_quickstats_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-quickstats-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the summary widget, we're just going to use the content for the the users online and visit/visitor totals
include_once( dirname( __FILE__ ) . "/includes/log/widgets/summary.php");
wp_statistics_generate_summary_postbox_content(null, false, false);
// We can only have one hit's chart per page, so if the hits widget is visible, don't display it here.
if( wp_statistics_is_wp_widget_visible( 'wp-statistics-hits-widget' ) !== true ) {
?>
<br>
<hr width="80%"/>
<br>
<?php
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/hits.php");
wp_statistics_generate_hits_postbox_content("300px", 10);
}
?>
<br>
<hr width="80%"/>
<br>
<div style="text-align: center;">
<a class="button-primary" href="admin.php?page=wp-statistics/wp-statistics.php"><?php _e('WP Statistics Overview', 'wp_statistics');?></a>
</div>
<br>
<?php
}
function wp_statistics_browsers_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-browsers-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the summary widget, we're just going to use the content for the the users online and visit/visitor totals.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/browsers.php");
wp_statistics_generate_browsers_postbox_content();
}
function wp_statistics_countries_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-countries-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
$ISOCountryCode = $WP_Statistics->get_country_codes();
// Include the country widget.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/countries.php");
wp_statistics_generate_countries_postbox_content($ISOCountryCode);
}
function wp_statistics_hitsmap_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-hitsmap-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
$ISOCountryCode = $WP_Statistics->get_country_codes();
// Include the map widget.
if( $WP_Statistics->get_option( 'map_type' ) == 'jqvmap' ) {
wp_enqueue_style('jqvmap-css', plugin_dir_url(__FILE__) . 'assets/jqvmap/jqvmap.css', true, '1.1');
wp_enqueue_script('jquery-vmap', plugin_dir_url(__FILE__) . 'assets/jqvmap/jquery.vmap.min.js', true, '1.1');
wp_enqueue_script('jquery-vmap-world', plugin_dir_url(__FILE__) . 'assets/jqvmap/maps/jquery.vmap.world.js', true, '1.1');
include_once( dirname( __FILE__ ) . "/includes/log/widgets/jqv.map.php");
}
else {
include_once( dirname( __FILE__ ) . "/includes/log/widgets/google.map.php");
}
wp_statistics_generate_map_postbox_content($ISOCountryCode);
}
function wp_statistics_hits_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-hits-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/hits.php");
wp_statistics_generate_hits_postbox_content("300px", 10);
}
function wp_statistics_pages_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-pages-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/pages.php");
list( $total, $uris ) = wp_statistics_get_top_pages();
wp_statistics_generate_pages_postbox_content($total, $uris);
}
function wp_statistics_recent_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-recent-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/recent.php");
$ISOCountryCode = $WP_Statistics->get_country_codes();
wp_statistics_generate_recent_postbox_content($ISOCountryCode);
}
function wp_statistics_referring_widget() {
GLOBAL $wpdb, $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-referring-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/referring.php");
if( sizeof( $result ) > 0 ) {
wp_statistics_generate_referring_postbox_content();
}
}
function wp_statistics_search_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-search-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/search.php");
wp_statistics_generate_search_postbox_content(wp_statistics_searchengine_list(), '300px', 10);
}
function wp_statistics_summary_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-summary-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/summary.php");
wp_statistics_generate_summary_postbox_content(wp_statistics_searchengine_list());
}
function wp_statistics_words_widget() {
GLOBAL $wpdb, $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-words-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
$ISOCountryCode = $WP_Statistics->get_country_codes();
// Include the hits chart widget, we're going to display the last 10 days only as the WordPress columns are kind of small to do much else.
include_once( dirname( __FILE__ ) . "/includes/log/widgets/words.php");
wp_statistics_generate_words_postbox_content($ISOCountryCode);
}
function wp_statistics_top_visitors_widget() {
GLOBAL $WP_Statistics;
// If the widget isn't visible, don't output the stats as they take too much memory and CPU to compute for no reason.
if( ( $is_visible = wp_statistics_is_wp_widget_visible( 'wp-statistics-top-visitors-widget', 'dashboard' ) ) !== true ) { echo $is_visible; return; }
// Load the css we use for the statistics pages.
wp_statistics_load_widget_css_and_scripts();
// Include the summary widget, we're just going to use the content for the the users online and visit/visitor totals.
$ISOCountryCode = $WP_Statistics->get_country_codes();
include_once( dirname( __FILE__ ) . "/includes/log/widgets/top.visitors.php");
wp_statistics_generate_top_visitors_postbox_content($ISOCountryCode, 'today', 10, true);
}
?>