function validation($data, $files) { $errors = parent::validation($data, $files); if ($this->taoresource_entry_mode == 'add') { // make sure that either the file or the URL are supplied if (empty($data['url']) && $_FILES['taoresourcefile']['size'] <= 0) { $errors['url'] = get_string('missingresource', 'taoresource'); } // if file is uploaded - check that there was no problem if (empty($data['url']) && $_FILES['taoresourcefile']['error'] != 0) { // error - physical upload of file failed $errors['taoresourcefile'] = get_string('fileuploadfailed', 'taoresource'); } // check that this resource signature does not allready exist if (!empty($data['url'])) { $hash = sha1($data['url']); $result = count_records('taoresource_entry', 'identifier', $hash) + count_records('taoresource_entry', 'url', $data['url']); if ($result > 0) { $errors['url'] = get_string('resourceexists', 'taoresource'); } } else { $tempfile = $_FILES['taoresourcefile']['tmp_name']; $hash = taoresource_sha1file($tempfile); $taoresource_entry->identifier = $hash; $uri = $hash . '-' . $_FILES['taoresourcefile']['name']; $result = count_records('taoresource_entry', 'identifier', $hash) + count_records('taoresource_entry', 'url', $uri); if ($result > 0) { $errors['taoresourcefile'] = get_string('resourceexists', 'taoresource'); } } } // let the plugins see the form validation $plugins = taoresource_get_plugins(); foreach ($plugins as $plugin) { $rc = $plugin->taoresource_entry_validation($data, $files, $errors, $this->taoresource_entry_mode); if (!$rc) { break; } } return $errors; }
// page step 1 if ($pagestep == 1) { // is this a local resource or a remote one? if (!empty($taoresource_entry->url)) { $taoresource_entry->identifier = sha1($taoresource_entry->url); $taoresource_entry->mimetype = mimeinfo("type", $taoresource_entry->url); } else { // if resource uploaded then move to temp area until user has // completed metadata if (!taoresource_check_and_create_moddata_temp_dir()) { error("Error - can't create resources temp dir"); } $tempfile = $_FILES['taoresourcefile']['tmp_name']; $taoresource_entry->uploadname = clean_param($_FILES['taoresourcefile']['name'], PARAM_PATH); $taoresource_entry->mimetype = clean_param($_FILES['taoresourcefile']['type'], PARAM_URL); if (empty($tempfile) || !($hash = taoresource_sha1file($tempfile))) { error("Error - can't create hash of incoming resource file"); } $taoresource_entry->identifier = $hash; $taoresource_entry->file = $hash . '-' . $taoresource_entry->uploadname; $taoresource_entry->tempfilename = $CFG->dataroot . TAORESOURCE_TEMPPATH . $taoresource_entry->file; $formdata->identifier = $taoresource_entry->identifier; $formdata->file = $taoresource_entry->file; $formdata->uploadname = $taoresource_entry->uploadname; $formdata->mimetype = $taoresource_entry->mimetype; if (!taoresource_copy_file($tempfile, $taoresource_entry->tempfilename, true)) { error("Error - can't copy upload file to temp"); } } } else { // is this a local resource or a remote one?