diff --git a/lib/tablelib.php b/lib/tablelib.php index 70138797506..daaf4718e6f 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -2197,7 +2197,17 @@ class table_default_export_format_parent { function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) { //use some whitespace to indicate where there was some line spacing. $text = str_replace(array('
', "\n", "\r"), ' ', $text); - return strip_tags($text); + return html_entity_decode(strip_tags($text)); + } + + /** + * Format a row of data, removing HTML tags and entities from each of the cells + * + * @param array $row + * @return array + */ + public function format_data(array $row): array { + return array_map([$this, 'format_text'], $row); } } @@ -2284,13 +2294,13 @@ class table_dataformat_export_format extends table_default_export_format_parent * @param array $headers */ public function output_headers($headers) { - $this->columns = $headers; + $this->columns = $this->format_data($headers); if (method_exists($this->dataformat, 'write_header')) { error_log('The function write_header() does not support multiple sheets. In order to support multiple sheets you ' . 'must implement start_output() and start_sheet() and remove write_header() in your dataformat.'); - $this->dataformat->write_header($headers); + $this->dataformat->write_header($this->columns); } else { - $this->dataformat->start_sheet($headers); + $this->dataformat->start_sheet($this->columns); } } @@ -2300,6 +2310,10 @@ class table_dataformat_export_format extends table_default_export_format_parent * @param array $row One record of data */ public function add_data($row) { + if (!$this->supports_html()) { + $row = $this->format_data($row); + } + $this->dataformat->write_record($row, $this->rownum++); return true; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 185b8858582..3996f05caa8 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -5,6 +5,7 @@ information provided here is intended especially for developers. * For plugins that override secondary navigation, the namespace for the custom secondary navigation class has changed. It was (for example) mod_mymodule\local\views\secondary but is now mod_mymodule\navigation\views\secondary. The old location will continue to work, but will be deprecated in 4.1. +* When exporting table content, HTML tags/entities will be removed when the selected dataformat does not support HTML === 4.0.2 === * The core renderer `edit_button` method now accepts an optional `$method` argument (get/post) for the button diff --git a/reportbuilder/classes/local/helpers/schedule.php b/reportbuilder/classes/local/helpers/schedule.php index a1335ee2a81..9809bc354c7 100644 --- a/reportbuilder/classes/local/helpers/schedule.php +++ b/reportbuilder/classes/local/helpers/schedule.php @@ -24,11 +24,11 @@ use core_user; use invalid_parameter_exception; use stdClass; use stored_file; +use table_dataformat_export_format; use core\message\message; use core\plugininfo\dataformat; use core_reportbuilder\local\models\audience as audience_model; use core_reportbuilder\local\models\schedule as model; -use core_reportbuilder\output\dataformat_export_format; use core_reportbuilder\table\custom_report_table_view; /** @@ -163,7 +163,7 @@ class schedule { // cleaned in order to instantiate export class without exception). ob_start(); $table->download = $schedule->get('format'); - $exportclass = new dataformat_export_format($table, $table->download); + $exportclass = new table_dataformat_export_format($table, $table->download); ob_end_clean(); // Create our schedule report stored file. @@ -180,11 +180,14 @@ class schedule { $storedfile = \core\dataformat::write_data_to_filearea( $filerecord, $table->download, - $table->headers, + $exportclass->format_data($table->headers), $table->rawdata, - static function(stdClass $record) use ($table, $exportclass): array { + static function(stdClass $record, bool $supportshtml) use ($table, $exportclass): array { $record = $table->format_row($record); - return $exportclass->format_data($record); + if (!$supportshtml) { + $record = $exportclass->format_data($record); + } + return $record; } ); diff --git a/reportbuilder/classes/output/dataformat_export_format.php b/reportbuilder/classes/output/dataformat_export_format.php deleted file mode 100644 index 230c8b5488f..00000000000 --- a/reportbuilder/classes/output/dataformat_export_format.php +++ /dev/null @@ -1,61 +0,0 @@ -. - -declare(strict_types=1); - -namespace core_reportbuilder\output; - -use table_dataformat_export_format; - -defined('MOODLE_INTERNAL') || die(); - -require_once("{$CFG->libdir}/tablelib.php"); - -/** - * Dataformat export class for reports - * - * @package core_reportbuilder - * @copyright 2021 Paul Holden