public static function audio_mime_types() { static $mimetypes = null; if (is_null($mimetypes)) { $descriptions = self::audio_file_descriptions(); $mimetypes = PluginArtefactFile::get_mimetypes_from_description($descriptions, true); } return $mimetypes; }
/** * retrieves the files from the remote host */ public function prepare_files() { if (empty($this->importer)) { throw new ImportException(null, 'Failed to initialise XMLRPC file retrieval - no importer object'); } $this->prepare_tempdir(); $this->token = $this->importer->get('token'); require_once get_config('docroot') . 'api/xmlrpc/client.php'; $client = new Client(); try { $client->set_method('portfolio/mahara/lib.php/fetch_file')->add_param($this->token)->send($this->host->wwwroot); } catch (XmlrpcClientException $e) { throw new ImportException($this->importer, 'Failed to retrieve zipfile from remote server: ' . $e->getMessage()); } if (!($filecontents = base64_decode($client->response))) { throw new ImportException($this->importer, 'Failed to retrieve zipfile from remote server'); } $this->importfilename = 'import.zip'; $this->importfile = $this->tempdir . $this->importfilename; if (!file_put_contents($this->tempdir . $this->importfilename, $filecontents)) { throw new ImportException($this->importer, 'Failed to write out the zipfile to local temporary storage'); } // detect the filetype and bail if it's not a zip file safe_require('artefact', 'file'); require_once 'file.php'; $ziptypes = PluginArtefactFile::get_mimetypes_from_description('zip'); $this->mimetype = file_mime_type($this->tempdir . $this->importfilename); if (!in_array($this->mimetype, $ziptypes)) { throw new ImportException($this->importer, 'Not a valid zipfile - mimetype was ' . $this->mimetype); } }
function addfontform_validate(Pieform $form, $values) { global $USER, $SESSION; require_once 'file.php'; require_once 'uploadmanager.php'; $foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, '', $values['fonttitle']); if (!$foldername) { $form->set_error('fonttitle', get_string('invalidfonttitle', 'skin')); } // If we are uploading a zip file we need to extract things before we can validate them if (!empty($values['fontfileZip'])) { safe_require('artefact', 'file'); $ziptypes = PluginArtefactFile::get_mimetypes_from_description('zip'); $zipmimetype = file_mime_type($values['fontfileZip']['name']); $zipmimetype = $zipmimetype || (substr($values['fontfileZip']['name'], -4) == '.zip' ? 'application/zip' : null); if (in_array($zipmimetype, $ziptypes)) { // we are dealing with a zip file // First pass it through the virus checker $um = new upload_manager('fontfileZip'); if ($error = $um->preprocess_file()) { $form->set_error('fontfileZip', $error); } $zip = new ZipArchive(); if ($zip->open($values['fontfileZip']['tmp_name'])) { $check = uploadfiles_info(); for ($i = 0; $i < $zip->numFiles; $i++) { $fontname = dirname($zip->getNameIndex($i)); $filename = basename($zip->getNameIndex($i)); if (empty($fontname) || $fontname == '.') { $fontname = substr($values['fontfileZip']['name'], 0, -1 * strlen('.zip')); } // Check that all the needed files exist in the zip file foreach ($check as $key => $item) { if (end(explode('.', $zip->getNameIndex($i))) == $item['suffix']) { $check[$key]['found'] = true; } } } // now examine our $check array to make sure at least one of each of the required files was found foreach ($check as $key => $item) { if ($item['required'] == true && $item['found'] == false) { $form->set_error('fontfileZip', get_string('fontfilemissing', 'skin', $item['suffix'])); } } } else { $form->set_error('fontfileZip', get_string('archivereadingerror', 'skin')); } } else { $form->set_error('fontfileZip', get_string('notvalidzipfile', 'skin')); } } else { foreach (uploadfiles_info() as $inputname => $details) { $um = new upload_manager($inputname, false, null, !$details['required']); if ($error = $um->preprocess_file()) { $form->set_error($inputname, $error); } if (!$um->optionalandnotsupplied && $details['suffix']) { $reqext = ".{$details['suffix']}"; $fileext = substr($values[$inputname]['name'], -1 * strlen($reqext)); if ($fileext != $reqext) { $form->set_error($inputname, get_string('notvalidfontfile', 'skin', strtoupper($details['suffix']))); } } } } }