UsageStatistics_Widget.php
1.86 KB
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
<?php
namespace W3TC;
/**
* widget with stats
*/
class UsageStatistics_Widget {
function init() {
add_action( 'admin_print_styles-toplevel_page_w3tc_dashboard',
array( $this, 'admin_print_styles_w3tc_dashboard' ) );
add_action( 'admin_print_scripts-toplevel_page_w3tc_dashboard',
array( $this, 'admin_print_scripts_w3tc_dashboard' ) );
add_action( 'w3tc_widget_setup', array(
$this,
'w3tc_widget_setup'
) );
add_action( 'w3tc_ajax_ustats_get', array( $this, 'w3tc_ajax_ustats_get' ) );
}
function w3tc_widget_setup() {
Util_Widget::add( 'w3tc_usage_statistics',
'<div class="w3tc-widget-w3tc-logo"></div>' .
'<div class="w3tc-widget-text">' .
__( 'Caching Statistics', 'w3-total-cache' ) .
'</div>',
array( $this, 'widget_form' ),
Util_Ui::admin_url( 'admin.php?page=w3tc_general#miscellaneous' ),
'normal' );
}
function widget_form() {
$storage = new UsageStatistics_StorageReader();
$summary_promise = $storage->get_history_summary_promise();
$c = Dispatcher::config();
if ( $c->get_boolean( 'stats.enabled' ) && Util_Environment::is_w3tc_pro( $c ) )
include W3TC_DIR . '/UsageStatistics_Widget_View.php';
else
include W3TC_DIR . '/UsageStatistics_Widget_View_Disabled.php';
}
public function admin_print_styles_w3tc_dashboard() {
wp_enqueue_style( 'w3tc-widget' );
wp_enqueue_style( 'w3tc-widget-usage-statistics',
plugins_url( 'UsageStatistics_Widget_View.css', W3TC_FILE ),
array(), W3TC_VERSION );
}
public function admin_print_scripts_w3tc_dashboard() {
wp_enqueue_script( 'w3tc-widget-usage-statistics',
plugins_url( 'UsageStatistics_Widget_View.js', W3TC_FILE ),
array(), W3TC_VERSION );
}
public function w3tc_ajax_ustats_get() {
$storage = new UsageStatistics_StorageReader();
$summary = $storage->get_history_summary();
echo json_encode( $summary );
exit();
}
}