mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-83335 core: Explicitly specify escape with fgetcsv/fputcsv
PHP 8.4 requires that a value be provided for the `$escape` parameter to both `fgetcsv()` and `fputcsv()`.
This commit is contained in:
parent
ab5692acdf
commit
b29615a6f0
9 changed files with 26 additions and 26 deletions
|
@ -85,7 +85,7 @@ class brickfield_accessibility_guideline {
|
|||
$csv = fopen(dirname(__FILE__) .'/guidelines/translations/'. $domain .'.txt', 'r');
|
||||
|
||||
if ($csv) {
|
||||
while ($translation = fgetcsv($csv)) {
|
||||
while ($translation = fgetcsv($csv, escape: '\\')) {
|
||||
if (count($translation) == 4) {
|
||||
$this->translations[$translation[0]] = [
|
||||
'title' => $translation[1],
|
||||
|
|
|
@ -85,9 +85,9 @@ if ($options['replace']) {
|
|||
$results = $urlfinder->http_link_stats();
|
||||
asort($results);
|
||||
$fp = fopen('php://stdout', 'w');
|
||||
fputcsv($fp, ['clientsite', 'httpdomain', 'urlcount']);
|
||||
fputcsv($fp, ['clientsite', 'httpdomain', 'urlcount'], escape: '\\');
|
||||
foreach ($results as $domain => $count) {
|
||||
fputcsv($fp, [$SITE->shortname, $domain, $count]);
|
||||
fputcsv($fp, [$SITE->shortname, $domain, $count], escape: '\\');
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ class dataset_manager {
|
|||
return false;
|
||||
}
|
||||
foreach ($data as $line) {
|
||||
fputcsv($fh, $line);
|
||||
fputcsv($fh, $line, escape: '\\');
|
||||
}
|
||||
fclose($fh);
|
||||
|
||||
|
@ -290,12 +290,12 @@ class dataset_manager {
|
|||
$rh = $file->get_content_file_handle();
|
||||
|
||||
// Copy the var names as they are, all files should have the same var names.
|
||||
$varnames = fgetcsv($rh);
|
||||
$varnames = fgetcsv($rh, escape: '\\');
|
||||
|
||||
$analysablesvalues[] = fgetcsv($rh);
|
||||
$analysablesvalues[] = fgetcsv($rh, escape: '\\');
|
||||
|
||||
// Copy the columns as they are, all files should have the same columns.
|
||||
$columns = fgetcsv($rh);
|
||||
$columns = fgetcsv($rh, escape: '\\');
|
||||
}
|
||||
|
||||
// Merge analysable values skipping the ones that are the same in all analysables.
|
||||
|
@ -316,9 +316,9 @@ class dataset_manager {
|
|||
throw new \moodle_exception('errorcannotwritedataset', 'analytics', '', $tmpfilepath);
|
||||
}
|
||||
|
||||
fputcsv($wh, $varnames);
|
||||
fputcsv($wh, $values);
|
||||
fputcsv($wh, $columns);
|
||||
fputcsv($wh, $varnames, escape: '\\');
|
||||
fputcsv($wh, $values, escape: '\\');
|
||||
fputcsv($wh, $columns, escape: '\\');
|
||||
|
||||
// Iterate through all files and add them to the tmp one. We don't want file contents in memory.
|
||||
foreach ($files as $file) {
|
||||
|
@ -402,11 +402,11 @@ class dataset_manager {
|
|||
|
||||
$calculations = array();
|
||||
|
||||
$headers = fgetcsv($rh);
|
||||
$headers = fgetcsv($rh, escape: '\\');
|
||||
// Get rid of the sampleid column name.
|
||||
array_shift($headers);
|
||||
|
||||
while ($columns = fgetcsv($rh)) {
|
||||
while ($columns = fgetcsv($rh, escape: '\\')) {
|
||||
$uniquesampleid = array_shift($columns);
|
||||
|
||||
// Unfortunately fgetcsv does not respect line's var types.
|
||||
|
|
|
@ -209,7 +209,7 @@ class behat_core_competency_generator extends behat_generator_base {
|
|||
*/
|
||||
protected function preprocess_plan(array $data): array {
|
||||
if (isset($data['competencies'])) {
|
||||
$competencies = array_map('trim', str_getcsv($data['competencies']));
|
||||
$competencies = array_map('trim', str_getcsv($data['competencies'], escape: '\\'));
|
||||
$data['competencyids'] = array_map([$this, 'get_competency_id'], $competencies);
|
||||
|
||||
unset($data['competencies']);
|
||||
|
|
|
@ -112,7 +112,7 @@ if ($handle = fopen($imported_file, 'r')) {
|
|||
|
||||
// data should be separated by a ';'. *NOT* by a comma! TODO: version 2.0
|
||||
// or whenever we can depend on PHP5, set the second parameter (8192) to 0 (unlimited line length) : the database can store over 128k per line.
|
||||
while ( $csv_data = fgetcsv($handle, 8192, ';', '"')) { // if the line is over 8k, it won't work...
|
||||
while ( $csv_data = fgetcsv($handle, 8192, ';', '"', '\\')) { // if the line is over 8k, it won't work...
|
||||
$line++;
|
||||
|
||||
// be tolerant on input, as fgetcsv returns "an array comprising a single null field" on blank lines
|
||||
|
|
|
@ -126,7 +126,7 @@ class csv_import_reader {
|
|||
$columns = array();
|
||||
// str_getcsv doesn't iterate through the csv data properly. It has
|
||||
// problems with line returns.
|
||||
while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
|
||||
while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure, '\\')) {
|
||||
// Check to see if we have an empty line.
|
||||
if (count($fgetdata) == 1) {
|
||||
if ($fgetdata[0] !== null) {
|
||||
|
@ -204,7 +204,7 @@ class csv_import_reader {
|
|||
return false;
|
||||
}
|
||||
$fp = fopen($filename, "r");
|
||||
$line = fgetcsv($fp);
|
||||
$line = fgetcsv($fp, escape: '\\');
|
||||
fclose($fp);
|
||||
if ($line === false) {
|
||||
return false;
|
||||
|
@ -234,7 +234,7 @@ class csv_import_reader {
|
|||
return false;
|
||||
}
|
||||
//skip header
|
||||
return (fgetcsv($this->_fp) !== false);
|
||||
return (fgetcsv($this->_fp, escape: '\\') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,7 +246,7 @@ class csv_import_reader {
|
|||
if (empty($this->_fp) or feof($this->_fp)) {
|
||||
return false;
|
||||
}
|
||||
if ($ser = fgetcsv($this->_fp)) {
|
||||
if ($ser = fgetcsv($this->_fp, escape: '\\')) {
|
||||
return $ser;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -449,7 +449,7 @@ class csv_export_writer {
|
|||
}
|
||||
}
|
||||
$delimiter = csv_import_reader::get_delimiter($this->delimiter);
|
||||
fputcsv($this->fp, $row, $delimiter, $this->csvenclosure);
|
||||
fputcsv($this->fp, $row, $delimiter, $this->csvenclosure, '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -126,7 +126,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor
|
|||
|
||||
$samples = array();
|
||||
$targets = array();
|
||||
while (($data = fgetcsv($fh)) !== false) {
|
||||
while (($data = fgetcsv($fh, escape: '\\')) !== false) {
|
||||
$sampledata = array_map('floatval', $data);
|
||||
$samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
|
||||
$targets[] = intval($data[$metadata['nfeatures']]);
|
||||
|
@ -189,7 +189,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor
|
|||
$sampleids = array();
|
||||
$samples = array();
|
||||
$predictions = array();
|
||||
while (($data = fgetcsv($fh)) !== false) {
|
||||
while (($data = fgetcsv($fh, escape: '\\')) !== false) {
|
||||
$sampledata = array_map('floatval', $data);
|
||||
$sampleids[] = $data[0];
|
||||
$samples[] = array_slice($sampledata, 1, $metadata['nfeatures']);
|
||||
|
@ -270,7 +270,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor
|
|||
|
||||
$samples = array();
|
||||
$targets = array();
|
||||
while (($data = fgetcsv($fh)) !== false) {
|
||||
while (($data = fgetcsv($fh, escape: '\\')) !== false) {
|
||||
$sampledata = array_map('floatval', $data);
|
||||
|
||||
$samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
|
||||
|
@ -535,8 +535,8 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor
|
|||
* @return array
|
||||
*/
|
||||
protected function extract_metadata($fh) {
|
||||
$metadata = fgetcsv($fh);
|
||||
return array_combine($metadata, fgetcsv($fh));
|
||||
$metadata = fgetcsv($fh, escape: '\\');
|
||||
return array_combine($metadata, fgetcsv($fh, escape: '\\'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -282,7 +282,7 @@ class phpunit_dataset {
|
|||
rewind($fh);
|
||||
|
||||
// We just accept default, delimiter = comma, enclosure = double quote.
|
||||
while ( ($row = fgetcsv($fh) ) !== false ) {
|
||||
while ( ($row = fgetcsv($fh, escape: '\\') ) !== false ) {
|
||||
if (empty($this->columns[$tablename])) {
|
||||
$this->columns[$tablename] = $row;
|
||||
} else {
|
||||
|
|
|
@ -115,7 +115,7 @@ class recording_row_playback implements renderable, templatable {
|
|||
$issafeformat = false;
|
||||
// Now check the list of safe formats.
|
||||
if ($safeformats = config::get('recording_safe_formats')) {
|
||||
$safeformatarray = str_getcsv($safeformats);
|
||||
$safeformatarray = str_getcsv($safeformats, escape: '\\');
|
||||
$issafeformat = in_array($playback['type'], $safeformatarray);
|
||||
}
|
||||
return ($canmanagerecordings && $canviewallformats) || $issafeformat;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue