Extension_NewRelic_Plugin_Admin.php
5.57 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
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
<?php
namespace W3TC;
class Extension_NewRelic_Plugin_Admin {
private $_config;
/**
*
*
* @param unknown $extensions
* @param Config $config
* @return mixed
*/
static public function w3tc_extensions( $extensions, $config ) {
$extensions['newrelic'] = array (
'name' => 'New Relic',
'author' => 'W3 EDGE',
'description' => __( 'New Relic is software analytics platform offering app performance management and mobile monitoring solutions.', 'w3-total-cache' ),
'author_uri' => 'https://www.w3-edge.com/',
'extension_uri' => 'https://www.w3-edge.com/',
'extension_id' => 'newrelic',
'settings_exists' => true,
'version' => '1.0',
'enabled' => true,
'requirements' => '',
'active_frontend_own_control' => true,
'path' => 'w3-total-cache/Extension_NewRelic_Plugin.php'
);
return $extensions;
}
function __construct() {
$this->_config = Dispatcher::config();
}
function run() {
add_filter( 'w3tc_compatibility_test', array(
$this, 'verify_compatibility' ) );
add_action( 'w3tc_config_save', array( $this, 'w3tc_config_save' ), 10, 1 );
add_filter( 'w3tc_admin_actions', array( $this, 'w3tc_admin_actions' ) );
add_filter( 'w3tc_admin_menu', array( $this, 'w3tc_admin_menu' ) );
add_filter( 'w3tc_extension_plugin_links_newrelic',
array( $this, 'w3tc_extension_plugin_links' ) );
add_action( 'w3tc_settings_page-w3tc_monitoring',
array( $this, 'w3tc_settings_page_w3tc_monitoring' ) );
add_action( 'admin_init_w3tc_general', array(
'\W3TC\Extension_NewRelic_GeneralPage',
'admin_init_w3tc_general'
) );
add_action( 'w3tc_ajax', array(
'\W3TC\Extension_NewRelic_Popup',
'w3tc_ajax'
) );
if ( Util_Admin::is_w3tc_admin_page() ) {
add_action( 'admin_notices', array(
$this,
'admin_notices'
) );
add_action( 'network_admin_notices', array(
$this,
'admin_notices'
) );
}
add_action( 'admin_init_w3tc_dashboard', array(
'\W3TC\Extension_NewRelic_Widget',
'admin_init_w3tc_dashboard' ) );
add_action( 'w3tc_ajax', array(
'\W3TC\Extension_NewRelic_Widget',
'w3tc_ajax' ) );
add_filter( 'w3tc_notes', array( $this, 'w3tc_notes' ) );
}
public function w3tc_admin_menu( $menu ) {
$c = Dispatcher::config();
$monitoring_type = $c->get_string( array( 'newrelic', 'monitoring_type' ) );
if ( $monitoring_type == 'apm' ) {
$menu = array_merge( $menu, array(
'w3tc_monitoring' => array(
'page_title' => __( 'Monitoring', 'w3-total-cache' ),
'menu_text' => __( 'Monitoring', 'w3-total-cache' ),
'visible_always' => false
)
) );
}
return $menu;
}
public function w3tc_admin_actions( $handlers ) {
$handlers['new_relic'] = 'Extension_NewRelic_AdminActions';
return $handlers;
}
public function w3tc_extension_plugin_links( $links ) {
$links = array();
$links[] = '<a class="edit" href="' .
esc_attr( Util_Ui::admin_url( 'admin.php?page=w3tc_general#monitoring' ) ) .
'">'. __( 'Settings' ).'</a>';
return $links;
}
public function w3tc_settings_page_w3tc_monitoring() {
$v = new Extension_NewRelic_Page();
$v->render_content();
}
function admin_notices() {
$api_key = $this->_config->get_string( array( 'newrelic', 'api_key' ) );
if ( empty( $api_key ) )
return;
$nerser = Dispatcher::component( 'Extension_NewRelic_Service' );
$verify_running_result = $nerser->verify_running();
$not_running = is_array( $verify_running_result );
if ( $not_running ) {
$message = '<p>' .
__( 'New Relic is not running correctly. ', 'w3-total-cache' ) .
'<a href="#" class="w3tc_link_more {for_class: \'w3tc_nr_admin_notice\'}">' .
'more</a> ' .
'<div class="w3tc_none w3tc_nr_admin_notice">' .
__( 'The plugin has detected the following issues:. ', 'w3-total-cache' );
$message .= "<ul class=\"w3-bullet-list\">\n";
foreach ( $verify_running_result as $cause ) {
$message .= "<li>$cause</li>";
}
$message .= "</ul>\n";
$message .= '<p>' . sprintf(
__( 'Please review the <a href="%s">settings</a>.', 'w3-total-cache' ),
network_admin_url( 'admin.php?page=w3tc_general#monitoring' ) ) . "</p>";
$message .= "</div></p>\n";
Util_Ui::error_box( $message );
}
}
function w3tc_notes( $notes ) {
$newrelic_notes = Dispatcher::component( 'Extension_NewRelic_AdminNotes' );
$notes = array_merge( $notes,
$newrelic_notes->notifications( $this->_config ) );
return $notes;
}
/**
* Returns a list of the verification status of the the new relic
* requirements. To be used on the compatibility page
*
* @param unknown $verified_list
* @return array
*/
function verify_compatibility( $verified_list ) {
$nerser = Dispatcher::component( 'Extension_NewRelic_Service' );
$nr_verified = $nerser->verify_compatibility();
$verified_list[] = '<strong>New Relic</strong>';
foreach ( $nr_verified as $criteria => $result )
$verified_list[] = sprintf( "$criteria: %s", $result );
return $verified_list;
}
public function w3tc_config_save( $config ) {
// frontend activity
$api_key = $config->get_string( array( 'newrelic', 'api_key' ) );
$is_filled = !empty( $api_key );
if ( $is_filled ) {
$monitoring_type = $config->get_string( array(
'newrelic', 'monitoring_type' ) );
if ( $monitoring_type == 'browser' ) {
$v = $config->get_string( array( 'newrelic',
'browser.application_id' ) );
$is_filled = !empty( $v );
} else {
$v = $config->get_string( array( 'newrelic',
'apm.application_name' ) );
$is_filled = !empty( $v );
}
}
$config->set_extension_active_frontend( 'newrelic', $is_filled );
}
}