_config = Dispatcher::config(); } /** * Runs plugin */ function run() { add_filter( 'w3tc_config_default_values', array( $this, 'w3tc_config_default_values' ) ); $config = Dispatcher::config(); // remainder only when extension is frontend-active if ( !$config->is_extension_active_frontend( 'newrelic' ) ) return; if ( $this->_config->get_string( array( 'newrelic', 'monitoring_type' ) ) == 'browser' ) { Util_Bus::add_ob_callback( 'newrelic', array( $this, 'ob_callback_browser' ) ); } else { require_once W3TC_LIB_NEWRELIC_DIR . '/NewRelicWrapper.php'; $this->set_appname(); if ( defined( 'DOING_CRON' ) && DOING_CRON ) $this->background_task(); Util_Bus::add_ob_callback( 'newrelic', array( $this, 'ob_callback_apm' ) ); } add_filter( 'w3tc_footer_comment', array( $this, 'w3tc_footer_comment' ) ); } public function w3tc_config_default_values( $default_values ) { $default_values['newrelic'] = array( 'monitoring_type' => 'apm', 'accept.logged_roles' => true, 'accept.roles' => array( 'contributor' ), 'use_php_function' => true, 'cache_time' => 5, 'include_rum' => true ); return $default_values; } function ob_callback_browser( $buffer ) { $core = Dispatcher::component( 'Extension_NewRelic_Core' ); $app = $core->get_effective_browser_application(); if ( isset( $app['loader_script'] ) && $this->_can_add_tracker_script( $buffer ) ) { $buffer = preg_replace( '~
]*)*>~Ui', '\\0' . $app['loader_script'], $buffer, 1 ); } $buffer = str_replace('{w3tc_newrelic_reject_reason}', ( $this->newrelic_reject_reason != '' ? sprintf( ' (%s)', $this->newrelic_reject_reason ) : '' ), $buffer ); return $buffer; } function ob_callback_apm( $buffer ) { if ( !$this->_can_add_tracker_script( $buffer ) ) { $this->disable_auto_rum(); } else { if ( $this->_config->get_boolean( array( 'newrelic', 'include_rum' ) ) ) { $buffer = preg_replace( '~]*)*>~Ui', '\\0' . \NewRelicWrapper::get_browser_timing_header(), $buffer, 1 ); $buffer = preg_replace( '~<\\/body>~', \NewRelicWrapper::get_browser_timing_footer() . '\\0', $buffer, 1 ); } } $buffer = str_replace('{w3tc_newrelic_reject_reason}', ( $this->newrelic_reject_reason != '' ? sprintf( ' (%s)', $this->newrelic_reject_reason ) : '' ), $buffer ); return $buffer; } /** * Mark current transaction as an background job in New Relic. */ function background_task() { \NewRelicWrapper::mark_as_background_job(); } /** * Disable auto rum for current transaction. */ function disable_auto_rum() { \NewRelicWrapper::disable_auto_rum(); } function _can_add_tracker_script( $buffer ) { // $v = ''; if ( preg_match('~^\s*<\?xml[^>]*>\s*