css = $this->get_prepared_css(); //to support IMAGES $field_formats = $this->field_formats['order']; // overwrite! probably modified by parent $this->image_format_fields = isset( $field_formats['image'] ) ? $field_formats['image'] : array(); $this->image_format_fields = apply_filters( "woe_{$format}_image_format_fields", $this->image_format_fields ); } public function start( $data = '' ) { $data = $this->make_header( $data ); $data = apply_filters( "woe_{$this->format}_header_filter", $data ); $this->prepare_array( $data ); parent::start( $data ); $this->table_header_row = $data; if ( $this->mode != 'preview' ) { $this->set_table_header_row($this->table_header_row); if( $this->settings['custom_css'] ) $this->css['style'] = ''; $meta_encoding = apply_filters("woe_html_meta_encoding", ''); fwrite( $this->handle, '' . $meta_encoding . '' ); do_action( "woe_html_print_body_start", $this->handle, $this ); } if ( ! empty( $this->settings['display_column_names'] ) AND $data ) { if ( $this->mode == 'preview' ) { $this->rows[] = $data; } else { if ( $this->settings['header_text'] ) { fwrite( $this->handle, '
' . $this->settings['header_text'] . '
' ); } if( apply_filters( "woe_html_header_print_table", true) ) fwrite( $this->handle, '' ); do_action( "woe_before_{$this->format}_print_header", $this->handle, $data, $this ); if ( ! apply_filters( "woe_{$this->format}_custom_output_func", false, $this->handle, $data, true ) ) { fwrite( $this->handle, '\n" ); } do_action( "woe_{$this->format}_print_header", $this->handle, $data, $this ); } } else { if ( $this->mode !== 'preview' ) { if ( $this->settings['header_text'] ) { fwrite( $this->handle, '
' . $this->settings['header_text'] . '
' ); } if( apply_filters( "woe_html_header_print_table", true) ) fwrite( $this->handle, '
' . join( '', $data ) . "
' ); } } } public function output( $rec ) { $rows = parent::output( $rec ); $images_add_link = $this->mode != 'preview' ? wc_string_to_bool( $this->settings['images_add_link'] ) : false; foreach ( $rows as $row ) { $this->prepare_array( $row ); if ( $this->has_output_filter ) { $row = apply_filters( "woe_{$this->format}_output_filter", $row, $this ); if ( ! $row ) { continue; } } //to support IMAGES foreach ( $row as $column => &$cell ) { if ( $this->field_format_is( $column, $this->image_format_fields ) ) { $html = $this->make_img_html_from_path( $cell, $this->settings['row_images_width'], $this->settings['row_images_height'], $images_add_link ); $cell = $html ? $html : ""; } } if ( $this->mode == 'preview' ) { $this->rows[] = $row; } else { if ( ! apply_filters( "woe_{$this->format}_custom_output_func", false, $this->handle, $row, false ) ) { fwrite( $this->handle, '\n" ); } } } } public function finish() { $this->try_apply_summary_report_fields(); if ( $this->mode == 'preview' ) { if( $this->settings['custom_css'] ) { foreach( $this->css['inline'] as $k=>$v) $this->css['inline'][$k] = ''; } $this->rows = apply_filters( "woe_{$this->format}_preview_rows", $this->rows ); fwrite( $this->handle, '
' ); if ( $this->settings['header_text'] ) { fwrite( $this->handle, '
' . $this->settings['header_text'] . '
' ); } if( apply_filters( "woe_html_header_print_table", true) ) fwrite( $this->handle, '
' . join( '', $row ) . "
' ); if ( $this->settings['display_column_names'] && count( $this->rows ) < 2 || count( $this->rows ) < 1 ) { $this->rows[] = array( '' ); } foreach ( $this->rows as $num => $rec ) { if ( $num == 0 AND ! empty( $this->settings['display_column_names'] ) ) { fwrite( $this->handle, '\n" ); } else { fwrite( $this->handle, '\n" ); } } if (! empty( $this->settings['display_column_names'] ) && ! empty( $this->settings['repeat_header_last_line'] ) && $this->table_header_row) { fwrite( $this->handle, '\n" ); } if( apply_filters( "woe_html_header_print_table", true) ) fwrite( $this->handle, '
' . __( 'No results', 'woo-order-export-lite' ) .'
' . join( '', $rec ) . "
' . join( '', $rec ) . "
' . join( '', $this->table_header_row ) . "
' ); if ( $this->settings['footer_text'] ) { fwrite( $this->handle, '' ); } fwrite( $this->handle, '' ); } else { do_action( "woe_{$this->format}_print_footer", $this->handle, $this ); $this->table_header_row = $this->get_table_header_row(); if (! empty( $this->settings['display_column_names'] ) && ! empty( $this->settings['repeat_header_last_line'] ) && $this->table_header_row) { if ( ! apply_filters( "woe_{$this->format}_custom_output_func", false, $this->handle, $this->table_header_row, true ) ) { fwrite( $this->handle, '' . join( '', $this->table_header_row ) . "\n" ); } } if( apply_filters( "woe_html_header_print_table", true) ) fwrite( $this->handle, '' ); if ( $this->settings['footer_text'] ) { fwrite( $this->handle, '' ); } do_action( "woe_html_print_body_end", $this->handle, $this ); fwrite( $this->handle, '' ); } parent::finish(); } protected function prepare_array( &$arr ) { } protected function get_prepared_css() { $default_css = array(); if ($this->settings['font_size']) { $default_css['font-size'] = $this->settings['font_size'] . 'px'; } $default_header_css = array(); if ( $this->settings['header_text_color'] ) { $default_header_css['color'] = $this->settings['header_text_color']; } $default_footer_css = array(); if ( $this->settings['footer_text_color'] ) { $default_footer_css['color'] = $this->settings['footer_text_color']; } $align = "left"; switch($this->settings['cols_align']) { case 'L': $align = "left"; break; case 'R': $align = "right"; break; case 'C': $align = "center"; break; } $default_th_css = array('text-align' => $align, 'font-weight' => 'bold'); $default_td_css = array('text-align' => $align); if ( $this->settings['table_header_text_color'] ) { $default_th_css['color'] = $this->settings['table_header_text_color']; } if ( $this->settings['table_header_background_color'] ) { $default_th_css['background-color'] = $this->settings['table_header_background_color']; } if ( $this->settings['table_row_text_color'] ) { $default_td_css['color'] = $this->settings['table_row_text_color']; } if ( $this->settings['table_row_background_color'] ) { $default_td_css['background-color'] = $this->settings['table_row_background_color']; } $css = array(); $default = array( 'body' => $default_css, 'header' => $default_header_css, 'footer' => $default_footer_css, 'th' => $default_th_css, 'td' => $default_td_css, ); foreach ($default as $key => $tmp) { $tmp_css = array(); foreach ($tmp as $p => $s) { $tmp_css[] = sprintf('%s: %s', $p, $s); } $css[$key] = implode('; ', $tmp_css); } $style = ' body, .header, .footer, table th, table td {'.$css['body'].'} table th {'.$css['th'].'} table td {'.$css['td'].'} .header {'.$css['header'].'} .footer {'.$css['footer'].'} '; return array( 'style' => $style, 'inline'=> $css, ); } public function get_table_header_row() { return get_transient($this->get_transient_key_table_header_row()); } public function set_table_header_row($row) { return set_transient($this->get_transient_key_table_header_row(), $row, 5 * MINUTE_IN_SECONDS); } public function get_transient_key_table_header_row() { return 'woocommerce-order-file-'. str_replace('/', '-', $this->filename) .'-html-table-header-row'; } }