Automattic\WooCommerce\Internal\Admin\Logging

PageController::render_single_file_viewprivateWC 1.0

Render the single file view.

Метод класса: PageController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->render_single_file_view(): void;

Код PageController::render_single_file_view() WC 9.9.4

<?php
private function render_single_file_view(): void {
	$params = $this->get_query_params( array( 'file_id', 'view' ) );
	$file   = $this->file_controller->get_file_by_id( $params['file_id'] );

	if ( is_wp_error( $file ) ) {
		?>
		<div class="notice notice-error notice-inline">
			<?php echo wp_kses_post( wpautop( $file->get_error_message() ) ); ?>
			<?php
			printf(
				'<p><a href="%1$s">%2$s</a></p>',
				esc_url( $this->get_logs_tab_url() ),
				esc_html__( 'Return to the file list.', 'woocommerce' )
			);
			?>
		</div>
		<?php

		return;
	}

	$rotations         = $this->file_controller->get_file_rotations( $file->get_file_id() );
	$rotation_url_base = add_query_arg( 'view', 'single_file', $this->get_logs_tab_url() );

	$download_url           = add_query_arg(
		array(
			'action'  => 'export',
			'file_id' => array( $file->get_file_id() ),
		),
		wp_nonce_url( $this->get_logs_tab_url(), 'bulk-log-files' )
	);
	$delete_url             = add_query_arg(
		array(
			'action'  => 'delete',
			'file_id' => array( $file->get_file_id() ),
		),
		wp_nonce_url( $this->get_logs_tab_url(), 'bulk-log-files' )
	);
	$delete_confirmation_js = sprintf(
		"return window.confirm( '%s' )",
		esc_js( __( 'Delete this log file permanently?', 'woocommerce' ) )
	);

	$stream      = $file->get_stream();
	$line_number = 1;

	?>
	<header id="logs-header" class="wc-logs-header">
		<h2>
			<?php
			printf(
				// translators: %s is the name of a log file.
				esc_html__( 'Viewing log file %s', 'woocommerce' ),
				sprintf(
					'<span class="file-id">%s</span>',
					esc_html( $file->get_file_id() )
				)
			);
			?>
		</h2>
		<?php if ( count( $rotations ) > 1 ) : ?>
			<nav class="wc-logs-single-file-rotations">
				<h3><?php esc_html_e( 'File rotations:', 'woocommerce' ); ?></h3>
				<ul class="wc-logs-rotation-links">
					<?php if ( isset( $rotations['current'] ) ) : ?>
						<?php
						printf(
							'<li><a href="%1$s" class="button button-small button-%2$s">%3$s</a></li>',
							esc_url( add_query_arg( 'file_id', $rotations['current']->get_file_id(), $rotation_url_base ) ),
							$file->get_file_id() === $rotations['current']->get_file_id() ? 'primary' : 'secondary',
							esc_html__( 'Current', 'woocommerce' )
						);
						unset( $rotations['current'] );
						?>
					<?php endif; ?>
					<?php foreach ( $rotations as $rotation ) : ?>
						<?php
						printf(
							'<li><a href="%1$s" class="button button-small button-%2$s">%3$s</a></li>',
							esc_url( add_query_arg( 'file_id', $rotation->get_file_id(), $rotation_url_base ) ),
							$file->get_file_id() === $rotation->get_file_id() ? 'primary' : 'secondary',
							absint( $rotation->get_rotation() )
						);
						?>
					<?php endforeach; ?>
				</ul>
			</nav>
		<?php endif; ?>
		<div class="wc-logs-single-file-actions">
			<?php
			// Download button.
			printf(
				'<a href="%1$s" class="button button-secondary">%2$s</a>',
				esc_url( $download_url ),
				esc_html__( 'Download', 'woocommerce' )
			);
			?>
			<?php
			// Delete button.
			printf(
				'<a href="%1$s" class="button button-secondary" onclick="%2$s">%3$s</a>',
				esc_url( $delete_url ),
				esc_attr( $delete_confirmation_js ),
				esc_html__( 'Delete permanently', 'woocommerce' )
			);
			?>
		</div>
	</header>
	<section id="logs-entries" class="wc-logs-entries">
		<?php while ( ! feof( $stream ) ) : ?>
			<?php
			$line = fgets( $stream );
			if ( is_string( $line ) ) {
				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- format_line does the escaping.
				echo $this->format_line( $line, $line_number );
				++$line_number;
			}
			?>
		<?php endwhile; ?>
	</section>
	<script>
		// Clear the line number hash and highlight with a click.
		document.documentElement.addEventListener( 'click', ( event ) => {
			if ( window.location.hash && ! event.target.classList.contains( 'line-anchor' ) ) {
				let scrollPos = document.documentElement.scrollTop;
				window.location.hash = '';
				document.documentElement.scrollTop = scrollPos;
				history.replaceState( null, '', window.location.pathname + window.location.search );
			}
		} );
	</script>
	<?php
}