From 4fb2306ee43b2cb2fef7942f6c1d3c47ab5b0fa5 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 6 Apr 2010 18:34:38 +0000 Subject: [PATCH] MDL-21146 $CFG can not be used in low level file operations - please set the defaults elsewhere if really necessary; removing the extra cleaning + undefined notices - please make sure all palces that actually output the strings are processed properly, there is no way around this, cleaning must be always done before output, not just storage; using real nulls where we do not know the value --- lib/file/file_storage.php | 48 ++++++++------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/lib/file/file_storage.php b/lib/file/file_storage.php index bd464e10a84..8277e62405c 100644 --- a/lib/file/file_storage.php +++ b/lib/file/file_storage.php @@ -457,7 +457,7 @@ class file_storage { * @return object stored_file instance of newly created file */ public function create_file_from_storedfile($file_record, $fileorid) { - global $DB, $CFG; + global $DB; if ($fileorid instanceof stored_file) { $fid = $fileorid->get_id(); @@ -514,21 +514,6 @@ class file_storage { } } - if ($key == 'source') { - $value = clean_param($value, PARAM_URL); - } - - if ($key == 'author') { - $value = clean_param($value, PARAM_TEXT); - } - - if ($key == 'license') { - $value = clean_param($value, PARAM_TEXT); - if ($value === '') { - $value = $CFG->sitedefaultlicense; - } - } - $newrecord->$key = $value; } @@ -601,7 +586,7 @@ class file_storage { * @return object stored_file instance */ public function create_file_from_pathname($file_record, $pathname) { - global $DB, $CFG; + global $DB; $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too @@ -632,13 +617,6 @@ class file_storage { throw new file_exception('storedfileproblem', 'Invalid file name'); } - $file_record->source = clean_param($file_record->source, PARAM_URL); - $file_record->author = clean_param($file_record->author, PARAM_TEXT); - $file_record->license = clean_param($file_record->license, PARAM_TEXT); - if ($file_record->license === '') { - $file_record->license = $CFG->sitedefaultlicense; - } - $now = time(); $newrecord = new object(); @@ -653,9 +631,9 @@ class file_storage { $newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified; $newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype; $newrecord->userid = empty($file_record->userid) ? null : $file_record->userid; - $newrecord->source = $file_record->source; - $newrecord->author = $file_record->author; - $newrecord->license = $file_record->license; + $newrecord->source = empty($file_record->source) ? null : $file_record->source; + $newrecord->author = empty($file_record->author) ? null : $file_record->author; + $newrecord->license = empty($file_record->license) ? null : $file_record->license; list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_file_to_pool($pathname); @@ -687,7 +665,7 @@ class file_storage { * @return object stored_file instance */ public function create_file_from_string($file_record, $content) { - global $DB, $CFG; + global $DB; $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too @@ -718,13 +696,6 @@ class file_storage { throw new file_exception('storedfileproblem', 'Invalid file name'); } - $file_record->source = clean_param($file_record->source, PARAM_URL); - $file_record->author = clean_param($file_record->author, PARAM_TEXT); - $file_record->license = clean_param($file_record->license, PARAM_TEXT); - if ($file_record->license === '') { - $file_record->license = $CFG->sitedefaultlicense; - } - $now = time(); $newrecord = new object(); @@ -739,10 +710,9 @@ class file_storage { $newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified; $newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype; $newrecord->userid = empty($file_record->userid) ? null : $file_record->userid; - - $newrecord->license = empty($file_record->license) ? null : $CFG->sitedefaultlicense; - $newrecord->source = empty($file_record->source) ? null : ''; - $newrecord->author = empty($file_record->author) ? null : ''; + $newrecord->source = empty($file_record->source) ? null : $file_record->source; + $newrecord->author = empty($file_record->author) ? null : $file_record->author; + $newrecord->license = empty($file_record->license) ? null : $file_record->license; list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_string_to_pool($content);