* @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();
}
}
- 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;
}
* @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
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();
$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);
* @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
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();
$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);