collector->get_data();
if ( empty( $data['assets'] ) ) {
return;
}
$position_labels = array(
// @TODO translator comments or context:
'missing' => __( 'Missing', 'query-monitor' ),
'broken' => __( 'Missing Dependencies', 'query-monitor' ),
'header' => __( 'Header', 'query-monitor' ),
'footer' => __( 'Footer', 'query-monitor' ),
);
$type_label = $this->get_type_labels();
$this->type = $this->collector->get_dependency_type();
$hosts = array(
__( 'Other', 'query-monitor' ),
);
$this->before_tabular_output();
echo '';
echo '';
echo '| ' . esc_html__( 'Position', 'query-monitor' ) . ' | ';
echo '' . esc_html__( 'Handle', 'query-monitor' ) . ' | ';
echo '';
$args = array(
'prepend' => array(
'local' => $data['host'],
),
);
echo $this->build_filter( $this->type . '-host', $hosts, __( 'Host', 'query-monitor' ), $args ); // WPCS: XSS ok.
echo ' | ';
echo '' . esc_html__( 'Source', 'query-monitor' ) . ' | ';
echo '';
echo $this->build_filter( $this->type . '-dependencies', $data['dependencies'], __( 'Dependencies', 'query-monitor' ) ); // WPCS: XSS ok.
echo ' | ';
echo '';
echo $this->build_filter( $this->type . '-dependents', $data['dependents'], __( 'Dependents', 'query-monitor' ) ); // WPCS: XSS ok.
echo ' | ';
echo '' . esc_html__( 'Version', 'query-monitor' ) . ' | ';
echo '
';
echo '';
echo '
';
foreach ( $position_labels as $position => $label ) {
if ( ! empty( $data['assets'][ $position ] ) ) {
foreach ( $data['assets'][ $position ] as $handle => $asset ) {
$this->dependency_row( $handle, $asset, $label );
}
}
}
echo '';
echo '';
echo '';
printf(
'| %1$s | ',
sprintf(
esc_html( $type_label['total'] ),
'' . esc_html( number_format_i18n( $data['counts']['total'] ) ) . ''
)
);
echo '
';
echo '';
$this->after_tabular_output();
}
protected function dependency_row( $handle, array $asset, $label ) {
$data = $this->collector->get_data();
$highlight_deps = array_map( array( $this, '_prefix_type' ), $asset['dependencies'] );
$highlight_dependents = array_map( array( $this, '_prefix_type' ), $asset['dependents'] );
$dependencies_list = implode( ' ', $asset['dependencies'] );
$dependents_list = implode( ' ', $asset['dependents'] );
$dependency_output = array();
foreach ( $asset['dependencies'] as $dep ) {
if ( isset( $data['missing_dependencies'][ $dep ] ) ) {
$dependency_output[] = sprintf(
'%s',
sprintf(
/* translators: %s: Name of missing script or style dependency */
__( '%s (missing)', 'query-monitor' ),
esc_html( $dep )
)
);
} else {
$dependency_output[] = $dep;
}
}
$qm_host = ( $asset['local'] ) ? 'local' : __( 'Other', 'query-monitor' );
$class = '';
if ( $asset['warning'] ) {
$class = 'qm-warn';
}
echo 'type ) . '-host="' . esc_attr( $qm_host ) . '" data-qm-' . esc_attr( $this->type ) . '-dependents="' . esc_attr( $dependents_list ) . '" data-qm-' . esc_attr( $this->type ) . '-dependencies="' . esc_attr( $dependencies_list ) . '" class="' . esc_attr( $class ) . '">';
echo '| ';
if ( $asset['warning'] ) {
echo '';
}
echo esc_html( $label );
echo ' | ';
$host = $asset['host'];
$parts = explode( '.', $host );
foreach ( $parts as $k => $part ) {
if ( strlen( $part ) > 16 ) {
$parts[ $k ] = substr( $parts[ $k ], 0, 6 ) . '…' . substr( $parts[ $k ], -6 );
}
}
$host = implode( '.', $parts );
echo '' . esc_html( $handle ) . ' | ';
echo '' . esc_html( $host ) . ' | ';
echo '';
if ( is_wp_error( $asset['source'] ) ) {
$error_data = $asset['source']->get_error_data();
if ( $error_data && isset( $error_data['src'] ) ) {
printf(
'%1$s: %2$s',
esc_html( $asset['source']->get_error_message() ),
esc_url( $error_data['src'] )
);
} else {
printf(
'%s',
esc_html( $asset['source']->get_error_message() )
);
}
} elseif ( ! empty( $asset['source'] ) ) {
printf(
'%s',
esc_url( $asset['source'] ),
esc_html( $asset['display'] )
);
}
echo ' | ';
echo '';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo implode( ', ', $dependency_output );
echo ' | ';
echo '' . implode( ', ', array_map( 'esc_html', $asset['dependents'] ) ) . ' | ';
echo '' . esc_html( $asset['ver'] ) . ' | ';
echo '
';
}
public function _prefix_type( $val ) {
return $this->type . '-' . $val;
}
public function admin_class( array $class ) {
$data = $this->collector->get_data();
if ( ! empty( $data['broken'] ) || ! empty( $data['missing'] ) ) {
$class[] = 'qm-error';
}
return $class;
}
public function admin_menu( array $menu ) {
$data = $this->collector->get_data();
if ( empty( $data['assets'] ) ) {
return $menu;
}
$type_label = $this->get_type_labels();
$label = sprintf(
$type_label['count'],
number_format_i18n( $data['counts']['total'] )
);
$args = array(
'title' => esc_html( $label ),
'id' => esc_attr( "query-monitor-{$this->collector->id}" ),
'href' => esc_attr( '#' . $this->collector->id() ),
);
if ( ! empty( $data['broken'] ) || ! empty( $data['missing'] ) ) {
$args['meta']['classname'] = 'qm-error';
}
$id = $this->collector->id();
$menu[ $id ] = $this->menu( $args );
return $menu;
}
}