$alert ) { $date = ( isset( $alert['created_on'] ) ) ? $alert['created_on'] : ''; $r = ''; $processed_row_data = array(); foreach ( self::$columns_header as $key => $label ) { $value = array_key_exists( $key, $alert ) ? $alert[ $key ] : ''; if ( 'timestamp' === $key ) { $value = $date; } $processed_row_data[ $key ] = $value; } foreach ( $processed_row_data as $key => $label ) { $cell_styling = 'padding: 16px 7px;'; if ( 'alert_id' === $key ) { $cell_styling .= ' text-align: center; font-weight: 700;'; } elseif ( 'severity' === $key ) { $cell_styling = '" class="tooltip" title="' . $label; $label = ''; } elseif ( 'user_displayname' === $key ) { $cell_styling .= ' min-width: 100px;'; } elseif ( 'message' === $key ) { $cell_styling .= ' min-width: 400px; word-break: break-all; line-height: 1.5;'; } $r .= '' . $label . ''; } $r .= ''; fwrite( $output, $r ); } } fclose( $output ); } /** * Sets the writer file name. * * @param string $file - The name of the writer file to be used. * * @return void * * @since 5.0.0 */ public static function set_file( string $file ) { self::$file_name = $file; } /** * Returns the writer file name. * * @return string * * @since 5.0.0 */ public static function get_file(): string { return (string) self::$file_name; } /** * Sets the header_columns property to be used in HTML generation * * @param array $columns - The column names. * * @return void * * @since 5.0.0 */ public static function set_header_columns( array $columns ) { self::$columns_header = $columns; } /** * Set the file footer - closes the HTML output. * * @return void * * @since 5.0.0 */ public static function set_footer() { $output = fopen( self::get_file(), 'a+' ); fwrite( $output, '

WP Activity Log is supported and developed by Melapress.

' ); fclose( $output ); } /** * Prepares the header columns for the HTML file * * @param string $title - The title of the report. * @param resource $stream - The file stream to write to. * @param array $report_filters - The report filters criteria. * @return void * * @since 5.0.0 */ private static function prepare_header( string $title, $stream, array $report_filters = array() ) { fwrite( $stream, self::build_report_header( $report_filters ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite fwrite( $stream, '

' . $title . '

' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite fwrite( $stream, '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite $header = ''; $header .= ''; foreach ( self::$columns_header as $item ) { $header .= ''; } $header .= ''; $header .= ''; fwrite( $stream, $header ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite fwrite( $stream, '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite } /** * Generate the HTML head of the Report. * * @param array $report_data - The report data array with values needed for generating the custom part of the report, and filters used (so we can show the report header along with the criteria used to generate it). * * @return string * * @since 5.0.0 */ private static function build_report_header( $report_data ): string { $str = 'Periodic report | WP Activity Log'; if ( \class_exists( 'WSAL\Extensions\Views\Reports' ) ) { $white_settings = Settings_Helper::get_option_value( Reports::REPORT_WHITE_LABEL_SETTINGS_NAME ); $logo_link = isset( $white_settings['logo_url'] ) ? (string) $white_settings['logo_url'] : ''; $logo_src = isset( $white_settings['logo'] ) ? (string) $white_settings['logo'] : ''; if ( 0 === strlen( $logo_link ) ) { $logo_link = 'https://melapress.com/?utm_source=plugin&utm_medium=referral&utm_campaign=wsal&utm_content=priodic-report'; } if ( ! isset( $logo_src ) || empty( $logo_src ) ) { $logo_src = ' '; } else { $logo_src = 'Report_logo'; } $str .= '
'; $str .= ''; // Don't use esc_url here. Logo source can be something other than a URL. $str .= $logo_src; $str .= ''; $str .= '

'; if ( array_key_exists( 'custom_title', $report_data ) ) { $str .= $report_data['custom_title']; unset( $report_data['custom_title'] ); } $str .= '

'; $str .= '
'; $now = time(); $date = DateTime_Formatter_Helper::get_formatted_date_time( $now, 'date' ); $time = DateTime_Formatter_Helper::get_formatted_date_time( $now, 'time' ); $user = User_Helper::get_current_user(); $str .= '
'; $report_attributes = array(); $report_attributes[ esc_html__( 'Report Date', 'wp-security-audit-log' ) ] = $date; $report_attributes[ esc_html__( 'Report Time', 'wp-security-audit-log' ) ] = $time; $timezone = Settings_Helper::get_timezone(); /** * Transform timezone values. * * @since 3.2.3 */ if ( '0' === $timezone ) { $timezone = 'UTC'; } elseif ( '1' === $timezone ) { $timezone = wp_timezone_string(); } elseif ( 'wp' === $timezone ) { $timezone = wp_timezone_string(); } elseif ( 'utc' === $timezone ) { $timezone = 'UTC'; } $report_attributes[ esc_html__( 'Timezone', 'wp-security-audit-log' ) ] = $timezone; $report_attributes[ esc_html__( 'Generated by', 'wp-security-audit-log' ) ] = $user->user_login . ' — ' . $user->user_email; $contact_attributes = array( esc_html__( 'Business Name', 'wp-security-audit-log' ) => isset( $white_settings['business_name'] ) ? $white_settings['business_name'] : '', esc_html__( 'Contact Name', 'wp-security-audit-log' ) => isset( $white_settings['name_surname'] ) ? $white_settings['name_surname'] : '', esc_html__( 'Contact Email', 'wp-security-audit-log' ) => isset( $white_settings['email'] ) ? $white_settings['email'] : '', esc_html__( 'Contact Phone', 'wp-security-audit-log' ) => isset( $white_settings['phone_number'] ) ? $white_settings['phone_number'] : '', ); foreach ( $contact_attributes as $label => $value ) { if ( strlen( (string) $value ) > 0 ) { $report_attributes[ $label ] = $value; } } $tbody = '
' . $item . '
'; $tbody .= ''; foreach ( $report_attributes as $label => $value ) { $tbody .= ''; $tbody .= ''; $tbody .= ''; $tbody .= ''; } if ( array_key_exists( 'comment', $report_data ) && strlen( $report_data['comment'] ) > 0 ) { $tbody .= ''; $tbody .= ''; $tbody .= ''; $tbody .= ''; $tbody .= ''; $tbody .= ''; } unset( $report_data['comment'] ); $tbody .= ''; if ( isset( $report_data['no_meta'] ) && false === $report_data['no_meta'] ) { $tbody .= ''; $tbody .= ''; unset( $report_data['no_meta'] ); // $criteria = $this->get_criteria_list(); foreach ( $report_data as $criteria_label => $criteria_values ) { $tbody .= ''; $tbody .= ''; $tbody .= ''; $tbody .= ''; } } $tbody .= ''; $tbody .= '
' . $label . ':' . $value . '
' . esc_html__( 'Comment', 'wp-security-audit-log' ) . ':
' . $report_data['comment'] . '
' . esc_html__( 'Report Criteria', 'wp-security-audit-log' ) . '
' . $criteria_label . ':' . \implode( '
', (array) $criteria_values ) . '
'; $str .= $tbody; $str .= ''; } $str .= '
'; return $str; } } }