diff --git a/qm-plugins/qm-vip-concat/class-qm-collector-vip-concat.php b/qm-plugins/qm-vip-concat/class-qm-collector-vip-concat.php new file mode 100644 index 0000000000..9ff32650a6 --- /dev/null +++ b/qm-plugins/qm-vip-concat/class-qm-collector-vip-concat.php @@ -0,0 +1,49 @@ +get_levels() as $level ) { + add_action( "qm/{$level}", array( $this, $level ), 10, 2 ); + } + } + + /** + * @param mixed $message + * @param array $context + * @phpstan-param LogMessage $message + * @return void + */ + public function vip_concat_info( $message, array $context = array() ) { + $this->store( 'vip_concat_info', $message, $context ); + } + public function vip_concat_warn( $message, array $context = array() ) { + $this->store( 'vip_concat_warn', $message, $context ); + } + + /** + * @return array + * @phpstan-return list + */ + public function get_levels() { + return array( + 'vip_concat_info', + 'vip_concat_warn', + ); + } + + /** + * @return array + * @phpstan-return list + */ + public function get_warning_levels() { + return array( + 'vip_concat_warn', + ); + } +} diff --git a/qm-plugins/qm-vip-concat/class-qm-output-vip-concat.php b/qm-plugins/qm-vip-concat/class-qm-output-vip-concat.php new file mode 100644 index 0000000000..974253746b --- /dev/null +++ b/qm-plugins/qm-vip-concat/class-qm-output-vip-concat.php @@ -0,0 +1,147 @@ +collector->get_data(); + + if ( empty( $data->logs ) ) { + $this->before_non_tabular_output(); + + $notice = sprintf( + /* translators: %s: Link to help article */ + __( 'No data logged. Read about the WordPress VIP Platform\'s file concatenation feature.', 'query-monitor' ), + 'https://docs.wpvip.com/vip-go-mu-plugins/file-concatenation-and-minification/' + ); + echo $this->build_notice( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- + + $this->after_non_tabular_output(); + + return; + } + + $levels = array(); + + foreach ( $this->collector->get_levels() as $level ) { + if ( $data->counts[ $level ] ) { + $levels[ $level ] = sprintf( + '%s (%d)', + ucfirst( $level ), + $data->counts[ $level ] + ); + } else { + $levels[ $level ] = ucfirst( $level ); + } + } + $this->before_tabular_output(); + + $level_args = array( + 'all' => sprintf( + /* translators: %s: Total number of items in a list */ + __( 'All (%d)', 'query-monitor' ), + count( $data->logs ) + ), + ); + + echo ''; + echo ''; + echo ''; + echo $this->build_filter( 'type', $levels, __( 'Level', 'query-monitor' ), $level_args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- + echo ''; + echo '' . esc_html__( 'Message', 'query-monitor' ) . ''; + echo ''; + echo ''; + echo ''; + + foreach ( $data->logs as $row ) { + + $row_attr = array(); + $row_attr['data-qm-type'] = $row['level']; + + $attr = ''; + + foreach ( $row_attr as $a => $v ) { + $attr .= ' ' . $a . '="' . esc_attr( $v ) . '"'; + } + + $is_warning = in_array( $row['level'], $this->collector->get_warning_levels(), true ); + + if ( $is_warning ) { + $class = 'qm-warn'; + } else { + $class = ''; + } + + echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- + echo ''; + + if ( $is_warning ) { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo QueryMonitor::icon( 'warning' ); + } else { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo QueryMonitor::icon( 'blank' ); + } + + echo esc_html( ucfirst( str_replace( 'vip_concat_', '', $row['level'] ) ) ); + echo ''; + printf( + '
%s
', + esc_html( $row['message'] ) + ); + + echo ''; + + } + + echo ''; + + $this->after_tabular_output(); + } + + /** + * Adds data to top admin bar + * + * @param array $title + * + * @return array + */ + public function admin_title( array $title ) { + return $title; + } + + /** + * @param array $class + * + * @return array + */ + public function admin_class( array $class ) { + $class[] = 'qm-vip_concat'; + return $class; + } + + public function admin_menu( array $menu ) { + + $menu[] = $this->menu( array( + 'id' => 'qm-vip_concat', + 'href' => '#qm-vip_concat', + 'title' => __( 'VIP JS/CSS Concat', 'query-monitor' ), + )); + + return $menu; + } +} diff --git a/qm-plugins/qm-vip-concat/qm-vip-concat.php b/qm-plugins/qm-vip-concat/qm-vip-concat.php new file mode 100644 index 0000000000..8b424c96bb --- /dev/null +++ b/qm-plugins/qm-vip-concat/qm-vip-concat.php @@ -0,0 +1,32 @@ +