public function get_effective_browser_application() { $c = Dispatcher::config(); $api_key = $c->get(array('newrelic', 'api_key')); $id = $c->get(array('newrelic', 'browser.application_id')); if (empty($api_key) || empty($id)) { return null; } $applications_string = get_option('w3tc_nr_browser_applications'); $applications = @json_decode($applications_string, true); if (!is_array($applications)) { $applications = array(); } if (isset($applications[$id])) { return $applications[$id]; } try { $api = new Extension_NewRelic_Api($api_key); $app = $api->get_browser_application($id); if (!is_null($app)) { $applications[$id] = $app; update_option('w3tc_nr_browser_applications', json_encode($applications)); } return $app; } catch (\Exception $ex) { return null; } }
public function w3tc_ajax_newrelic_list_applications() { $api_key = $_REQUEST['api_key']; $c = Dispatcher::config(); $details = array('api_key' => $api_key, 'monitoring_type' => $c->get_string(array('newrelic', 'monitoring_type')), 'apm.application_name' => $c->get_string(array('newrelic', 'apm.application_name')), 'browser.application_id' => $c->get_string(array('newrelic', 'browser.application_id'))); if ($details['monitoring_type'] != 'browser') { $details['monitoring_type'] = 'apm'; } $service = new Extension_NewRelic_Service($api_key); try { $details['apm_applications'] = $service->get_applications(); $api = new Extension_NewRelic_Api($api_key); $details['browser_applications'] = $api->get_browser_applications(); } catch (\Exception $ex) { $details = array('api_key' => $api_key, 'error_message' => 'API key verification failed: ' . $ex->getMessage()); $this->render_intro($details); return; } $details['browser_disabled'] = !Util_Environment::is_w3tc_pro($c); include W3TC_DIR . '/Extension_NewRelic_Popup_View_ListApplications.php'; }